From f38410976d5bcc1ebfc4688fd2a4bc563b744ee3 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 1 Oct 2018 15:54:14 -0700 Subject: [PATCH] Delete conversation external files on deletion --- js/models/conversations.js | 9 +++++++++ js/modules/types/conversation.js | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/js/models/conversations.js b/js/models/conversations.js index 9942399341f..a7652b81032 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -123,6 +123,15 @@ return this.id === this.ourNumber; }, + async cleanup() { + await window.Signal.Types.Conversation.deleteExternalFiles( + this.attributes, + { + deleteAttachmentData, + } + ); + }, + async updateAndMerge(message) { this.updateLastMessage(); diff --git a/js/modules/types/conversation.js b/js/modules/types/conversation.js index c4ada566939..1d2aad7cd26 100644 --- a/js/modules/types/conversation.js +++ b/js/modules/types/conversation.js @@ -123,7 +123,31 @@ async function migrateConversation(conversation, options = {}) { return upgradeToVersion2(conversation, options); } +async function deleteExternalFiles(conversation, options = {}) { + if (!conversation) { + return; + } + + const { deleteAttachmentData } = options; + if (!isFunction(deleteAttachmentData)) { + throw new Error( + 'Conversation.buildAvatarUpdater: deleteAttachmentData must be a function' + ); + } + + const { avatar, profileAvatar } = conversation; + + if (avatar && avatar.path) { + await deleteAttachmentData(avatar.path); + } + + if (profileAvatar && profileAvatar.path) { + await deleteAttachmentData(profileAvatar.path); + } +} + module.exports = { + deleteExternalFiles, migrateConversation, maybeUpdateAvatar, maybeUpdateProfileAvatar,