Delete right away if we already have the message

This commit is contained in:
Josh Perez 2020-07-27 14:15:32 -04:00 committed by Scott Nonnenberg
parent dfa846e4f3
commit 1ad2b175dc
10 changed files with 194 additions and 27 deletions

View file

@ -2288,6 +2288,7 @@
if (data.message.reaction) {
const { reaction } = data.message;
window.log.info('Queuing reaction for', reaction.targetTimestamp);
const reactionModel = Whisper.Reactions.add({
emoji: reaction.emoji,
remove: reaction.remove,
@ -2305,6 +2306,7 @@
if (data.message.delete) {
const { delete: del } = data.message;
window.log.info('Queuing DOE for', del.targetSentTimestamp);
const deleteModel = Whisper.Deletes.add({
targetSentTimestamp: del.targetSentTimestamp,
serverTimestamp: data.serverTimestamp,

View file

@ -11,8 +11,6 @@
(function() {
'use strict';
const ONE_DAY = 24 * 60 * 60 * 1000;
window.Whisper = window.Whisper || {};
Whisper.Deletes = new (Backbone.Collection.extend({
forMessage(message) {
@ -46,6 +44,8 @@
// Do not await, since this can deadlock the queue
fromContact.queueJob(async () => {
window.log.info('Handling DOE for', del.get('targetSentTimestamp'));
const messages = await window.Signal.Data.getMessagesBySentAt(
del.get('targetSentTimestamp'),
{
@ -74,29 +74,12 @@
return;
}
// Make sure the server timestamps for the DOE and the matching message
// are less than one day apart
const delta = Math.abs(
del.get('serverTimestamp') - targetMessage.get('serverTimestamp')
);
if (delta > ONE_DAY) {
window.log.info('Received late DOE. Dropping.', {
fromId: del.get('fromId'),
targetSentTimestamp: del.get('targetSentTimestamp'),
messageServerTimestamp: message.get('serverTimestamp'),
deleteServerTimestamp: del.get('serverTimestamp'),
});
this.remove(del);
return;
}
const message = MessageController.register(
targetMessage.id,
targetMessage
);
await message.handleDeleteForEveryone(del);
await window.Signal.Util.deleteForEveryone(message, del);
this.remove(del);
});

View file

@ -1111,7 +1111,7 @@
isErased() {
return Boolean(this.get('isErased'));
},
async eraseContents(additionalProperties = {}) {
async eraseContents(additionalProperties = {}, shouldPersist = true) {
if (this.get('isErased')) {
return;
}
@ -1139,9 +1139,11 @@
});
this.trigger('content-changed');
await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
});
if (shouldPersist) {
await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
});
}
},
unload() {
if (this.quotedMessage) {
@ -2583,7 +2585,9 @@
// Does this message have any pending, previously-received associated
// delete for everyone messages?
const deletes = Whisper.Deletes.forMessage(message);
deletes.forEach(del => Whisper.Deletes.onDelete(del, false));
deletes.forEach(del => {
window.Signal.Util.deleteForEveryone(message, del, false);
});
await window.Signal.Data.saveMessage(message.attributes, {
Message: Whisper.Message,
@ -2658,7 +2662,7 @@
}
},
async handleDeleteForEveryone(del) {
async handleDeleteForEveryone(del, shouldPersist = true) {
window.log.info('Handling DOE.', {
fromId: del.get('fromId'),
targetSentTimestamp: del.get('targetSentTimestamp'),
@ -2673,7 +2677,10 @@
Whisper.Notifications.remove(notificationForMessage);
// Erase the contents of this message
await this.eraseContents({ deletedForEveryone: true, reactions: [] });
await this.eraseContents(
{ deletedForEveryone: true, reactions: [] },
shouldPersist
);
// Update the conversation's last message in case this was the last message
this.getConversation().updateLastMessage();

View file

@ -53,11 +53,22 @@
reaction.get('targetTimestamp')
);
if (!targetConversation) {
window.log.info(
'No contact for reaction',
reaction.get('targetAuthorE164'),
reaction.get('targetAuthorUuid'),
reaction.get('targetTimestamp')
);
return;
}
// awaiting is safe since `onReaction` is never called from inside the queue
await targetConversation.queueJob(async () => {
window.log.info(
'Handling reaction for',
reaction.get('targetTimestamp')
);
const messages = await window.Signal.Data.getMessagesBySentAt(
reaction.get('targetTimestamp'),
{