From 40e3a8fa7260f5d0152387bd556e94307bcd84a4 Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 13 Jun 2023 17:54:28 +1000 Subject: [PATCH] feat: finished group and community leaving modals --- ts/components/menu/ConversationHeaderMenu.tsx | 6 +-- .../menu/ConversationListItemContextMenu.tsx | 6 +-- ts/components/menu/Menu.tsx | 54 ++----------------- 3 files changed, 8 insertions(+), 58 deletions(-) diff --git a/ts/components/menu/ConversationHeaderMenu.tsx b/ts/components/menu/ConversationHeaderMenu.tsx index bbc3f409c..9ec3ed2b8 100644 --- a/ts/components/menu/ConversationHeaderMenu.tsx +++ b/ts/components/menu/ConversationHeaderMenu.tsx @@ -30,10 +30,9 @@ import { ChangeNicknameMenuItem, ClearNicknameMenuItem, DeletePrivateContactMenuItem, - DeleteGroupOrCommunityMenuItem, DeleteMessagesMenuItem, InviteContactMenuItem, - LeaveGroupMenuItem, + LeaveGroupOrCommunityMenuItem, MarkAllReadMenuItem, RemoveModeratorsMenuItem, ShowUserDetailsMenuItem, @@ -85,12 +84,11 @@ export const ConversationHeaderMenu = (props: PropsConversationHeaderMenu) => { - + - diff --git a/ts/components/menu/ConversationListItemContextMenu.tsx b/ts/components/menu/ConversationListItemContextMenu.tsx index 8b407032c..bf7aa791b 100644 --- a/ts/components/menu/ConversationListItemContextMenu.tsx +++ b/ts/components/menu/ConversationListItemContextMenu.tsx @@ -18,10 +18,9 @@ import { DeclineAndBlockMsgRequestMenuItem, DeclineMsgRequestMenuItem, DeletePrivateContactMenuItem, - DeleteGroupOrCommunityMenuItem, DeleteMessagesMenuItem, InviteContactMenuItem, - LeaveGroupMenuItem, + LeaveGroupOrCommunityMenuItem, MarkAllReadMenuItem, MarkConversationUnreadMenuItem, ShowUserDetailsMenuItem, @@ -66,8 +65,7 @@ const ConversationListItemContextMenu = (props: PropsContextConversationItem) => - - + diff --git a/ts/components/menu/Menu.tsx b/ts/components/menu/Menu.tsx index 24cd8275e..3c0fae9bd 100644 --- a/ts/components/menu/Menu.tsx +++ b/ts/components/menu/Menu.tsx @@ -127,68 +127,22 @@ export const DeletePrivateContactMenuItem = () => { return null; }; -export const DeleteGroupOrCommunityMenuItem = () => { - const dispatch = useDispatch(); - const convoId = useConvoIdFromContext(); - const isPublic = useIsPublic(convoId); - const isLeft = useIsLeft(convoId); - const isKickedFromGroup = useIsKickedFromGroup(convoId); - const isPrivate = useIsPrivate(convoId); - const isGroup = !isPrivate && !isPublic; - - // You need to have left a closed group first to be able to delete it completely as there is a leaving message to send first. - // A community can just be removed right away. - if (isPublic || (isGroup && (isLeft || isKickedFromGroup))) { - const menuItemText = isPublic ? window.i18n('leaveGroup') : window.i18n('editMenuDeleteGroup'); - - const onClickClose = () => { - dispatch(updateConfirmModal(null)); - }; - - const showConfirmationModal = () => { - dispatch( - updateConfirmModal({ - title: menuItemText, - message: window.i18n('leaveGroupConfirmation'), - onClickClose, - okTheme: SessionButtonColor.Danger, - onClickOk: async () => { - if (isPublic) { - await getConversationController().deleteCommunity(convoId, { - fromSyncMessage: false, - }); - } else { - await getConversationController().deleteClosedGroup(convoId, { - fromSyncMessage: false, - sendLeaveMessage: true, - }); - } - }, - }) - ); - }; - - return {menuItemText}; - } - return null; -}; - -export const LeaveGroupMenuItem = () => { +export const LeaveGroupOrCommunityMenuItem = () => { const convoId = useConvoIdFromContext(); const username = useConversationUsername(convoId) || convoId; - const isPublic = useIsPublic(convoId); const isLeft = useIsLeft(convoId); const isKickedFromGroup = useIsKickedFromGroup(convoId); const isPrivate = useIsPrivate(convoId); + const isPublic = useIsPublic(convoId); - if (!isKickedFromGroup && !isLeft && !isPrivate && !isPublic) { + if (!isKickedFromGroup && !isLeft && !isPrivate) { return ( { showLeaveGroupByConvoId(convoId, username); }} > - {window.i18n('leaveGroup')} + {isPublic ? window.i18n('leaveCommunity') : window.i18n('leaveGroup')} ); }