pass newestMessageIdFromDb to initMessagePolling

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-10-16 16:11:26 +02:00
parent 7eb8b9fa70
commit c81b1fa62f
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 6 additions and 7 deletions

View File

@ -56,10 +56,8 @@ interface ChatMessageRepository : LifecycleAwareManager {
* Long polls the server for any updates to the chat, if found, it synchronizes
* the database with the server and emits the new messages to [messageFlow],
* else it simply retries after timeout.
*
* [withNetworkParams] credentials and url.
*/
fun initMessagePolling(): Job
fun initMessagePolling(initialMessageId: Long): Job
/**
* Gets a individual message.

View File

@ -158,6 +158,8 @@ class OfflineFirstChatRepository @Inject constructor(
Log.d(TAG, "newestMessageId after sync: $newestMessageIdFromDb")
} else {
Log.d(TAG, "Initial online request is skipped because offline messages are up to date")
// if conversationModel was not up to date and there are new messages, they will just get pulled with
// look into future.. Old messages will be displayed immediately beforehand.
}
val limit = getCappedMessagesAmountOfChatBlock(newestMessageIdFromDb)
@ -175,7 +177,7 @@ class OfflineFirstChatRepository @Inject constructor(
updateUiForLastCommonRead()
updateUiForLastReadMessage(newestMessageIdFromDb)
initMessagePolling()
initMessagePolling(newestMessageIdFromDb)
}
private suspend fun getCappedMessagesAmountOfChatBlock(messageId: Long): Int {
@ -240,18 +242,17 @@ class OfflineFirstChatRepository @Inject constructor(
updateUiForLastCommonRead()
}
override fun initMessagePolling(): Job =
override fun initMessagePolling(initialMessageId: Long): Job =
scope.launch {
Log.d(TAG, "---- initMessagePolling ------------")
val initialMessageId = chatDao.getNewestMessageId(internalConversationId).toInt()
Log.d(TAG, "newestMessage: $initialMessageId")
var fieldMap = getFieldMap(
lookIntoFuture = true,
includeLastKnown = false,
setReadMarker = true,
lastKnown = initialMessageId
lastKnown = initialMessageId.toInt()
)
val networkParams = Bundle()