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