From c81fa7e6b0e4d47f0d23686b7b738e4ee2832a4b Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Mon, 24 Feb 2025 14:50:30 +0700 Subject: [PATCH] android, desktop: marking chat read fix (#5658) * android, desktop: marking chat read fix * comments --- apps/ios/SimpleXChat/ChatTypes.swift | 1 + .../kotlin/chat/simplex/common/model/ChatModel.kt | 3 ++- .../chat/simplex/common/views/chat/ChatItemsLoader.kt | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/ios/SimpleXChat/ChatTypes.swift b/apps/ios/SimpleXChat/ChatTypes.swift index 60d5082584..554207e90d 100644 --- a/apps/ios/SimpleXChat/ChatTypes.swift +++ b/apps/ios/SimpleXChat/ChatTypes.swift @@ -1612,6 +1612,7 @@ public struct ChatStats: Decodable, Hashable { // actual only via getChats() and getChat(.initial), otherwise, zero public var reportsCount: Int = 0 public var minUnreadItemId: Int64 = 0 + // actual only via getChats(), otherwise, false public var unreadChat: Bool = false } 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 04fd6b380d..656937641c 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 @@ -1233,10 +1233,11 @@ data class Chat( @Serializable data class ChatStats( val unreadCount: Int = 0, - // actual only via getChats() and getChat(.initial), otherwise, zero val unreadMentions: Int = 0, + // actual only via getChats() and getChat(.initial), otherwise, zero val reportsCount: Int = 0, val minUnreadItemId: Long = 0, + // actual only via getChats(), otherwise, false val unreadChat: Boolean = false ) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt index 3613ceaa7c..6a8c277ae1 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt @@ -54,11 +54,13 @@ suspend fun processLoadedChat( if (contentTag == null) { // update main chats, not content tagged withChats { - if (getChat(chat.id) == null) { + val oldChat = getChat(chat.id) + if (oldChat == null) { addChat(chat) } else { updateChatInfo(chat.remoteHostId, chat.chatInfo) - updateChatStats(chat.remoteHostId, chat.id, chat.chatStats) + // unreadChat is currently not actual in getChat query (always false) + updateChatStats(chat.remoteHostId, chat.id, chat.chatStats.copy(unreadChat = oldChat.chatStats.unreadChat)) } } }