Skip to content

Commit

Permalink
Delete conversation external files on deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Oct 2, 2018
1 parent 2cfbfe4 commit f384109
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions js/models/conversations.js
Expand Up @@ -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();

Expand Down
24 changes: 24 additions & 0 deletions js/modules/types/conversation.js
Expand Up @@ -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,
Expand Down

0 comments on commit f384109

Please sign in to comment.