feat: when hiding note to self it shouldn't delete the messages

added a keepMessages option to deleteConvoInitialChecks
pull/2789/head
William Grant 2 years ago
parent 2e7a55bad5
commit ebf9db67a3

@ -262,7 +262,8 @@ export function showLeavePrivateConversationbyConvoId(
onClickClose(); onClickClose();
await getConversationController().delete1o1(conversationId, { await getConversationController().delete1o1(conversationId, {
fromSyncMessage: false, fromSyncMessage: false,
justHidePrivate: isMe, justHidePrivate: true,
keepMessages: isMe,
}); });
await clearConversationInteractionState({ conversationId }); await clearConversationInteractionState({ conversationId });
} catch (err) { } catch (err) {

@ -251,17 +251,20 @@ export class ConversationController {
public async delete1o1( public async delete1o1(
id: string, 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()) { if (!conversation || !conversation.isPrivate()) {
return; return;
} }
window.log.debug(`WIP: delete1o1 keepMessages ${id} ${options.keepMessages}`);
if (options.justHidePrivate || isNil(options.justHidePrivate) || conversation.isMe()) { if (options.justHidePrivate || isNil(options.justHidePrivate) || conversation.isMe()) {
window.log.debug(`WIP: delete1o1 justHide ${id}`);
// we just set the hidden field to true // 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. // 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}`); window.log.info(`deleteContact isPrivate, marking as hidden: ${id}`);
conversation.set({ conversation.set({
priority: CONVERSATION_PRIORITIES.hidden, 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) // 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 await conversation.commit(); // this updates the wrappers content to reflect the hidden state
} else { } else {
window.log.debug(`WIP: delete1o1 delete ${id}`);
window.log.info(`deleteContact isPrivate, reset fields and removing from wrapper: ${id}`); window.log.info(`deleteContact isPrivate, reset fields and removing from wrapper: ${id}`);
await conversation.setIsApproved(false, false); await conversation.setIsApproved(false, false);
@ -390,9 +394,13 @@ export class ConversationController {
this.conversations.reset([]); this.conversations.reset([]);
} }
private async deleteConvoInitialChecks(convoId: string, deleteType: ConvoVolatileType) { private async deleteConvoInitialChecks(
convoId: string,
deleteType: ConvoVolatileType,
keepMessages?: boolean
) {
if (!this._initialFetchComplete) { 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}`); window.log.info(`${deleteType} with ${convoId}`);
@ -403,10 +411,15 @@ export class ConversationController {
return null; return null;
} }
// those are the stuff to do for all conversation types // Note in some cases (hiding a conversation) we don't want to delete the messages
window.log.info(`${deleteType} destroyingMessages: ${convoId}`); if (!keepMessages) {
await deleteAllMessagesByConvoIdNoConfirmation(convoId); window.log.debug(`WIP: ${deleteType} destroyingMessages: ${convoId}`);
window.log.info(`${deleteType} messages destroyed: ${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; return conversation;
} }

Loading…
Cancel
Save