mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 21:45:42 +03:00
Reduce complexity for 'ChatController#processMessagesFromTheFuture'
Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
d0df4039c6
commit
ae0a9d6aae
1 changed files with 32 additions and 25 deletions
|
@ -2373,7 +2373,6 @@ class ChatController(args: Bundle) :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processMessagesFromTheFuture(chatMessageList: List<ChatMessage>) {
|
private fun processMessagesFromTheFuture(chatMessageList: List<ChatMessage>) {
|
||||||
var chatMessage: ChatMessage
|
|
||||||
|
|
||||||
val shouldAddNewMessagesNotice = (adapter?.itemCount ?: 0) > 0 && chatMessageList.isNotEmpty()
|
val shouldAddNewMessagesNotice = (adapter?.itemCount ?: 0) > 0 && chatMessageList.isNotEmpty()
|
||||||
|
|
||||||
|
@ -2386,14 +2385,25 @@ class ChatController(args: Bundle) :
|
||||||
adapter?.addToStart(unreadChatMessage, false)
|
adapter?.addToStart(unreadChatMessage, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val isThereANewNotice =
|
|
||||||
shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1
|
|
||||||
|
|
||||||
determinePreviousMessageIds(chatMessageList)
|
determinePreviousMessageIds(chatMessageList)
|
||||||
|
|
||||||
for (i in chatMessageList.indices) {
|
addMessagesToAdapter(shouldAddNewMessagesNotice, chatMessageList)
|
||||||
chatMessage = chatMessageList[i]
|
|
||||||
|
|
||||||
|
if (shouldAddNewMessagesNotice && adapter != null) {
|
||||||
|
layoutManager?.scrollToPositionWithOffset(
|
||||||
|
adapter!!.getMessagePositionByIdInReverse("-1"),
|
||||||
|
binding.messagesListView.height / 2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addMessagesToAdapter(
|
||||||
|
shouldAddNewMessagesNotice: Boolean,
|
||||||
|
chatMessageList: List<ChatMessage>
|
||||||
|
) {
|
||||||
|
val isThereANewNotice =
|
||||||
|
shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1
|
||||||
|
for (chatMessage in chatMessageList) {
|
||||||
chatMessage.activeUser = conversationUser
|
chatMessage.activeUser = conversationUser
|
||||||
|
|
||||||
val shouldScroll =
|
val shouldScroll =
|
||||||
|
@ -2403,36 +2413,33 @@ class ChatController(args: Bundle) :
|
||||||
adapter != null &&
|
adapter != null &&
|
||||||
adapter?.itemCount == 0
|
adapter?.itemCount == 0
|
||||||
|
|
||||||
if (!shouldAddNewMessagesNotice && !shouldScroll) {
|
modifyMessageCount(shouldAddNewMessagesNotice, shouldScroll)
|
||||||
if (!binding.popupBubbleView.isShown) {
|
|
||||||
newMessagesCount = 1
|
|
||||||
binding.popupBubbleView.show()
|
|
||||||
} else if (binding.popupBubbleView.isShown) {
|
|
||||||
newMessagesCount++
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newMessagesCount = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if (adapter != null) {
|
adapter?.let {
|
||||||
chatMessage.isGrouped = (
|
chatMessage.isGrouped = (
|
||||||
adapter!!.isPreviousSameAuthor(
|
it.isPreviousSameAuthor(
|
||||||
chatMessage.actorId,
|
chatMessage.actorId,
|
||||||
-1
|
-1
|
||||||
) && adapter!!.getSameAuthorLastMessagesCount(chatMessage.actorId) %
|
) && it.getSameAuthorLastMessagesCount(chatMessage.actorId) %
|
||||||
GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0
|
GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0
|
||||||
)
|
)
|
||||||
chatMessage.isOneToOneConversation =
|
chatMessage.isOneToOneConversation =
|
||||||
(currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
|
(currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
|
||||||
adapter?.addToStart(chatMessage, shouldScroll)
|
it.addToStart(chatMessage, shouldScroll)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldAddNewMessagesNotice && adapter != null) {
|
private fun modifyMessageCount(shouldAddNewMessagesNotice: Boolean, shouldScroll: Boolean) {
|
||||||
layoutManager?.scrollToPositionWithOffset(
|
if (!shouldAddNewMessagesNotice && !shouldScroll) {
|
||||||
adapter!!.getMessagePositionByIdInReverse("-1"),
|
if (!binding.popupBubbleView.isShown) {
|
||||||
binding.messagesListView.height / 2
|
newMessagesCount = 1
|
||||||
)
|
binding.popupBubbleView.show()
|
||||||
|
} else if (binding.popupBubbleView.isShown) {
|
||||||
|
newMessagesCount++
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newMessagesCount = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue