From 4be2a33be5193102ca81434ca3ab9640510bccfb Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 4 Mar 2022 17:39:37 -0800 Subject: [PATCH] Populate dataMessage on CallbackResultType when sending 1:1 messages --- ts/textsecure/OutgoingMessage.ts | 9 +++++++++ ts/textsecure/SendMessage.ts | 11 ++++------- ts/util/wrapWithSyncMessageSend.ts | 6 +++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ts/textsecure/OutgoingMessage.ts b/ts/textsecure/OutgoingMessage.ts index 5a50136e05..38c0ef1a99 100644 --- a/ts/textsecure/OutgoingMessage.ts +++ b/ts/textsecure/OutgoingMessage.ts @@ -189,8 +189,16 @@ export default class OutgoingMessage { numberCompleted(): void { this.identifiersCompleted += 1; if (this.identifiersCompleted >= this.identifiers.length) { + const proto = this.message; const contentProto = this.getContentProtoBytes(); const { timestamp, contentHint, recipients } = this; + let dataMessage: Uint8Array | undefined; + + if (proto instanceof Proto.Content && proto.dataMessage) { + dataMessage = Proto.DataMessage.encode(proto.dataMessage).finish(); + } else if (proto instanceof Proto.DataMessage) { + dataMessage = Proto.DataMessage.encode(proto).finish(); + } this.callback({ successfulIdentifiers: this.successfulIdentifiers, @@ -199,6 +207,7 @@ export default class OutgoingMessage { unidentifiedDeliveries: this.unidentifiedDeliveries, contentHint, + dataMessage, recipients, contentProto, timestamp, diff --git a/ts/textsecure/SendMessage.ts b/ts/textsecure/SendMessage.ts index 02a0a3f7fa..6a8c23e1f7 100644 --- a/ts/textsecure/SendMessage.ts +++ b/ts/textsecure/SendMessage.ts @@ -889,7 +889,6 @@ export default class MessageSender { new Promise((resolve, reject) => { this.sendMessageProto({ callback: (res: CallbackResultType) => { - res.dataMessage = message.encode(); if (res.errors && res.errors.length > 0) { reject(new SendMessageProtoError(res)); } else { @@ -974,7 +973,6 @@ export default class MessageSender { reject(new SendMessageProtoError(result)); return; } - resolve(result); }; @@ -1808,15 +1806,15 @@ export default class MessageSender { sendLogCallback?: SendLogCallbackType; timestamp: number; }>): Promise { - const dataMessage = proto.dataMessage - ? Proto.DataMessage.encode(proto.dataMessage).finish() - : undefined; - const myE164 = window.textsecure.storage.user.getNumber(); const myUuid = window.textsecure.storage.user.getUuid()?.toString(); const identifiers = recipients.filter(id => id !== myE164 && id !== myUuid); if (identifiers.length === 0) { + const dataMessage = proto.dataMessage + ? Proto.DataMessage.encode(proto.dataMessage).finish() + : undefined; + return Promise.resolve({ dataMessage, errors: [], @@ -1828,7 +1826,6 @@ export default class MessageSender { return new Promise((resolve, reject) => { const callback = (res: CallbackResultType) => { - res.dataMessage = dataMessage; if (res.errors && res.errors.length > 0) { reject(new SendMessageProtoError(res)); } else { diff --git a/ts/util/wrapWithSyncMessageSend.ts b/ts/util/wrapWithSyncMessageSend.ts index 5117f22ac9..ced27b8690 100644 --- a/ts/util/wrapWithSyncMessageSend.ts +++ b/ts/util/wrapWithSyncMessageSend.ts @@ -75,7 +75,7 @@ export async function wrapWithSyncMessageSend({ `wrapWithSyncMessageSend/${logId}: dataMessage was not returned by send!` ); } else { - log.error(`wrapWithSyncMessageSend/${logId}: Sending sync message...`); + log.info(`wrapWithSyncMessageSend/${logId}: Sending sync message...`); const ourConversation = window.ConversationController.getOurConversationOrThrow(); const options = await getSendOptions(ourConversation.attributes, { @@ -83,8 +83,8 @@ export async function wrapWithSyncMessageSend({ }); await handleMessageSend( sender.sendSyncMessage({ - destination: ourConversation.get('e164'), - destinationUuid: ourConversation.get('uuid'), + destination: conversation.get('e164'), + destinationUuid: conversation.get('uuid'), encodedDataMessage: dataMessage, expirationStartTimestamp: null, options,