Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ interface ChatMessageRepository : LifecycleAwareManager {
referenceId: String
): Flow<Result<ChatMessage?>>

@Suppress("LongParameterList")
suspend fun addTemporaryMessage(
message: CharSequence,
displayName: String,
replyTo: Int,
sendWithoutNotification: Boolean,
referenceId: String
referenceId: String,
threadTitle: String?
): Flow<Result<ChatMessage?>>

@Suppress("LongParameterList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,22 +608,17 @@ class OfflineFirstChatRepository @Inject constructor(
threadTitle
)

val chatMessageModel = response.ocs?.data?.toDomainModel()

val sentMessage = if (this@OfflineFirstChatRepository::internalConversationId.isInitialized) {
chatDao
.getTempMessageForConversation(
internalConversationId,
referenceId,
threadId
).firstOrNull()
} else {
null
}
val messageJson = response.ocs?.data
val chatMessageModel = messageJson?.toDomainModel()

sentMessage?.let {
it.sendStatus = SendStatus.SENT_PENDING_ACK
chatDao.updateChatMessage(it)
if (messageJson != null && this@OfflineFirstChatRepository::internalConversationId.isInitialized) {
// Persist the authoritative response immediately (correct isThread/threadId/threadTitle
// included) instead of leaving the client-side guess in the temp row until the next sync -
// otherwise a thread indicator only appears after reopening the chat.
chatDao.upsertChatMessagesAndDeleteTemp(
internalConversationId,
listOf(messageJson.asEntity(currentUser.id!!))
)
}

Log.d(TAG, "sending chat message succeeded: " + message)
Expand Down Expand Up @@ -691,13 +686,14 @@ class OfflineFirstChatRepository @Inject constructor(
}
}

@Suppress("Detekt.TooGenericExceptionCaught")
@Suppress("Detekt.TooGenericExceptionCaught", "LongParameterList")
override suspend fun addTemporaryMessage(
message: CharSequence,
displayName: String,
replyTo: Int,
sendWithoutNotification: Boolean,
referenceId: String
referenceId: String,
threadTitle: String?
): Flow<Result<ChatMessage?>> =
flow {
try {
Expand All @@ -706,7 +702,8 @@ class OfflineFirstChatRepository @Inject constructor(
message.toString(),
replyTo,
sendWithoutNotification,
referenceId
referenceId,
threadTitle
)
chatDao.upsertChatMessage(tempChatMessageEntity)
} catch (e: Exception) {
Expand Down Expand Up @@ -1037,12 +1034,14 @@ class OfflineFirstChatRepository @Inject constructor(
emit(Result.failure(e))
}

@Suppress("LongParameterList")
private fun createChatMessageEntity(
internalConversationId: String,
message: String,
replyTo: Int,
sendWithoutNotification: Boolean,
referenceId: String
referenceId: String,
threadTitle: String?
): ChatMessageEntity {
val currentTimeMillis = System.currentTimeMillis()

Expand All @@ -1063,6 +1062,8 @@ class OfflineFirstChatRepository @Inject constructor(
internalConversationId = internalConversationId,
id = negativeTimeOfDayMillis,
threadId = threadId,
isThread = threadTitle != null,
threadTitle = threadTitle,
message = message,
deleted = false,
token = conversationModel.token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ class ChatViewModel @AssistedInject constructor(
private fun handleThreadMessages(chatMessageList: List<ChatMessage>): List<ChatMessage> {
fun isThreadChildMessage(currentMessage: MutableMap.MutableEntry<Int, ChatMessage>): Boolean =
currentMessage.value.isThread &&
currentMessage.value.threadId != null &&
currentMessage.value.threadId?.toInt() != currentMessage.value.jsonMessageId

val chatMessageMap = chatMessageList.associateBy { it.jsonMessageId }.toMutableMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ class MessageInputViewModel :
displayName,
replyTo,
sendWithoutNotification,
referenceId
referenceId,
threadTitle
).collect { result ->
if (result.isSuccess) {
Log.d(TAG, "temp message ref id: " + (result.getOrNull()?.referenceId ?: "none"))
Expand Down
Loading