extract getCappedMessagesAmountOfChatBlock

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-10-16 15:20:23 +02:00
parent adf18020c1
commit 7eb8b9fa70
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -160,21 +160,7 @@ class OfflineFirstChatRepository @Inject constructor(
Log.d(TAG, "Initial online request is skipped because offline messages are up to date")
}
val chatBlock = getBlockOfMessage(newestMessageIdFromDb.toInt())
val amountBetween = chatDao.getCountBetweenMessageIds(
internalConversationId,
newestMessageIdFromDb,
chatBlock!!.oldestMessageId
)
Log.d(TAG, "amount of messages between newestMessageId and oldest message of same ChatBlock:$amountBetween")
val limit = if (amountBetween > DEFAULT_MESSAGES_LIMIT) {
DEFAULT_MESSAGES_LIMIT
} else {
amountBetween
}
Log.d(TAG, "limit of messages to load for UI (max 100 to ensure performance is okay):$limit")
val limit = getCappedMessagesAmountOfChatBlock(newestMessageIdFromDb)
showMessagesBeforeAndEqual(
internalConversationId,
@ -192,6 +178,25 @@ class OfflineFirstChatRepository @Inject constructor(
initMessagePolling()
}
private suspend fun getCappedMessagesAmountOfChatBlock(messageId: Long): Int {
val chatBlock = getBlockOfMessage(messageId.toInt())
val amountBetween = chatDao.getCountBetweenMessageIds(
internalConversationId,
messageId,
chatBlock!!.oldestMessageId
)
Log.d(TAG, "amount of messages between newestMessageId and oldest message of same ChatBlock:$amountBetween")
val limit = if (amountBetween > DEFAULT_MESSAGES_LIMIT) {
DEFAULT_MESSAGES_LIMIT
} else {
amountBetween
}
Log.d(TAG, "limit of messages to load for UI (max 100 to ensure performance is okay):$limit")
return limit
}
private suspend fun updateUiForLastReadMessage(newestMessageId: Long) {
val scrollToLastRead = conversationModel.lastReadMessage.toLong() < newestMessageId
if (scrollToLastRead) {