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 () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
window.Whisper = window.Whisper || {};
|
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({
|
var Message = window.Whisper.Message = Backbone.Model.extend({
|
||||||
database : Whisper.Database,
|
database : Whisper.Database,
|
||||||
|
@ -13,7 +16,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on('change:attachments', this.updateImageUrl);
|
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:expirationStartTimestamp', this.setToExpire);
|
||||||
this.on('change:expireTimer', this.setToExpire);
|
this.on('change:expireTimer', this.setToExpire);
|
||||||
this.on('unload', this.revokeImageUrl);
|
this.on('unload', this.revokeImageUrl);
|
||||||
|
@ -139,6 +142,17 @@
|
||||||
|
|
||||||
return '';
|
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() {
|
updateImageUrl: function() {
|
||||||
this.revokeImageUrl();
|
this.revokeImageUrl();
|
||||||
var attachment = this.get('attachments')[0];
|
var attachment = this.get('attachments')[0];
|
||||||
|
|
|
@ -109,6 +109,7 @@
|
||||||
|
|
||||||
// ES2015+ modules
|
// ES2015+ modules
|
||||||
const attachmentsPath = Attachments.getPath(app.getPath('userData'));
|
const attachmentsPath = Attachments.getPath(app.getPath('userData'));
|
||||||
|
const deleteAttachmentData = Attachments.deleteData(attachmentsPath);
|
||||||
const readAttachmentData = Attachments.readData(attachmentsPath);
|
const readAttachmentData = Attachments.readData(attachmentsPath);
|
||||||
const writeAttachmentData = Attachments.writeData(attachmentsPath);
|
const writeAttachmentData = Attachments.writeData(attachmentsPath);
|
||||||
|
|
||||||
|
@ -121,6 +122,7 @@
|
||||||
window.Signal.Migrations = window.Signal.Migrations || {};
|
window.Signal.Migrations = window.Signal.Migrations || {};
|
||||||
// Injected context functions to keep `Message` agnostic from Electron:
|
// Injected context functions to keep `Message` agnostic from Electron:
|
||||||
window.Signal.Migrations.context = {
|
window.Signal.Migrations.context = {
|
||||||
|
deleteAttachmentData,
|
||||||
readAttachmentData,
|
readAttachmentData,
|
||||||
writeAttachmentData,
|
writeAttachmentData,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue