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 5b05d033c8..6b735ab751 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 @@ -2971,6 +2971,17 @@ class CIQuote ( } } + fun canModerate(chatInfo: ChatInfo, allowSentItems: Boolean): Boolean { + val member = memberToModerate(chatInfo) + if (member != null) return true + + if (allowSentItems && chatInfo is ChatInfo.Group && chatDir is CIDirection.GroupSnd) { + val m = chatInfo.groupInfo.membership + return m.memberRole >= GroupMemberRole.Admin + } + return false + } + companion object { fun getSample(itemId: Long?, sentAt: Instant, text: String, chatDir: CIDirection?): CIQuote = CIQuote(chatDir = chatDir, itemId = itemId, sentAt = sentAt, content = MsgContent.MCText(text)) 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 218e6a6b29..61a3d82e3d 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 @@ -301,13 +301,13 @@ fun ChatView(staleChatId: State, onComposed: suspend (chatId: String) - } }, deleteMessage = { itemId, mode -> - val toDeleteItem = chatModel.chatItems.value.firstOrNull { it.id == itemId } + val toDeleteItem = chatModel.chatItems.value.firstOrNull { it.id == itemId } ?: apiLoadSingleMessage(chatRh, chatInfo.chatType, chatInfo.apiId, itemId) val toModerate = toDeleteItem?.memberToModerate(chatInfo) val groupInfo = toModerate?.first val groupMember = toModerate?.second val deletedChatItem: ChatItem? val toChatItem: ChatItem? - val r = if ((mode == CIDeleteMode.cidmBroadcast || mode == CIDeleteMode.cidmInternalMark) && groupInfo != null && groupMember != null) { + val r = if (mode == CIDeleteMode.cidmBroadcast && groupInfo != null && groupMember != null) { chatModel.controller.apiDeleteMemberChatItems( chatRh, groupId = groupInfo.groupId, diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt index 1a094f613a..7c77893082 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt @@ -314,15 +314,17 @@ fun ChatItemView( ArchiveReportItemAction(cItem, showMenu, deleteMessageAsync) val qItem = cItem.quotedItem if (qItem != null) { - ModerateReportItemAction(rhId, cInfo, cItem, qItem, showMenu, deleteMessage) val rMember = qItem.memberToModerate(cInfo) + if (rMember != null || qItem.canModerate(cInfo, true)) { + ModerateReportItemAction(rhId, cInfo, cItem, qItem, showMenu, deleteMessage) + } if (rMember != null && !rMember.blockedByAdmin && rMember.canBlockForAll(cInfo.groupInfo)) { BlockMemberAction( rhId, chatInfo = cInfo, groupInfo = cInfo.groupInfo, cItem = cItem, - reportedItem = qItem, + reportedQuote = qItem, member = rMember, showMenu = showMenu, deleteMessage = deleteMessage @@ -942,7 +944,7 @@ private fun ModerateReportItemAction( rhId: Long?, chatInfo: ChatInfo, cItem: ChatItem, - reportedItem: CIQuote, + reportedQuote: CIQuote, showMenu: MutableState, deleteMessage: suspend (Long, CIDeleteMode) -> ChatItemDeletion? ) { @@ -951,16 +953,17 @@ private fun ModerateReportItemAction( painterResource(MR.images.ic_flag), onClick = { withBGApi { - val reportedMessageId = getLocalIdForReportedMessage(rhId, chatInfo, reportedItem, cItem.id) + val reportId = cItem.id + val reportedMessageId = reportedQuote.itemId ?: getLocalIdForReportedMessage(rhId, chatInfo, reportId) if (reportedMessageId != null) { moderateMessageAlertDialog( reportedMessageId, questionText = moderateMessageQuestionText(chatInfo.featureEnabled(ChatFeature.FullDelete), 1), - deleteMessage = { id, m -> + deleteMessage = { _, m -> withApi { - val deleted = deleteMessage(id, m) - if (deleted != null) { - deleteMessage(cItem.id, CIDeleteMode.cidmInternalMark) + val moderated = deleteMessage(reportedMessageId, m) + if (moderated != null) { + deleteMessage(reportId, CIDeleteMode.cidmInternalMark) } } }, @@ -979,7 +982,7 @@ private fun BlockMemberAction( chatInfo: ChatInfo, groupInfo: GroupInfo, cItem: ChatItem, - reportedItem: CIQuote, + reportedQuote: CIQuote, member: GroupMember, showMenu: MutableState, deleteMessage: suspend (Long, CIDeleteMode) -> ChatItemDeletion? @@ -994,7 +997,7 @@ private fun BlockMemberAction( SectionItemView({ AlertManager.shared.hideAlert() withBGApi { - val reportedMessageId = getLocalIdForReportedMessage(rhId, chatInfo, reportedItem, cItem.id) + val reportedMessageId = reportedQuote.itemId ?: getLocalIdForReportedMessage(rhId, chatInfo, cItem.id) if (reportedMessageId != null) { blockAndModerateAlertDialog( rhId, @@ -1012,7 +1015,7 @@ private fun BlockMemberAction( SectionItemView({ AlertManager.shared.hideAlert() withBGApi { - val reportedMessageId = getLocalIdForReportedMessage(rhId, chatInfo, reportedItem, cItem.id) + val reportedMessageId = reportedQuote.itemId ?: getLocalIdForReportedMessage(rhId, chatInfo, cItem.id) if (reportedMessageId != null) { blockForAllAlert(rhId, gInfo = groupInfo, mem = member, blockMember = { withBGApi { @@ -1023,7 +1026,8 @@ private fun BlockMemberAction( member = member, blocked = true ) - deleteMessage(reportedMessageId, CIDeleteMode.cidmInternalMark) + val reportId = cItem.id + deleteMessage(reportId, CIDeleteMode.cidmInternalMark) } catch (ex: Exception) { Log.e(TAG, "BlockMemberAction block and moderate ${ex.message}") } @@ -1057,7 +1061,8 @@ private fun ArchiveReportItemAction(cItem: ChatItem, showMenu: MutableState