Skip to content
Draft
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 @@ -268,20 +268,27 @@ class OfflineFirstChatRepository @Inject constructor(
delay(INSURANCE_REQUEST_DELAY)
Log.d(TAG, "execute insurance request with latestKnownMessageIdFromSync: $latestKnownMessageIdFromSync")

var fieldMap = getFieldMap(
lookIntoFuture = true,
timeout = 0,
includeLastKnown = false,
lastKnown = latestKnownMessageIdFromSync.toInt(),
limit = 200
)
val networkParams = Bundle()
networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap)

getAndPersistMessages(networkParams)
fetchNewMessages()
}
}

/**
* Fetches messages newer than latest known message
*/
private suspend fun fetchNewMessages() {
var fieldMap = getFieldMap(
lookIntoFuture = true,
timeout = 0,
includeLastKnown = false,
lastKnown = latestKnownMessageIdFromSync.toInt(),
limit = 200
)
val networkParams = Bundle()
networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap)

getAndPersistMessages(networkParams)
}

override suspend fun loadMoreMessages(
beforeMessageId: Long,
roomToken: String,
Expand Down Expand Up @@ -955,10 +962,16 @@ class OfflineFirstChatRepository @Inject constructor(
}

override suspend fun onSignalingChatMessageReceived(chatMessages: List<ChatMessageJson>) {
if (chatMessages.any { it.messageParameters?.containsKey("file") == true }) {
Log.d(TAG, "onSignalingChatMessageReceived fetch file data")
fetchNewMessages()
return
}

persistChatMessagesAndHandleSystemMessages(chatMessages, emitOnIncoming = true)

// we assume that the signaling messages are on top of the latest chatblock and include them inside it.
// If for whatever reason the assume was not correct and there would be messages in between, the
// If for whatever reason the assumption was not correct and there would be messages in between, the
// insurance request should fix this by adding the missing messages and updating the chatblocks.
val latestChatBlock = chatBlocksDao.getLatestChatBlock(internalConversationId, threadId)
latestChatBlock.first()?.apply {
Expand Down
Loading