mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
fix to handle chats without offline messages when connection is lost
avoid NPE: java.lang.NullPointerException at com.nextcloud.talk.chat.data.network.OfflineFirstChatRepository.getCappedMessagesAmountOfChatBlock(OfflineFirstChatRepository.kt:186) at com.nextcloud.talk.chat.data.network.OfflineFirstChatRepository.access$getCappedMessagesAmountOfChatBlock(OfflineFirstChatRepository.kt:43) at com.nextcloud.talk.chat.data.network.OfflineFirstChatRepository$loadInitialMessages$1.invokeSuspend(OfflineFirstChatRepository.kt:162) Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
7e3a4e4a83
commit
f817c20b4e
@ -159,6 +159,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
Log.d(TAG, "newestMessageIdFromDb after sync: $newestMessageIdFromDb")
|
||||
}
|
||||
|
||||
if (newestMessageIdFromDb.toInt() != 0) {
|
||||
val limit = getCappedMessagesAmountOfChatBlock(newestMessageIdFromDb)
|
||||
|
||||
showMessagesBeforeAndEqual(
|
||||
@ -173,6 +174,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
|
||||
updateUiForLastCommonRead()
|
||||
updateUiForLastReadMessage(newestMessageIdFromDb)
|
||||
}
|
||||
|
||||
initMessagePolling(newestMessageIdFromDb)
|
||||
}
|
||||
@ -180,10 +182,11 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
private suspend fun getCappedMessagesAmountOfChatBlock(messageId: Long): Int {
|
||||
val chatBlock = getBlockOfMessage(messageId.toInt())
|
||||
|
||||
if (chatBlock != null) {
|
||||
val amountBetween = chatDao.getCountBetweenMessageIds(
|
||||
internalConversationId,
|
||||
messageId,
|
||||
chatBlock!!.oldestMessageId
|
||||
chatBlock.oldestMessageId
|
||||
)
|
||||
|
||||
Log.d(TAG, "amount of messages between newestMessageId and oldest message of same ChatBlock:$amountBetween")
|
||||
@ -194,6 +197,10 @@ class OfflineFirstChatRepository @Inject constructor(
|
||||
}
|
||||
Log.d(TAG, "limit of messages to load for UI (max 100 to ensure performance is okay):$limit")
|
||||
return limit
|
||||
} else {
|
||||
Log.e(TAG, "No chat block found. Returning 0 as limit.")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateUiForLastReadMessage(newestMessageId: Long) {
|
||||
|
Loading…
Reference in New Issue
Block a user