From 38c6cb0d7d576075ba6af1dc9a96019cb2196f3d Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 13 Jun 2023 17:43:30 +1000 Subject: [PATCH] feat: finished note to self and 1o1 conversation leaving and hiding --- _locales/en/messages.json | 5 +++++ .../conversation-list-item/InteractionItem.tsx | 13 +++++++++++-- ts/components/menu/Menu.tsx | 3 ++- ts/interactions/conversationInteractions.ts | 16 ++++++++++------ ts/types/LocalizerKeys.ts | 5 +++++ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e485a3e75..03cebb64b 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -94,6 +94,7 @@ "continue": "Continue", "error": "Error", "delete": "Delete", + "hide": "Hide", "messageDeletionForbidden": "You don’t have permission to delete others’ messages", "deleteJustForMe": "Delete just for me", "deleteForEveryone": "Delete for everyone", @@ -101,9 +102,13 @@ "deleteMessageQuestion": "Delete this message?", "deleteMessages": "Delete Messages", "deleteMessagesConfirmation": "Permanently delete the messages in this conversation?", + "hideConversation": "Hide Conversation", + "hideNoteToSelfConfirmation": "Are you sure you want to hide your Note to Self conversation?", + "hideConversationFailed": "Failed to hide the Conversation!", "deleteConversation": "Delete Conversation", "deleteConversationConfirmation": "Are you sure you want to delete your conversation with $name$?", "deleteConversationFailed": "Failed to leave the Conversation!", + "hiding": "Hiding...", "leaving": "Leaving...", "deleted": "$count$ deleted", "messageDeletedPlaceholder": "This message has been deleted", diff --git a/ts/components/leftpane/conversation-list-item/InteractionItem.tsx b/ts/components/leftpane/conversation-list-item/InteractionItem.tsx index 68eb848dc..d11d04037 100644 --- a/ts/components/leftpane/conversation-list-item/InteractionItem.tsx +++ b/ts/components/leftpane/conversation-list-item/InteractionItem.tsx @@ -54,14 +54,23 @@ export const InteractionItem = (props: InteractionItemProps) => { } let text = storedLastMessageText || ''; + let failText = ''; switch (interactionType) { + case ConversationInteractionType.Hide: + failText = window.i18n('hideConversationFailed'); + text = + interactionStatus === ConversationInteractionStatus.Error + ? failText + : interactionStatus === ConversationInteractionStatus.Loading + ? window.i18n('hiding') + : text; + break; case ConversationInteractionType.Leave: - const failText = isCommunity + failText = isCommunity ? '' : isGroup ? window.i18n('leaveGroupFailed') : window.i18n('deleteConversationFailed'); - text = interactionStatus === ConversationInteractionStatus.Error ? failText diff --git a/ts/components/menu/Menu.tsx b/ts/components/menu/Menu.tsx index e4acdfe40..24cd8275e 100644 --- a/ts/components/menu/Menu.tsx +++ b/ts/components/menu/Menu.tsx @@ -452,6 +452,7 @@ export const DeletePrivateConversationMenuItem = () => { const username = useConversationUsername(convoId) || convoId; const isRequest = useIsIncomingRequest(convoId); const isPrivate = useIsPrivate(convoId); + const isMe = useIsMe(convoId); if (!convoId || !isPrivate || isRequest) { return null; @@ -463,7 +464,7 @@ export const DeletePrivateConversationMenuItem = () => { showLeavePrivateConversationbyConvoId(convoId, username); }} > - {window.i18n('deleteConversation')} + {isMe ? window.i18n('hideConversation') : window.i18n('deleteConversation')} ); }; diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index b9efae72a..c08151df7 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -51,6 +51,7 @@ export enum ConversationInteractionStatus { } export enum ConversationInteractionType { + Hide = 'hide', Leave = 'leave', } @@ -243,6 +244,7 @@ export async function showUpdateGroupMembersByConvoId(conversationId: string) { export function showLeavePrivateConversationbyConvoId(conversationId: string, name: string) { const conversation = getConversationController().get(conversationId); + const isMe = conversation.isMe(); if (!conversation.isPrivate()) { throw new Error('showLeavePrivateConversationDialog() called with a non private convo.'); @@ -256,12 +258,12 @@ export function showLeavePrivateConversationbyConvoId(conversationId: string, na try { await updateConversationInteractionState({ conversationId, - type: ConversationInteractionType.Leave, + type: isMe ? ConversationInteractionType.Hide : ConversationInteractionType.Leave, status: ConversationInteractionStatus.Start, }); await getConversationController().delete1o1(conversationId, { fromSyncMessage: false, - justHidePrivate: true, + justHidePrivate: isMe, }); onClickClose(); @@ -271,7 +273,7 @@ export function showLeavePrivateConversationbyConvoId(conversationId: string, na window.log.warn(`showLeavePrivateConversationbyConvoId error: ${err}`); await updateConversationInteractionState({ conversationId, - type: ConversationInteractionType.Leave, + type: isMe ? ConversationInteractionType.Hide : ConversationInteractionType.Leave, status: ConversationInteractionStatus.Error, }); } @@ -279,10 +281,12 @@ export function showLeavePrivateConversationbyConvoId(conversationId: string, na window?.inboxStore?.dispatch( updateConfirmModal({ - title: window.i18n('deleteConversation'), - message: window.i18n('deleteConversationConfirmation', [name]), + title: isMe ? window.i18n('hideConversation') : window.i18n('deleteConversation'), + message: isMe + ? window.i18n('hideNoteToSelfConfirmation') + : window.i18n('deleteConversationConfirmation', [name]), onClickOk, - okText: window.i18n('delete'), + okText: isMe ? window.i18n('hide') : window.i18n('delete'), okTheme: SessionButtonColor.Danger, onClickClose, conversationId, diff --git a/ts/types/LocalizerKeys.ts b/ts/types/LocalizerKeys.ts index 7d303ae08..4aa5d70ce 100644 --- a/ts/types/LocalizerKeys.ts +++ b/ts/types/LocalizerKeys.ts @@ -94,6 +94,7 @@ export type LocalizerKeys = | 'continue' | 'error' | 'delete' + | 'hide' | 'messageDeletionForbidden' | 'deleteJustForMe' | 'deleteForEveryone' @@ -101,9 +102,13 @@ export type LocalizerKeys = | 'deleteMessageQuestion' | 'deleteMessages' | 'deleteMessagesConfirmation' + | 'hideConversation' + | 'hideNoteToSelfConfirmation' + | 'hideConversationFailed' | 'deleteConversation' | 'deleteConversationConfirmation' | 'deleteConversationFailed' + | 'hiding' | 'leaving' | 'deleted' | 'messageDeletedPlaceholder'