mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-09 22:04:24 +01:00
fix unread message behavior
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
b1bd50747b
commit
5810d070fa
@ -3759,8 +3759,10 @@ class ChatActivity :
|
||||
}
|
||||
|
||||
private fun processMessagesFromTheFuture(chatMessageList: List<ChatMessage>) {
|
||||
val shouldAddNewMessagesNotice = layoutManager?.findFirstVisibleItemPosition()!! > 0
|
||||
if (shouldAddNewMessagesNotice) {
|
||||
val insertNewMessagesNotice = (adapter?.itemCount ?: 0) > 0 && chatMessageList.isNotEmpty()
|
||||
val scrollToEndOnUpdate = layoutManager?.findFirstVisibleItemPosition() == 0
|
||||
|
||||
if (insertNewMessagesNotice) {
|
||||
val unreadChatMessage = ChatMessage()
|
||||
unreadChatMessage.jsonMessageId = -1
|
||||
unreadChatMessage.actorId = "-1"
|
||||
@ -3769,7 +3771,41 @@ class ChatActivity :
|
||||
adapter?.addToStart(unreadChatMessage, false)
|
||||
}
|
||||
|
||||
addMessagesToAdapter(shouldAddNewMessagesNotice, chatMessageList)
|
||||
if (!scrollToEndOnUpdate) {
|
||||
binding.popupBubbleView.isShown.let {
|
||||
if (it) {
|
||||
newMessagesCount++
|
||||
} else {
|
||||
newMessagesCount = 1
|
||||
binding.scrollDownButton.visibility = View.GONE
|
||||
binding.popupBubbleView.show()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
binding.scrollDownButton.visibility = View.GONE
|
||||
newMessagesCount = 0
|
||||
}
|
||||
|
||||
for (chatMessage in chatMessageList) {
|
||||
chatMessage.activeUser = conversationUser
|
||||
|
||||
adapter?.let {
|
||||
chatMessage.isGrouped = (
|
||||
it.isPreviousSameAuthor(chatMessage.actorId, -1) &&
|
||||
it.getSameAuthorLastMessagesCount(chatMessage.actorId) %
|
||||
GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0
|
||||
)
|
||||
chatMessage.isOneToOneConversation =
|
||||
(currentConversation?.type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
|
||||
chatMessage.isFormerOneToOneConversation =
|
||||
(currentConversation?.type == ConversationType.FORMER_ONE_TO_ONE)
|
||||
it.addToStart(chatMessage, scrollToEndOnUpdate)
|
||||
}
|
||||
}
|
||||
|
||||
if (insertNewMessagesNotice && scrollToEndOnUpdate && adapter != null) {
|
||||
scrollToFirstUnreadMessage()
|
||||
}
|
||||
}
|
||||
|
||||
private fun processMessagesNotFromTheFuture(chatMessageList: List<ChatMessage>) {
|
||||
@ -3814,53 +3850,6 @@ class ChatActivity :
|
||||
}
|
||||
}
|
||||
|
||||
private fun addMessagesToAdapter(shouldAddNewMessagesNotice: Boolean, chatMessageList: List<ChatMessage>) {
|
||||
val isThereANewNotice =
|
||||
shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1
|
||||
for (chatMessage in chatMessageList) {
|
||||
chatMessage.activeUser = conversationUser
|
||||
|
||||
val shouldScroll =
|
||||
!isThereANewNotice &&
|
||||
!shouldAddNewMessagesNotice &&
|
||||
layoutManager?.findFirstVisibleItemPosition() == 0 ||
|
||||
adapter != null &&
|
||||
adapter?.itemCount == 0
|
||||
|
||||
modifyMessageCount(shouldAddNewMessagesNotice, shouldScroll)
|
||||
|
||||
adapter?.let {
|
||||
chatMessage.isGrouped = (
|
||||
it.isPreviousSameAuthor(chatMessage.actorId, -1) &&
|
||||
it.getSameAuthorLastMessagesCount(chatMessage.actorId) %
|
||||
GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0
|
||||
)
|
||||
chatMessage.isOneToOneConversation =
|
||||
(currentConversation?.type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
|
||||
chatMessage.isFormerOneToOneConversation =
|
||||
(currentConversation?.type == ConversationType.FORMER_ONE_TO_ONE)
|
||||
it.addToStart(chatMessage, shouldScroll)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun modifyMessageCount(shouldAddNewMessagesNotice: Boolean, shouldScroll: Boolean) {
|
||||
if (shouldAddNewMessagesNotice) {
|
||||
binding.popupBubbleView.isShown.let {
|
||||
if (it) {
|
||||
newMessagesCount++
|
||||
} else {
|
||||
newMessagesCount = 1
|
||||
binding.scrollDownButton.visibility = View.GONE
|
||||
binding.popupBubbleView.show()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
binding.scrollDownButton.visibility = View.GONE
|
||||
newMessagesCount = 0
|
||||
}
|
||||
}
|
||||
|
||||
private fun determinePreviousMessageIds(chatMessageList: List<ChatMessage>) {
|
||||
var previousMessageId = NO_PREVIOUS_MESSAGE_ID
|
||||
for (i in chatMessageList.indices.reversed()) {
|
||||
|
Loading…
Reference in New Issue
Block a user