From ebf9db67a3aa1f727f3c3a432be3b396924d215c Mon Sep 17 00:00:00 2001 From: William Grant Date: Fri, 16 Jun 2023 11:56:08 +1000 Subject: [PATCH] feat: when hiding note to self it shouldn't delete the messages added a keepMessages option to deleteConvoInitialChecks --- ts/interactions/conversationInteractions.ts | 3 +- .../conversations/ConversationController.ts | 31 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index aaf34a1f0..e4e65e224 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -262,7 +262,8 @@ export function showLeavePrivateConversationbyConvoId( onClickClose(); await getConversationController().delete1o1(conversationId, { fromSyncMessage: false, - justHidePrivate: isMe, + justHidePrivate: true, + keepMessages: isMe, }); await clearConversationInteractionState({ conversationId }); } catch (err) { diff --git a/ts/session/conversations/ConversationController.ts b/ts/session/conversations/ConversationController.ts index 0dddc0e1a..2f93256b8 100644 --- a/ts/session/conversations/ConversationController.ts +++ b/ts/session/conversations/ConversationController.ts @@ -251,17 +251,20 @@ export class ConversationController { public async delete1o1( id: string, - options: { fromSyncMessage: boolean; justHidePrivate?: boolean } + options: { fromSyncMessage: boolean; justHidePrivate?: boolean; keepMessages?: boolean } ) { - const conversation = await this.deleteConvoInitialChecks(id, '1o1'); + const conversation = await this.deleteConvoInitialChecks(id, '1o1', options?.keepMessages); + if (!conversation || !conversation.isPrivate()) { return; } + window.log.debug(`WIP: delete1o1 keepMessages ${id} ${options.keepMessages}`); + if (options.justHidePrivate || isNil(options.justHidePrivate) || conversation.isMe()) { + window.log.debug(`WIP: delete1o1 justHide ${id}`); // we just set the hidden field to true // so the conversation still exists (needed for that user's profile in groups) but is not shown on the list of conversation. - // We also keep the messages for now, as turning a contact as hidden might just be a temporary thing window.log.info(`deleteContact isPrivate, marking as hidden: ${id}`); conversation.set({ priority: CONVERSATION_PRIORITIES.hidden, @@ -269,6 +272,7 @@ export class ConversationController { // We don't remove entries from the contacts wrapper, so better keep corresponding convo volatile info for now (it will be pruned if needed) await conversation.commit(); // this updates the wrappers content to reflect the hidden state } else { + window.log.debug(`WIP: delete1o1 delete ${id}`); window.log.info(`deleteContact isPrivate, reset fields and removing from wrapper: ${id}`); await conversation.setIsApproved(false, false); @@ -390,9 +394,13 @@ export class ConversationController { this.conversations.reset([]); } - private async deleteConvoInitialChecks(convoId: string, deleteType: ConvoVolatileType) { + private async deleteConvoInitialChecks( + convoId: string, + deleteType: ConvoVolatileType, + keepMessages?: boolean + ) { if (!this._initialFetchComplete) { - throw new Error(`getConversationController.${deleteType} needs complete initial fetch`); + throw new Error(`getConversationController.${deleteType} needs complete initial fetch`); } window.log.info(`${deleteType} with ${convoId}`); @@ -403,10 +411,15 @@ export class ConversationController { return null; } - // those are the stuff to do for all conversation types - window.log.info(`${deleteType} destroyingMessages: ${convoId}`); - await deleteAllMessagesByConvoIdNoConfirmation(convoId); - window.log.info(`${deleteType} messages destroyed: ${convoId}`); + // Note in some cases (hiding a conversation) we don't want to delete the messages + if (!keepMessages) { + window.log.debug(`WIP: ${deleteType} destroyingMessages: ${convoId}`); + // those are the stuff to do for all conversation types + window.log.info(`${deleteType} destroyingMessages: ${convoId}`); + await deleteAllMessagesByConvoIdNoConfirmation(convoId); + window.log.info(`${deleteType} messages destroyed: ${convoId}`); + } + return conversation; }