From 2210d5427d056ec2b12dbfa563ce6875f8908815 Mon Sep 17 00:00:00 2001 From: Diogo Date: Sat, 21 Sep 2024 23:33:30 +0100 Subject: [PATCH] fixed message grouping and time show --- .../simplex/common/views/chat/ChatView.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt index f7ee924993..62365e1957 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt @@ -1197,7 +1197,7 @@ fun BoxWithConstraintsScope.ChatItemsList( // memberConnected events and deleted items are aggregated at the last chat item in a row, see ChatItemView } else { val (prevHidden, prevItem) = chatModel.getPrevShownChatItem(currIndex, ciCategory) - val itemSeparation = getItemSeparation(cItem, prevItem) + val itemSeparation = getItemSeparation(cItem, prevItem, nextItem) val range = chatViewItemsRange(currIndex, prevHidden) if (revealed.value && range != null) { reversedChatItems.subList(range.first, range.last + 1).forEachIndexed { index, ci -> @@ -1899,8 +1899,8 @@ private fun handleForwardConfirmation( ) } -private fun getItemSeparation(chatItem: ChatItem, nextItem: ChatItem?): ItemSeparation { - if (nextItem == null) { +private fun getItemSeparation(chatItem: ChatItem, prevItem: ChatItem?, nextItem: ChatItem?): ItemSeparation { + if (prevItem == null) { return ItemSeparation( timestamp = true, largeGap = false, @@ -1908,15 +1908,25 @@ private fun getItemSeparation(chatItem: ChatItem, nextItem: ChatItem?): ItemSepa ) } + if (nextItem == null) { + return ItemSeparation( + timestamp = true, + largeGap = false, + date = if (getTimestampDateText(chatItem.meta.itemTs) != getTimestampDateText(prevItem.meta.itemTs)) chatItem.meta.itemTs else null + ) + } + val sameMemberAndDirection = if (nextItem.chatDir is GroupRcv && chatItem.chatDir is GroupRcv) { chatItem.chatDir.groupMember.groupMemberId == nextItem.chatDir.groupMember.groupMemberId } else chatItem.chatDir.sent == nextItem.chatDir.sent val largeGap = !sameMemberAndDirection || (abs(nextItem.meta.createdAt.epochSeconds - chatItem.meta.createdAt.epochSeconds) >= 60) + Log.e(TAG, "getItemSeparation: next: ${nextItem.text} prev: ${prevItem.text} curr: ${chatItem.text}") + return ItemSeparation( - timestamp = largeGap || chatItem.meta.timestampText != nextItem.meta.timestampText, + timestamp = largeGap || nextItem.meta.timestampText != chatItem.meta.timestampText, largeGap = largeGap, - date = if (getTimestampDateText(chatItem.meta.itemTs) != getTimestampDateText(nextItem.meta.itemTs)) chatItem.meta.itemTs else null + date = if (getTimestampDateText(chatItem.meta.itemTs) != getTimestampDateText(prevItem.meta.itemTs)) chatItem.meta.itemTs else null ) }