Delete attachment files on disk upon message delete
This commit is contained in:
parent
279b3f81c7
commit
9d25aa4e43
2 changed files with 18 additions and 2 deletions
|
@ -1,8 +1,11 @@
|
|||
/* eslint-disable */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
||||
const { Message: TypedMessage } = window.Signal.Types;
|
||||
const { Attachment, Message: TypedMessage } = window.Signal.Types;
|
||||
const { context: migrationContext } = window.Signal.Migrations;
|
||||
|
||||
var Message = window.Whisper.Message = Backbone.Model.extend({
|
||||
database : Whisper.Database,
|
||||
|
@ -13,7 +16,7 @@
|
|||
}
|
||||
|
||||
this.on('change:attachments', this.updateImageUrl);
|
||||
this.on('destroy', this.revokeImageUrl);
|
||||
this.on('destroy', this.onDestroy);
|
||||
this.on('change:expirationStartTimestamp', this.setToExpire);
|
||||
this.on('change:expireTimer', this.setToExpire);
|
||||
this.on('unload', this.revokeImageUrl);
|
||||
|
@ -139,6 +142,17 @@
|
|||
|
||||
return '';
|
||||
},
|
||||
/* eslint-enable */
|
||||
/* jshint ignore:start */
|
||||
async onDestroy() {
|
||||
this.revokeImageUrl();
|
||||
const attachments = this.get('attachments');
|
||||
const deleteData =
|
||||
Attachment.deleteData(migrationContext.deleteAttachmentData);
|
||||
await Promise.all(attachments.map(deleteData));
|
||||
},
|
||||
/* jshint ignore:end */
|
||||
/* eslint-disable */
|
||||
updateImageUrl: function() {
|
||||
this.revokeImageUrl();
|
||||
var attachment = this.get('attachments')[0];
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
|
||||
// ES2015+ modules
|
||||
const attachmentsPath = Attachments.getPath(app.getPath('userData'));
|
||||
const deleteAttachmentData = Attachments.deleteData(attachmentsPath);
|
||||
const readAttachmentData = Attachments.readData(attachmentsPath);
|
||||
const writeAttachmentData = Attachments.writeData(attachmentsPath);
|
||||
|
||||
|
@ -121,6 +122,7 @@
|
|||
window.Signal.Migrations = window.Signal.Migrations || {};
|
||||
// Injected context functions to keep `Message` agnostic from Electron:
|
||||
window.Signal.Migrations.context = {
|
||||
deleteAttachmentData,
|
||||
readAttachmentData,
|
||||
writeAttachmentData,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue