Merge pull request #4865 from nextcloud/bugfix/4864/fixNpeOnLoadMore

avoid NPE in onLoadMore
This commit is contained in:
Marcel Hibbe 2025-04-14 13:39:31 +00:00 committed by GitHub
commit d617d65af2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2818,21 +2818,23 @@ class ChatActivity :
DateFormatter.isSameDay(message1.createdAt, message2.createdAt)
override fun onLoadMore(page: Int, totalItemsCount: Int) {
val id = (
adapter?.items?.last {
it.item is ChatMessage
}?.item as ChatMessage
).jsonMessageId
val messageId = (
adapter?.items
?.lastOrNull { it.item is ChatMessage }
?.item as? ChatMessage
)?.jsonMessageId
val urlForChatting = ApiUtils.getUrlForChat(chatApiVersion, conversationUser?.baseUrl, roomToken)
messageId?.let {
val urlForChatting = ApiUtils.getUrlForChat(chatApiVersion, conversationUser?.baseUrl, roomToken)
chatViewModel.loadMoreMessages(
beforeMessageId = id.toLong(),
withUrl = urlForChatting,
withCredentials = credentials!!,
withMessageLimit = MESSAGE_PULL_LIMIT,
roomToken = currentConversation!!.token
)
chatViewModel.loadMoreMessages(
beforeMessageId = it.toLong(),
withUrl = urlForChatting,
withCredentials = credentials!!,
withMessageLimit = MESSAGE_PULL_LIMIT,
roomToken = currentConversation!!.token
)
}
}
override fun format(date: Date): String =