From 60b6285f1ebee57bf54228d78499a85c6b7ee886 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Mon, 27 Sep 2021 11:52:48 -0700 Subject: [PATCH] Consistent scheduling of sendToGroup Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> --- ts/jobs/normalMessageSendJobQueue.ts | 58 +++++++++++++++------------- ts/models/conversations.ts | 4 +- ts/services/calling.ts | 50 ++++++++++++++---------- 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/ts/jobs/normalMessageSendJobQueue.ts b/ts/jobs/normalMessageSendJobQueue.ts index 48936d13b02..c3e953f26d7 100644 --- a/ts/jobs/normalMessageSendJobQueue.ts +++ b/ts/jobs/normalMessageSendJobQueue.ts @@ -260,33 +260,37 @@ export class NormalMessageSendJobQueue extends JobQueue; if (conversationType === Message.GROUP) { log.info('sending group message'); - innerPromise = window.Signal.Util.sendToGroup({ - groupSendOptions: { - attachments, - deletedForEveryoneTimestamp, - expireTimer, - groupV1: updateRecipients( - conversation.getGroupV1Info(), - recipientIdentifiersWithoutMe - ), - groupV2: updateRecipients( - conversation.getGroupV2Info(), - recipientIdentifiersWithoutMe - ), - messageText: body, - preview, - profileKey, - quote, - sticker, - timestamp: messageTimestamp, - mentions, - }, - conversation, - contentHint: ContentHint.RESENDABLE, - messageId, - sendOptions, - sendType: 'message', - }); + innerPromise = conversation.queueJob( + 'normalMessageSendJobQueue', + () => + window.Signal.Util.sendToGroup({ + groupSendOptions: { + attachments, + deletedForEveryoneTimestamp, + expireTimer, + groupV1: updateRecipients( + conversation.getGroupV1Info(), + recipientIdentifiersWithoutMe + ), + groupV2: updateRecipients( + conversation.getGroupV2Info(), + recipientIdentifiersWithoutMe + ), + messageText: body, + preview, + profileKey, + quote, + sticker, + timestamp: messageTimestamp, + mentions, + }, + conversation, + contentHint: ContentHint.RESENDABLE, + messageId, + sendOptions, + sendType: 'message', + }) + ); } else { log.info('sending direct message'); innerPromise = window.textsecure.messaging.sendMessageToIdentifier({ diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 980fd04b08d..50c1b5e0759 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -1222,7 +1222,7 @@ export class ConversationModel extends window.Backbone online: true, }; if (isDirectConversation(this.attributes)) { - handleMessageSend( + await handleMessageSend( window.textsecure.messaging.sendMessageProtoAndWait({ timestamp, recipients: groupMembers, @@ -1234,7 +1234,7 @@ export class ConversationModel extends window.Backbone { messageIds: [], sendType: 'typing' } ); } else { - handleMessageSend( + await handleMessageSend( window.Signal.Util.sendContentMessageToGroup({ contentHint: ContentHint.IMPLICIT, contentMessage, diff --git a/ts/services/calling.ts b/ts/services/calling.ts index d6918d8ca61..20e6d360511 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -906,14 +906,20 @@ export class CallingClass { logId: `sendToGroup/groupCallUpdate/${conversationId}-${eraId}`, messageIds: [], send: () => - window.Signal.Util.sendToGroup({ - groupSendOptions: { groupCallUpdate: { eraId }, groupV2, timestamp }, - conversation, - contentHint: ContentHint.DEFAULT, - messageId: undefined, - sendOptions, - sendType: 'callingMessage', - }), + conversation.queueJob('sendGroupCallUpdateMessage', () => + window.Signal.Util.sendToGroup({ + groupSendOptions: { + groupCallUpdate: { eraId }, + groupV2, + timestamp, + }, + conversation, + contentHint: ContentHint.DEFAULT, + messageId: undefined, + sendOptions, + sendType: 'callingMessage', + }) + ), sendType: 'callingMessage', timestamp, }).catch(err => { @@ -1567,19 +1573,21 @@ export class CallingClass { // We "fire and forget" because sending this message is non-essential. // We also don't sync this message. const { ContentHint } = Proto.UnidentifiedSenderMessage.Message; - await handleMessageSend( - window.Signal.Util.sendContentMessageToGroup({ - contentHint: ContentHint.DEFAULT, - contentMessage, - conversation, - isPartialSend: false, - messageId: undefined, - recipients: conversation.getRecipients(), - sendOptions: await getSendOptions(conversation.attributes), - sendType: 'callingMessage', - timestamp, - }), - { messageIds: [], sendType: 'callingMessage' } + await conversation.queueJob('handleSendCallMessageToGroup', async () => + handleMessageSend( + window.Signal.Util.sendContentMessageToGroup({ + contentHint: ContentHint.DEFAULT, + contentMessage, + conversation, + isPartialSend: false, + messageId: undefined, + recipients: conversation.getRecipients(), + sendOptions: await getSendOptions(conversation.attributes), + sendType: 'callingMessage', + timestamp, + }), + { messageIds: [], sendType: 'callingMessage' } + ) ); }