From 10c905dbdd96a45ff6340b794d587281fcada375 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Wed, 19 Aug 2026 09:24:11 +0000 Subject: [PATCH] android, desktop: fix chat preview and unread counter updating wrong chat ChatsContext has two live instances: the primary chat list and the secondary context used by the reports and member support views. In addChatItem the chat index is resolved against the receiver context (getChatIndex reads this.chats), but the list being read and written was chatsContext.chats - always the primary singleton. On the secondary context the two lists hold different chats in a different order, so the index pointed at an unrelated chat in the main list, which then received the last message preview, the unread increment and the pop to the top. Use the receiver context's own list, as every other method in the class already does. This reverts the unintended part of b97e1e0f1 and keeps its memberPending guard. --- .../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 11da8b874e..b532246f48 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) }