From 16d180efac26b62349b6c7c509cabd2c063715f2 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 31 May 2022 16:20:45 -0700 Subject: [PATCH] Send just sync message if we've already sent to all recipients --- ts/jobs/helpers/sendNormalMessage.ts | 21 +++++++++++++++------ ts/models/messages.ts | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ts/jobs/helpers/sendNormalMessage.ts b/ts/jobs/helpers/sendNormalMessage.ts index ac83ae896b..ef6efa78d6 100644 --- a/ts/jobs/helpers/sendNormalMessage.ts +++ b/ts/jobs/helpers/sendNormalMessage.ts @@ -108,6 +108,7 @@ export async function sendNormalMessage( const { allRecipientIdentifiers, recipientIdentifiersWithoutMe, + sentRecipientIdentifiers, untrustedUuids, } = getMessageRecipients({ log, @@ -151,9 +152,13 @@ export async function sendNormalMessage( let messageSendPromise: Promise; if (recipientIdentifiersWithoutMe.length === 0) { - if (!isMe(conversation.attributes) && !isGroup(conversation.attributes)) { + if ( + !isMe(conversation.attributes) && + !isGroup(conversation.attributes) && + sentRecipientIdentifiers.length === 0 + ) { log.info( - 'No recipients, but we are not sending to ourselves or to group. Failing job.' + 'No recipients; not sending to ourselves or to group, and no successful sends. Failing job.' ); markMessageFailed(message, [new Error('No valid recipients')]); return; @@ -337,20 +342,18 @@ function getMessageRecipients({ }>): { allRecipientIdentifiers: Array; recipientIdentifiersWithoutMe: Array; + sentRecipientIdentifiers: Array; untrustedUuids: Array; } { const allRecipientIdentifiers: Array = []; const recipientIdentifiersWithoutMe: Array = []; const untrustedUuids: Array = []; + const sentRecipientIdentifiers: Array = []; const currentConversationRecipients = conversation.getMemberConversationIds(); Object.entries(message.get('sendStateByConversationId') || {}).forEach( ([recipientConversationId, sendState]) => { - if (isSent(sendState.status)) { - return; - } - const recipient = window.ConversationController.get( recipientConversationId ); @@ -387,6 +390,11 @@ function getMessageRecipients({ return; } + if (isSent(sendState.status)) { + sentRecipientIdentifiers.push(recipientIdentifier); + return; + } + allRecipientIdentifiers.push(recipientIdentifier); if (!isRecipientMe) { recipientIdentifiersWithoutMe.push(recipientIdentifier); @@ -397,6 +405,7 @@ function getMessageRecipients({ return { allRecipientIdentifiers, recipientIdentifiersWithoutMe, + sentRecipientIdentifiers, untrustedUuids, }; } diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 56cd6c9146..5d4c848647 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -1581,6 +1581,7 @@ export class MessageModel extends window.Backbone.Model { this.set({ // This is the same as a normal send() expirationStartTimestamp: Date.now(), + errors: [], }); const result = await this.sendSyncMessage(); this.set({