From 3fabeef49f03022de323ade4ba1594835e4b00a1 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:21:51 +0700 Subject: [PATCH] changes --- .../chat/simplex/common/model/ChatModel.kt | 21 +++++++++ .../chat/simplex/common/model/SimpleXAPI.kt | 19 +++++--- .../common/views/chat/ChatItemsLoader.kt | 14 +++--- .../simplex/common/views/chat/ChatView.kt | 18 ++++++-- .../views/chat/group/GroupReportsView.kt | 44 ++++++++++++------- .../common/views/chatlist/ChatPreviewView.kt | 14 ++++++ 6 files changed, 99 insertions(+), 31 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 2ab2ceb9b9..b4d2c085f6 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 @@ -393,6 +393,13 @@ object ChatModel { } } + fun updateChatStats(rhId: Long?, chatId: ChatId, chatStats: Chat.ChatStats) { + val i = getChatIndex(rhId, chatId) + if (i >= 0) { + chats[i] = chats[i].copy(chatStats = chatStats) + } + } + suspend fun updateContactConnection(rhId: Long?, contactConnection: PendingContactConnection) = updateChat(rhId, ChatInfo.ContactConnection(contactConnection)) suspend fun updateContact(rhId: Long?, contact: Contact) = updateChat(rhId, ChatInfo.Direct(contact), addMissing = contact.directOrUsed) @@ -792,6 +799,20 @@ object ChatModel { changeUnreadCounterNoContentTag(rhId, user, -by) } + fun decreaseGroupReportsCounter(rhId: Long?, chatId: ChatId, wasArchived: Boolean) { + return + val i = getChatIndex(rhId, chatId) + if (i >= 0) { + val chat = chats.value[i] + chats[i] = chat.copy( + chatStats = chat.chatStats.copy( + reportsCount = (chat.chatStats.reportsCount - 1).coerceAtLeast(0), + archivedReportsCount = if (wasArchived) chat.chatStats.archivedReportsCount + 1 else chat.chatStats.archivedReportsCount + ) + ) + } + } + private fun changeUnreadCounterNoContentTag(rhId: Long?, user: UserLike, by: Int) { // updates anything only in main ChatView, not GroupReportsView or anything else from the future if (contentTag != null) return 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 1319960439..f4d2921f4a 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 @@ -2481,7 +2481,7 @@ object ChatController { addChatItem(rhId, cInfo, cItem) } withReportsChatsIfOpen { - if (cItem.content.msgContent is MsgContent.MCReport) { + if (cItem.isReport) { addChatItem(rhId, cInfo, cItem) } } @@ -2512,7 +2512,7 @@ object ChatController { updateChatItem(cInfo, cItem, status = cItem.meta.itemStatus) } withReportsChatsIfOpen { - if (cItem.content.msgContent is MsgContent.MCReport) { + if (cItem.isReport) { updateChatItem(cInfo, cItem, status = cItem.meta.itemStatus) } } @@ -2526,7 +2526,7 @@ object ChatController { updateChatItem(r.reaction.chatInfo, r.reaction.chatReaction.chatItem) } withReportsChatsIfOpen { - if (r.reaction.chatReaction.chatItem.content.msgContent is MsgContent.MCReport) { + if (r.reaction.chatReaction.chatItem.isReport) { updateChatItem(r.reaction.chatInfo, r.reaction.chatReaction.chatItem) } } @@ -2568,7 +2568,7 @@ object ChatController { } } withReportsChatsIfOpen { - if (cItem.content.msgContent is MsgContent.MCReport) { + if (cItem.isReport) { if (toChatItem == null) { removeChatItem(rhId, cInfo, cItem) } else { @@ -2603,12 +2603,17 @@ object ChatController { generalGetString(MR.strings.marked_deleted_description) ) } - val deleted = if (r.member_ != null && (cItem.chatDir as CIDirection.GroupRcv?)?.groupMember != r.member_) { + val wasModerated = r.member_ != null && (cItem.chatDir as CIDirection.GroupRcv?)?.groupMember != r.member_ + val deleted = if (wasModerated && r.member_ != null) { CIDeleted.Moderated(Clock.System.now(), r.member_) } else { CIDeleted.Deleted(Clock.System.now()) } upsertChatItem(rhId, cInfo, cItem.copy(meta = cItem.meta.copy(itemDeleted = deleted))) + val isActiveReport = cItem.isReport && !cItem.isDeletedContent && cItem.meta.itemDeleted == null + if (isActiveReport) { + decreaseGroupReportsCounter(rhId, cInfo.id, wasModerated) + } } } withReportsChatsIfOpen { @@ -3102,7 +3107,7 @@ object ChatController { val cItem = aChatItem.chatItem withChats { upsertChatItem(rh, cInfo, cItem) } withReportsChatsIfOpen { - if (cItem.content.msgContent is MsgContent.MCReport) { + if (cItem.isReport) { upsertChatItem(rh, cInfo, cItem) } } @@ -5953,7 +5958,7 @@ sealed class CR { is ChatRunning -> noDetails() is ChatStopped -> noDetails() is ApiChats -> withUser(user, json.encodeToString(chats)) - is ApiChat -> withUser(user, "chat: ${json.encodeToString(chat)}\nnavInfo: ${navInfo}") + is ApiChat -> withUser(user, "remoteHostId: ${chat.remoteHostId}\nchatInfo: ${chat.chatInfo}\nchatStats: ${chat.chatStats}\nnavInfo: ${navInfo}\nchatItems: ${chat.chatItems}") is ChatTags -> withUser(user, "userTags: ${json.encodeToString(userTags)}") is ApiChatItemInfo -> withUser(user, "chatItem: ${json.encodeToString(chatItem)}\n${json.encodeToString(chatItemInfo)}") is ServerTestResult -> withUser(user, "server: $testServer\nresult: ${json.encodeToString(testFailure)}") 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 05f06f3dce..d27a33ac47 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 @@ -44,11 +44,15 @@ suspend fun apiLoadMessages( when (pagination) { is ChatPagination.Initial -> { val newSplits = if (chat.chatItems.isNotEmpty() && navInfo.afterTotal > 0) listOf(chat.chatItems.last().id) else emptyList() - withChats(contentTag) { - if (getChat(chat.id) == null) { - addChat(chat) - } else { - updateChatInfo(chat.remoteHostId, chat.chatInfo) + if (contentTag == null) { + // update main chats, not content tagged + withChats { + if (getChat(chat.id) == null) { + addChat(chat) + } else { + updateChatInfo(chat.remoteHostId, chat.chatInfo) + updateChatStats(chat.remoteHostId, chat.id, chat.chatStats) + } } } withChats(contentTag) { 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 5553d82338..89f66e0a4e 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 @@ -397,9 +397,14 @@ fun ChatView( } else { removeChatItem(chatRh, chatInfo, deletedChatItem) } + val deletedItem = deleted.deletedChatItem.chatItem + val isActiveReport = deletedItem.isReport == true && !deletedItem.isDeletedContent && deletedItem.meta.itemDeleted == null + if (isActiveReport) { + decreaseGroupReportsCounter(chatRh, chatInfo.id, toChatItem != null) + } } withReportsChatsIfOpen { - if (deletedChatItem.content.msgContent is MsgContent.MCReport) { + if (deletedChatItem.isReport) { if (toChatItem != null) { upsertChatItem(chatRh, chatInfo, toChatItem) } else { @@ -520,7 +525,7 @@ fun ChatView( updateChatItem(cInfo, updatedCI) } withReportsChatsIfOpen { - if (cItem.content.msgContent is MsgContent.MCReport) { + if (cItem.isReport) { updateChatItem(cInfo, updatedCI) } } @@ -2322,17 +2327,22 @@ private fun deleteMessages(chatRh: Long?, chatInfo: ChatInfo, itemIds: List) { } else { openLoadedChat(chat.copy(chatItems = emptyList()), contentTag = contentFilter?.mcTag) } -} \ No newline at end of file +} diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatPreviewView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatPreviewView.kt index d0e9b003e2..bb07a94648 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatPreviewView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatPreviewView.kt @@ -322,6 +322,8 @@ fun ChatPreviewView( } else if (cInfo is ChatInfo.Group) { if (progressByTimeout) { progressView() + } else if (chat.chatStats.reportsCount > 0) { + GroupReportsIcon() } else { IncognitoIcon(chat.chatInfo.incognito) } @@ -469,6 +471,18 @@ fun IncognitoIcon(incognito: Boolean) { } } +@Composable +fun GroupReportsIcon() { + Icon( + painterResource(MR.images.ic_flag), + contentDescription = null, + tint = MaterialTheme.colors.error, + modifier = Modifier + .size(21.sp.toDp()) + .offset(x = 2.sp.toDp()) + ) +} + @Composable private fun groupInvitationPreviewText(currentUserProfileDisplayName: String?, groupInfo: GroupInfo): String { return if (groupInfo.membership.memberIncognito)