ios: UI to moderate messages of other members (#1980)

* ios: UI to moderate messages of other members

* split moderate action

* do not show moderate button on moderated, show alert
This commit is contained in:
Evgeny Poberezkin
2023-03-06 21:57:58 +00:00
committed by GitHub
parent 8f0e7512be
commit f1a9814faa
6 changed files with 86 additions and 14 deletions

View File

@@ -492,8 +492,13 @@ struct ChatView: View {
if !live || !ci.meta.isLive {
menu.append(deleteUIAction())
}
if let (groupInfo, _) = ci.memberToModerate(chat.chatInfo) {
menu.append(moderateUIAction(groupInfo))
}
} else if ci.meta.itemDeleted != nil {
menu.append(revealUIAction())
if !ci.isDeletedContent {
menu.append(revealUIAction())
}
menu.append(deleteUIAction())
} else if ci.isDeletedContent {
menu.append(deleteUIAction())
@@ -595,7 +600,29 @@ struct ChatView: View {
deletingItem = ci
}
}
private func moderateUIAction(_ groupInfo: GroupInfo) -> UIAction {
UIAction(
title: NSLocalizedString("Moderate", comment: "chat item action"),
image: UIImage(systemName: "flag"),
attributes: [.destructive]
) { _ in
AlertManager.shared.showAlert(Alert(
title: Text("Delete member message?"),
message: Text(
groupInfo.fullGroupPreferences.fullDelete.on
? "The message will be deleted for all members."
: "The message will be marked as moderated for all members."
),
primaryButton: .destructive(Text("Delete")) {
deletingItem = ci
deleteMessage(.cidmBroadcast)
},
secondaryButton: .cancel()
))
}
}
private func revealUIAction() -> UIAction {
UIAction(
title: NSLocalizedString("Reveal", comment: "chat item action"),
@@ -638,12 +665,22 @@ struct ChatView: View {
logger.debug("ChatView deleteMessage: in Task")
do {
if let di = deletingItem {
let (deletedItem, toItem) = try await apiDeleteChatItem(
type: chat.chatInfo.chatType,
id: chat.chatInfo.apiId,
itemId: di.id,
mode: mode
)
var deletedItem: ChatItem
var toItem: ChatItem?
if let (groupInfo, groupMember) = di.memberToModerate(chat.chatInfo) {
(deletedItem, toItem) = try await apiDeleteMemberChatItem(
groupId: groupInfo.apiId,
groupMemberId: groupMember.groupMemberId,
itemId: di.id
)
} else {
(deletedItem, toItem) = try await apiDeleteChatItem(
type: chat.chatInfo.chatType,
id: chat.chatInfo.apiId,
itemId: di.id,
mode: mode
)
}
DispatchQueue.main.async {
deletingItem = nil
if let toItem = toItem {