From 0812748df5b5382909479e6b83944a01130f1f1b Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Sat, 13 Jun 2026 10:45:42 +0000 Subject: [PATCH] android, desktop: fix message preview and unread count applied to the wrong chat When a member support chat or group reports view is open (a secondary chats context is active), incoming messages could overwrite the last-message preview of an unrelated chat in the main chat list, increment the wrong chat's unread badge, and pop the wrong chat to the top. ChatsContext.addChatItem computed the chat index against the receiver context's own list via getChatIndex, but then read/wrote chatsContext.chats[i], which always refers to the primary (main) chat list. On the secondary context the two lists are ordered differently, so the index pointed at a different chat. Use the receiver context's own list (chats[i]) consistently, matching every other method in ChatsContext and the iOS implementation. No change for the primary context, where chats and chatsContext.chats are the same list. --- .../kotlin/chat/simplex/common/model/ChatModel.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 a755b8bc6e..aec7160b3c 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 @@ -533,7 +533,7 @@ object ChatModel { val i = getChatIndex(rhId, cInfo.id) val chat: Chat if (i >= 0) { - chat = chatsContext.chats[i] + chat = chats[i] // update preview (for chat from main scope to show new items for invitee in pending status) if (cInfo.groupChatScope() == null || cInfo.groupInfo_?.membership?.memberPending == true) { val newPreviewItem = when (cInfo) { @@ -553,7 +553,7 @@ object ChatModel { else -> cItem } val wasUnread = chat.unreadTag - chatsContext.chats[i] = chat.copy( + chats[i] = chat.copy( chatItems = arrayListOf(newPreviewItem), chatStats = if (cItem.meta.itemStatus is CIStatus.RcvNew) { @@ -562,11 +562,11 @@ object ChatModel { } else chat.chatStats ) - updateChatTagReadInPrimaryContext(chatsContext.chats[i], wasUnread) + updateChatTagReadInPrimaryContext(chats[i], wasUnread) } // pop chat if (appPlatform.isDesktop && cItem.chatDir.sent) { - reorderChat(chatsContext.chats[i], 0) + reorderChat(chats[i], 0) } else { popChatCollector.throttlePopChat(chat.remoteHostId, chat.id, currentPosition = i) }