From 2e78e8acf5955ff078a15a4318a465a295406da3 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Sat, 10 Aug 2024 12:27:37 +0900 Subject: [PATCH] android, desktop: fix to chat throttler --- .../kotlin/chat/simplex/common/model/ChatModel.kt | 10 ++++++---- 1 file changed, 6 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 19c8b11ca5..78c34e2e2d 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 @@ -206,7 +206,10 @@ object ChatModel { class ChatsContext { val chats = _chats - fun addChat(chat: Chat) = chats.add(index = 0, chat) + fun addChat(chat: Chat) { + chat.popTs = Clock.System.now() + chats.add(index = 0, chat) + } fun updateChatInfo(rhId: Long?, cInfo: ChatInfo) { val i = getChatIndex(rhId, cInfo.id) @@ -252,8 +255,7 @@ object ChatModel { } fun updateChats(newChats: List) { - chats.clear() - chats.addAll(newChats) + chats.replaceAll(newChats) val cId = chatId.value // If chat is null, it was deleted in background after apiGetChats call @@ -268,7 +270,7 @@ object ChatModel { chats[i] = chat } else { // invalid state, correcting - chats.add(index = 0, chat) + addChat(chat) } } suspend fun addChatItem(rhId: Long?, cInfo: ChatInfo, cItem: ChatItem) {