From e8759fc81b40302dec65b828c97eaf5848ef4efb Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Sun, 1 Nov 2020 07:06:41 -0800 Subject: [PATCH] Fix out-of-order applications of reaction and delete-for-everyone --- js/deletes.js | 2 +- js/reactions.js | 10 +++++----- ts/models/messages.ts | 14 ++++++++------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/js/deletes.js b/js/deletes.js index da2a1aa5ebb0..471270fbfe5d 100644 --- a/js/deletes.js +++ b/js/deletes.js @@ -14,7 +14,7 @@ forMessage(message) { const matchingDeletes = this.filter({ targetSentTimestamp: message.get('sent_at'), - fromId: message.getContact().get('id'), + fromId: message.getContactId(), }); if (matchingDeletes.length > 0) { diff --git a/js/reactions.js b/js/reactions.js index 33a758f2f38f..5afb115545a2 100644 --- a/js/reactions.js +++ b/js/reactions.js @@ -24,15 +24,15 @@ } } + const senderId = message.getContactId(); + const sentAt = message.get('sent_at'); const reactionsBySource = this.filter(re => { - const mcid = message.get('conversationId'); - const recid = ConversationController.ensureContactIds({ + const targetSenderId = ConversationController.ensureContactIds({ e164: re.get('targetAuthorE164'), uuid: re.get('targetAuthorUuid'), }); - const mTime = message.get('sent_at'); - const rTime = re.get('targetTimestamp'); - return mcid === recid && mTime === rTime; + const targetTimestamp = re.get('targetTimestamp'); + return targetSenderId === senderId && targetTimestamp === sentAt; }); if (reactionsBySource.length > 0) { diff --git a/ts/models/messages.ts b/ts/models/messages.ts index af817be0e867..a9b402b11580 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -3344,16 +3344,18 @@ export class MessageModel extends window.Backbone.Model { // Does this message have any pending, previously-received associated reactions? const reactions = window.Whisper.Reactions.forMessage(message); - reactions.forEach(reaction => { - message.handleReaction(reaction, false); - }); + await Promise.all( + reactions.map(reaction => message.handleReaction(reaction, false)) + ); // Does this message have any pending, previously-received associated // delete for everyone messages? const deletes = window.Whisper.Deletes.forMessage(message); - deletes.forEach(del => { - window.Signal.Util.deleteForEveryone(message, del, false); - }); + await Promise.all( + deletes.map(del => + window.Signal.Util.deleteForEveryone(message, del, false) + ) + ); await window.Signal.Data.saveMessage(message.attributes, { Message: window.Whisper.Message,