diff --git a/js/deletes.js b/js/deletes.js index 471270fbfe..355ba8b3ff 100644 --- a/js/deletes.js +++ b/js/deletes.js @@ -25,14 +25,18 @@ return []; }, - onDelete(del) { + async onDelete(del) { try { - // The contact the delete message came from - const fromContact = ConversationController.get(del.get('fromId')); + // 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') + ); - if (!fromContact) { + if (!targetConversation) { window.log.info( - 'No contact for DOE', + 'No target conversation for DOE', del.get('fromId'), del.get('targetSentTimestamp') ); @@ -41,7 +45,7 @@ } // Do not await, since this can deadlock the queue - fromContact.queueJob(async () => { + targetConversation.queueJob(async () => { window.log.info('Handling DOE for', del.get('targetSentTimestamp')); const messages = await window.Signal.Data.getMessagesBySentAt( @@ -51,16 +55,9 @@ } ); - const targetMessage = messages.find(m => { - const messageContact = m.getContact(); - - if (!messageContact) { - return false; - } - - // Find messages which are from the same contact who sent the DOE - return messageContact.get('id') === fromContact.get('id'); - }); + const targetMessage = messages.find( + m => del.get('fromId') === m.getContactId() + ); if (!targetMessage) { window.log.info( diff --git a/js/reactions.js b/js/reactions.js index 5afb115545..8054574fd2 100644 --- a/js/reactions.js +++ b/js/reactions.js @@ -45,6 +45,8 @@ }, async onReaction(reaction) { try { + // The conversation the target message was in; we have to find it in the database + // to to figure that out. const targetConversation = await ConversationController.getConversationForTargetMessage( ConversationController.ensureContactIds({ e164: reaction.get('targetAuthorE164'), @@ -54,7 +56,7 @@ ); if (!targetConversation) { window.log.info( - 'No contact for reaction', + 'No target conversation for reaction', reaction.get('targetAuthorE164'), reaction.get('targetAuthorUuid'), reaction.get('targetTimestamp') diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index 1a3a104e1b..9df6f5195a 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -610,16 +610,7 @@ export class ConversationController { const messages = await getMessagesBySentAt(targetTimestamp, { MessageCollection: window.Whisper.MessageCollection, }); - const targetMessage = messages.find(m => { - const contact = m.getContact(); - - if (!contact) { - return false; - } - - const mcid = contact.get('id'); - return mcid === targetFromId; - }); + const targetMessage = messages.find(m => m.getContactId() === targetFromId); if (targetMessage) { return targetMessage.getConversation(); diff --git a/ts/background.ts b/ts/background.ts index fb106c3847..31d11d7dce 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -2607,6 +2607,12 @@ type WhatIsThis = typeof window.WhatIsThis; const message = initIncomingMessage(data, messageDescriptor); if (data.message.reaction) { + window.normalizeUuids( + data.message.reaction, + ['targetAuthorUuid'], + 'background::onMessageReceived' + ); + const { reaction } = data.message; window.log.info( 'Queuing incoming reaction for', @@ -2814,6 +2820,12 @@ type WhatIsThis = typeof window.WhatIsThis; const message = createSentMessage(data, messageDescriptor); if (data.message.reaction) { + window.normalizeUuids( + data.message.reaction, + ['targetAuthorUuid'], + 'background::onSentMessage' + ); + const { reaction } = data.message; window.log.info('Queuing sent reaction for', reaction.targetTimestamp); const reactionModel = window.Whisper.Reactions.add({