From e873a323a71358c17394c259d4649279df76f6df Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:40:06 +0700 Subject: [PATCH] unneeded updates and fixes --- .../chat/simplex/common/model/ChatModel.kt | 71 +++++++++---------- .../chat/simplex/common/model/SimpleXAPI.kt | 12 ---- .../simplex/common/views/chat/ChatInfoView.kt | 5 -- .../simplex/common/views/chat/ChatView.kt | 35 ++++----- .../views/chat/group/GroupProfileView.kt | 3 - .../views/chat/group/WelcomeMessageView.kt | 3 - .../views/chatlist/ChatListNavLinkView.kt | 9 --- .../common/views/chatlist/TagListView.kt | 6 -- 8 files changed, 50 insertions(+), 94 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 acee4f6181..5c7eb76307 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 @@ -670,10 +670,10 @@ object ChatModel { fun markChatItemsRead(remoteHostId: Long?, chatInfo: ChatInfo, itemIds: List? = null) { val cInfo = chatInfo - val markedRead = markItemsReadInCurrentChat(chatInfo, contentTag, itemIds) + val markedRead = markItemsReadInCurrentChat(chatInfo, itemIds) // update preview val chatIdx = getChatIndex(remoteHostId, cInfo.id) - if (chatIdx >= 0) { + if (chatIdx >= 0 && contentTag == null) { val chat = chats[chatIdx] val lastId = chat.chatItems.lastOrNull()?.id if (lastId != null) { @@ -688,6 +688,39 @@ object ChatModel { } } + private fun markItemsReadInCurrentChat(chatInfo: ChatInfo, itemIds: List? = null): Int { + val cInfo = chatInfo + var markedRead = 0 + if (chatId.value == cInfo.id) { + val items = chatItems.value + var i = items.lastIndex + val itemIdsFromRange = itemIds?.toMutableSet() ?: mutableSetOf() + val markedReadIds = mutableSetOf() + while (i >= 0) { + val item = items[i] + if (item.meta.itemStatus is CIStatus.RcvNew && (itemIds == null || itemIdsFromRange.contains(item.id))) { + val newItem = item.withStatus(CIStatus.RcvRead()) + items[i] = newItem + if (newItem.meta.itemLive != true && newItem.meta.itemTimed?.ttl != null) { + items[i] = newItem.copy(meta = newItem.meta.copy(itemTimed = newItem.meta.itemTimed.copy( + deleteAt = Clock.System.now() + newItem.meta.itemTimed.ttl.toDuration(DurationUnit.SECONDS))) + ) + } + markedReadIds.add(item.id) + markedRead++ + if (itemIds != null) { + itemIdsFromRange.remove(item.id) + // already set all needed items as read, can finish the loop + if (itemIdsFromRange.isEmpty()) break + } + } + i-- + } + chatItemsChangesListener?.read(if (itemIds != null) markedReadIds else null, items) + } + return markedRead + } + private fun decreaseCounterInChat(rhId: Long?, chatId: ChatId) { val chatIndex = getChatIndex(rhId, chatId) if (chatIndex == -1) return @@ -814,40 +847,6 @@ object ChatModel { } } - private fun markItemsReadInCurrentChat(chatInfo: ChatInfo, contentTag: MsgContentTag?, itemIds: List? = null): Int { - val cInfo = chatInfo - var markedRead = 0 - if (chatId.value == cInfo.id) { - val items = chatItemsForContent(contentTag).value - var i = items.lastIndex - val itemIdsFromRange = itemIds?.toMutableSet() ?: mutableSetOf() - val markedReadIds = mutableSetOf() - while (i >= 0) { - val item = items[i] - if (item.meta.itemStatus is CIStatus.RcvNew && (itemIds == null || itemIdsFromRange.contains(item.id))) { - val newItem = item.withStatus(CIStatus.RcvRead()) - items[i] = newItem - if (newItem.meta.itemLive != true && newItem.meta.itemTimed?.ttl != null) { - items[i] = newItem.copy(meta = newItem.meta.copy(itemTimed = newItem.meta.itemTimed.copy( - deleteAt = Clock.System.now() + newItem.meta.itemTimed.ttl.toDuration(DurationUnit.SECONDS))) - ) - } - markedReadIds.add(item.id) - markedRead++ - if (itemIds != null) { - itemIdsFromRange.remove(item.id) - // already set all needed items as read, can finish the loop - if (itemIdsFromRange.isEmpty()) break - } - } - i-- - } - // TODO LALAL - chatsContext.chatItemsChangesListener?.read(if (itemIds != null) markedReadIds else null, items) - } - return markedRead - } - fun increaseUnreadCounter(rhId: Long?, user: UserLike) { changeUnreadCounter(rhId, user, 1) } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index e38b958339..fc6fc0631e 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -2634,9 +2634,6 @@ object ChatController { withChats { updateGroup(rhId, r.groupInfo) } - withReportsChatsIfOpen { - updateGroup(rhId, r.groupInfo) - } } is CR.DeletedMember -> if (active(r.user)) { @@ -2688,9 +2685,6 @@ object ChatController { withChats { updateGroup(rhId, r.groupInfo) } - withReportsChatsIfOpen { - updateGroup(rhId, r.groupInfo) - } } is CR.UserJoinedGroup -> if (active(r.user)) { @@ -2719,9 +2713,6 @@ object ChatController { withChats { updateGroup(rhId, r.toGroup) } - withReportsChatsIfOpen { - updateGroup(rhId, r.toGroup) - } } is CR.NewMemberContactReceivedInv -> if (active(r.user)) { @@ -3052,9 +3043,6 @@ object ChatController { withChats { updateGroup(rh, groupInfo) } - withReportsChatsIfOpen { - updateGroup(rh, groupInfo) - } } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt index 8b0f5b4a72..afff6a9561 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt @@ -1251,11 +1251,6 @@ suspend fun save(applyToMode: DefaultThemeMode?, newTheme: ThemeModeOverride?, c updateChatInfo(chat.remoteHostId, chat.chatInfo.copy(groupInfo = chat.chatInfo.groupInfo.copy(uiThemes = changedThemes))) } } - withReportsChatsIfOpen { - if (chat.chatInfo is ChatInfo.Group) { - updateChatInfo(chat.remoteHostId, chat.chatInfo.copy(groupInfo = chat.chatInfo.groupInfo.copy(uiThemes = changedThemes))) - } - } } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt index 4ca9e1601d..d5b3845db4 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt @@ -396,10 +396,12 @@ fun ChatView( } } withReportsChatsIfOpen { - if (toChatItem != null) { - upsertChatItem(chatRh, chatInfo, toChatItem) - } else { - removeChatItem(chatRh, chatInfo, deletedChatItem) + if (deletedChatItem.content.msgContent is MsgContent.MCReport) { + if (toChatItem != null) { + upsertChatItem(chatRh, chatInfo, toChatItem) + } else { + removeChatItem(chatRh, chatInfo, deletedChatItem) + } } } } @@ -584,10 +586,7 @@ fun ChatView( ) } withReportsChatsIfOpen { - // It's important to call it on Main thread. Otherwise, composable crash occurs from time-to-time without useful stacktrace - withContext(Dispatchers.Main) { - markChatItemsRead(chatRh, chatInfo, itemsIds) - } + markChatItemsRead(chatRh, chatInfo, itemsIds) } } }, @@ -606,10 +605,7 @@ fun ChatView( ) } withReportsChatsIfOpen { - // It's important to call it on Main thread. Otherwise, composable crash occurs from time-to-time without useful stacktrace - withContext(Dispatchers.Main) { - markChatItemsRead(chatRh, chatInfo) - } + markChatItemsRead(chatRh, chatInfo) } } }, @@ -2291,11 +2287,13 @@ private fun deleteMessages(chatRh: Long?, chatInfo: ChatInfo, itemIds: List Unit) { withChats { updateGroup(rhId, group) } - withReportsChatsIfOpen { - updateGroup(rhId, group) - } } else -> {} @@ -466,9 +463,6 @@ private fun deleteTag(rhId: Long?, tag: ChatTag, saving: MutableState) withChats { updateGroup(rhId, group) } - withReportsChatsIfOpen { - updateGroup(rhId, group) - } } else -> {} }