From 6a05a56e3ec3f4c0a4e305740f0638784a55965d Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Wed, 14 Sep 2022 21:45:59 +0400 Subject: [PATCH] mobile: fix group delete alert text for local deletion (#1051) --- .../app/views/chat/group/GroupChatInfoView.kt | 15 ++++++++++----- .../app/views/chatlist/ChatListNavLinkView.kt | 8 ++++---- .../app/src/main/res/values-ru/strings.xml | 1 + apps/android/app/src/main/res/values/strings.xml | 1 + .../Views/Chat/Group/GroupChatInfoView.swift | 8 ++++++-- .../Shared/Views/ChatList/ChatListNavLink.swift | 10 +++++++--- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupChatInfoView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupChatInfoView.kt index e76ef8db3d..4065478baa 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupChatInfoView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupChatInfoView.kt @@ -72,17 +72,20 @@ fun GroupChatInfoView(chatModel: ChatModel, close: () -> Unit) { editGroupProfile = { ModalManager.shared.showCustomModal { close -> GroupProfileView(groupInfo, chatModel, close) } }, - deleteGroup = { deleteGroupDialog(chat.chatInfo, chatModel, close) }, + deleteGroup = { deleteGroupDialog(chat.chatInfo, groupInfo, chatModel, close) }, clearChat = { clearChatDialog(chat.chatInfo, chatModel, close) }, leaveGroup = { leaveGroupDialog(groupInfo, chatModel, close) }, ) } } -fun deleteGroupDialog(chatInfo: ChatInfo, chatModel: ChatModel, close: (() -> Unit)? = null) { +fun deleteGroupDialog(chatInfo: ChatInfo, groupInfo: GroupInfo, chatModel: ChatModel, close: (() -> Unit)? = null) { + val alertTextKey = + if (groupInfo.membership.memberCurrent) R.string.delete_group_for_all_members_cannot_undo_warning + else R.string.delete_group_for_self_cannot_undo_warning AlertManager.shared.showAlertMsg( title = generalGetString(R.string.delete_group_question), - text = generalGetString(R.string.delete_group_for_all_members_cannot_undo_warning), + text = generalGetString(alertTextKey), confirmText = generalGetString(R.string.delete_verb), onConfirm = { withApi { @@ -264,8 +267,10 @@ fun MemberRow(member: GroupMember, showMemberInfo: ((GroupMember) -> Unit)? = nu ) { ProfileImage(size = 46.dp, member.image) Column { - Text(member.chatViewName, maxLines = 1, overflow = TextOverflow.Ellipsis, - color = if (member.memberIncognito) Indigo else Color.Unspecified) + Text( + member.chatViewName, maxLines = 1, overflow = TextOverflow.Ellipsis, + color = if (member.memberIncognito) Indigo else Color.Unspecified + ) val s = member.memberStatus.shortText val statusDescr = if (user) String.format(generalGetString(R.string.group_info_member_you), s) else s Text( diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListNavLinkView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListNavLinkView.kt index 8754c098eb..480e520fe8 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListNavLinkView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListNavLinkView.kt @@ -130,7 +130,7 @@ fun GroupMenuItems(chat: Chat, groupInfo: GroupInfo, chatModel: ChatModel, showM GroupMemberStatus.MemInvited -> { JoinGroupAction(chat, groupInfo, chatModel, showMenu) if (groupInfo.canDelete) { - DeleteGroupAction(chat, chatModel, showMenu) + DeleteGroupAction(chat, groupInfo, chatModel, showMenu) } } else -> { @@ -143,7 +143,7 @@ fun GroupMenuItems(chat: Chat, groupInfo: GroupInfo, chatModel: ChatModel, showM LeaveGroupAction(groupInfo, chatModel, showMenu) } if (groupInfo.canDelete) { - DeleteGroupAction(chat, chatModel, showMenu) + DeleteGroupAction(chat, groupInfo, chatModel, showMenu) } } } @@ -201,12 +201,12 @@ fun DeleteContactAction(chat: Chat, chatModel: ChatModel, showMenu: MutableState } @Composable -fun DeleteGroupAction(chat: Chat, chatModel: ChatModel, showMenu: MutableState) { +fun DeleteGroupAction(chat: Chat, groupInfo: GroupInfo, chatModel: ChatModel, showMenu: MutableState) { ItemAction( stringResource(R.string.delete_verb), Icons.Outlined.Delete, onClick = { - deleteGroupDialog(chat.chatInfo, chatModel) + deleteGroupDialog(chat.chatInfo, groupInfo, chatModel) showMenu.value = false }, color = Color.Red diff --git a/apps/android/app/src/main/res/values-ru/strings.xml b/apps/android/app/src/main/res/values-ru/strings.xml index daa5ebc3ce..3ddb828a79 100644 --- a/apps/android/app/src/main/res/values-ru/strings.xml +++ b/apps/android/app/src/main/res/values-ru/strings.xml @@ -636,6 +636,7 @@ Удалить группу Удалить группу? Группа будет удалена для всех членов - это действие нельзя отменить! + Группа будет удалена для вас - это действие нельзя отменить! Выйти из группы Редактировать профиль группы diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml index 032eb9fa6f..bf89ae9054 100644 --- a/apps/android/app/src/main/res/values/strings.xml +++ b/apps/android/app/src/main/res/values/strings.xml @@ -637,6 +637,7 @@ Delete group Delete group? Group will be deleted for all members - this cannot be undone! + Group will be deleted for you - this cannot be undone! Leave group Edit group profile diff --git a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift index 6cb92a10ac..bbe54f5961 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift @@ -212,9 +212,9 @@ struct GroupChatInfoView: View { // TODO reuse this and clearChatAlert with ChatInfoView private func deleteGroupAlert() -> Alert { - Alert( + return Alert( title: Text("Delete group?"), - message: Text("Group will be deleted for all members - this cannot be undone!"), + message: deleteGroupAlertMessage(), primaryButton: .destructive(Text("Delete")) { Task { do { @@ -233,6 +233,10 @@ struct GroupChatInfoView: View { ) } + private func deleteGroupAlertMessage() -> Text { + groupInfo.membership.memberCurrent ? Text("Group will be deleted for all members - this cannot be undone!") : Text("Group will be deleted for you - this cannot be undone!") + } + private func clearChatAlert() -> Alert { Alert( title: Text("Clear conversation?"), diff --git a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift index 562abfc746..668d3717f6 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift @@ -148,7 +148,7 @@ struct ChatListNavLink: View { @ViewBuilder private func deleteGroupChatButton(_ groupInfo: GroupInfo) -> some View { Button(role: .destructive) { - AlertManager.shared.showAlert(deleteGroupAlert(.group(groupInfo: groupInfo))) + AlertManager.shared.showAlert(deleteGroupAlert(groupInfo)) } label: { Label("Delete", systemImage: "trash") } @@ -211,10 +211,10 @@ struct ChatListNavLink: View { ) } - private func deleteGroupAlert(_ chatInfo: ChatInfo) -> Alert { + private func deleteGroupAlert(_ groupInfo: GroupInfo) -> Alert { Alert( title: Text("Delete group?"), - message: Text("Group will be deleted for all members - this cannot be undone!"), + message: deleteGroupAlertMessage(groupInfo), primaryButton: .destructive(Text("Delete")) { Task { await deleteChat(chat) } }, @@ -222,6 +222,10 @@ struct ChatListNavLink: View { ) } + private func deleteGroupAlertMessage(_ groupInfo: GroupInfo) -> Text { + groupInfo.membership.memberCurrent ? Text("Group will be deleted for all members - this cannot be undone!") : Text("Group will be deleted for you - this cannot be undone!") + } + private func clearChatAlert() -> Alert { Alert( title: Text("Clear conversation?"),