2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-04-29 21:24:12 +00:00
|
|
|
/* global
|
|
|
|
Backbone,
|
|
|
|
Whisper,
|
|
|
|
MessageController,
|
|
|
|
ConversationController
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* eslint-disable more/no-then */
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2020-11-18 15:15:42 +00:00
|
|
|
(function () {
|
2020-04-29 21:24:12 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
Whisper.Deletes = new (Backbone.Collection.extend({
|
|
|
|
forMessage(message) {
|
|
|
|
const matchingDeletes = this.filter({
|
|
|
|
targetSentTimestamp: message.get('sent_at'),
|
2020-11-01 15:06:41 +00:00
|
|
|
fromId: message.getContactId(),
|
2020-04-29 21:24:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (matchingDeletes.length > 0) {
|
|
|
|
window.log.info('Found early DOE for message');
|
|
|
|
this.remove(matchingDeletes);
|
|
|
|
return matchingDeletes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
},
|
2020-11-02 22:49:07 +00:00
|
|
|
async onDelete(del) {
|
2020-04-29 21:24:12 +00:00
|
|
|
try {
|
2020-11-02 22:49:07 +00:00
|
|
|
// The conversation the deleted message was in; we have to find it in the database
|
|
|
|
// to to figure that out.
|
|
|
|
const targetConversation = await ConversationController.getConversationForTargetMessage(
|
|
|
|
del.get('fromId'),
|
|
|
|
del.get('targetSentTimestamp')
|
|
|
|
);
|
2020-04-29 21:24:12 +00:00
|
|
|
|
2020-11-02 22:49:07 +00:00
|
|
|
if (!targetConversation) {
|
2020-04-29 21:24:12 +00:00
|
|
|
window.log.info(
|
2020-11-02 22:49:07 +00:00
|
|
|
'No target conversation for DOE',
|
2020-04-29 21:24:12 +00:00
|
|
|
del.get('fromId'),
|
|
|
|
del.get('targetSentTimestamp')
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:24:58 +00:00
|
|
|
// Do not await, since this can deadlock the queue
|
2020-11-02 22:49:07 +00:00
|
|
|
targetConversation.queueJob(async () => {
|
2020-07-27 18:15:32 +00:00
|
|
|
window.log.info('Handling DOE for', del.get('targetSentTimestamp'));
|
|
|
|
|
2020-07-10 18:24:58 +00:00
|
|
|
const messages = await window.Signal.Data.getMessagesBySentAt(
|
|
|
|
del.get('targetSentTimestamp'),
|
|
|
|
{
|
|
|
|
MessageCollection: Whisper.MessageCollection,
|
|
|
|
}
|
|
|
|
);
|
2020-04-29 21:24:12 +00:00
|
|
|
|
2020-11-02 22:49:07 +00:00
|
|
|
const targetMessage = messages.find(
|
|
|
|
m => del.get('fromId') === m.getContactId()
|
|
|
|
);
|
2020-04-29 21:24:12 +00:00
|
|
|
|
2020-07-10 18:24:58 +00:00
|
|
|
if (!targetMessage) {
|
|
|
|
window.log.info(
|
|
|
|
'No message for DOE',
|
|
|
|
del.get('fromId'),
|
|
|
|
del.get('targetSentTimestamp')
|
|
|
|
);
|
2020-04-29 21:24:12 +00:00
|
|
|
|
2020-07-10 18:24:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-29 21:24:12 +00:00
|
|
|
|
2020-07-10 18:24:58 +00:00
|
|
|
const message = MessageController.register(
|
|
|
|
targetMessage.id,
|
|
|
|
targetMessage
|
|
|
|
);
|
2020-04-29 21:24:12 +00:00
|
|
|
|
2020-07-27 18:15:32 +00:00
|
|
|
await window.Signal.Util.deleteForEveryone(message, del);
|
2020-04-29 21:24:12 +00:00
|
|
|
|
2020-07-10 18:24:58 +00:00
|
|
|
this.remove(del);
|
|
|
|
});
|
2020-04-29 21:24:12 +00:00
|
|
|
} catch (error) {
|
|
|
|
window.log.error(
|
|
|
|
'Deletes.onDelete error:',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}))();
|
|
|
|
})();
|