From 3412ceba01c64aa2c2584254d10ad6ef14b9d83b Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Fri, 7 Mar 2025 23:49:55 +0700 Subject: [PATCH] android, desktop: fix group members duplicates (#5727) * android, desktop: fix group members duplicates * optimization * use groupMemberId as key --------- Co-authored-by: Evgeny Poberezkin --- .../commonMain/kotlin/chat/simplex/common/model/ChatModel.kt | 5 +++++ .../chat/simplex/common/views/chat/group/GroupMentions.kt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index 85db407a20..13cdc9f19a 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -789,6 +789,11 @@ object ChatModel { } // update current chat return if (chatId.value == groupInfo.id) { + if (groupMembers.value.isNotEmpty() && groupMembers.value.firstOrNull()?.groupId != groupInfo.groupId) { + // stale data, should be cleared at that point, otherwise, duplicated items will be here which will produce crashes in LazyColumn + groupMembers.value = emptyList() + groupMembersIndexes.value = emptyMap() + } val memberIndex = groupMembersIndexes.value[member.groupMemberId] val updated = chatItems.value.map { // Take into account only specific changes, not all. Other member updates are not important and can be skipped diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupMentions.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupMentions.kt index 89ef19dcda..1a63375432 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupMentions.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupMentions.kt @@ -196,7 +196,7 @@ fun GroupMentions( MaxMentionsReached() } } - itemsIndexed(filteredMembers.value, key = { _, item -> item.memberId }) { i, member -> + itemsIndexed(filteredMembers.value, key = { _, item -> item.groupMemberId }) { i, member -> if (i != 0 || !showMaxReachedBox) { Divider() }