From e308512bfd61d4cf27e493bdcb7a2a6bbb194a70 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 9 Mar 2023 09:21:39 +0400 Subject: [PATCH] Filter duplicate group ids --- .../Sources/ChatHistoryEntriesForView.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/submodules/TelegramUI/Sources/ChatHistoryEntriesForView.swift b/submodules/TelegramUI/Sources/ChatHistoryEntriesForView.swift index 953eaae337..9c24366eff 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryEntriesForView.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryEntriesForView.swift @@ -77,7 +77,8 @@ func chatHistoryEntriesForView( associatedThreadInfo: nil ) } - + + var existingGroupStableIds: [UInt32] = [] var groupBucket: [(Message, Bool, ChatHistoryMessageSelection, ChatMessageEntryAttributes, MessageHistoryEntryLocation?)] = [] var count = 0 loop: for entry in view.entries { @@ -156,7 +157,11 @@ func chatHistoryEntriesForView( if groupMessages { if !groupBucket.isEmpty && message.groupInfo != groupBucket[0].0.groupInfo { - entries.append(.MessageGroupEntry(groupBucket[0].0.groupInfo!, groupBucket, presentationData)) + let groupStableId = groupBucket[0].0.groupInfo!.stableId + if !existingGroupStableIds.contains(groupStableId) { + existingGroupStableIds.append(groupStableId) + entries.append(.MessageGroupEntry(groupBucket[0].0.groupInfo!, groupBucket, presentationData)) + } groupBucket.removeAll() } if let _ = message.groupInfo { @@ -189,7 +194,14 @@ func chatHistoryEntriesForView( if !groupBucket.isEmpty { assert(groupMessages) - entries.append(.MessageGroupEntry(groupBucket[0].0.groupInfo!, groupBucket, presentationData)) + + let groupStableId = groupBucket[0].0.groupInfo!.stableId + if !existingGroupStableIds.contains(groupStableId) { + existingGroupStableIds.append(groupStableId) + entries.append(.MessageGroupEntry(groupBucket[0].0.groupInfo!, groupBucket, presentationData)) + } + + groupBucket.removeAll() } if let maybeJoinMessage = joinMessage, !view.holeLater {