mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
extract getCappedMessagesAmountOfChatBlock
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
adf18020c1
commit
7eb8b9fa70
@ -160,21 +160,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
Log.d(TAG, "Initial online request is skipped because offline messages are up to date")
|
Log.d(TAG, "Initial online request is skipped because offline messages are up to date")
|
||||||
}
|
}
|
||||||
|
|
||||||
val chatBlock = getBlockOfMessage(newestMessageIdFromDb.toInt())
|
val limit = getCappedMessagesAmountOfChatBlock(newestMessageIdFromDb)
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
showMessagesBeforeAndEqual(
|
showMessagesBeforeAndEqual(
|
||||||
internalConversationId,
|
internalConversationId,
|
||||||
@ -192,6 +178,25 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
initMessagePolling()
|
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) {
|
private suspend fun updateUiForLastReadMessage(newestMessageId: Long) {
|
||||||
val scrollToLastRead = conversationModel.lastReadMessage.toLong() < newestMessageId
|
val scrollToLastRead = conversationModel.lastReadMessage.toLong() < newestMessageId
|
||||||
if (scrollToLastRead) {
|
if (scrollToLastRead) {
|
||||||
|
Loading…
Reference in New Issue
Block a user