From b70560934169a010ad1c930aa5984d4c1f63b04d Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 31 May 2023 08:54:45 -0700 Subject: [PATCH] Fix edit message in Note to Self --- ts/jobs/helpers/sendNormalMessage.ts | 2 +- ts/jobs/helpers/sendReaction.ts | 2 +- ts/textsecure/SendMessage.ts | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ts/jobs/helpers/sendNormalMessage.ts b/ts/jobs/helpers/sendNormalMessage.ts index f6db071aa96d..3b7b7cdfa117 100644 --- a/ts/jobs/helpers/sendNormalMessage.ts +++ b/ts/jobs/helpers/sendNormalMessage.ts @@ -221,7 +221,7 @@ export async function sendNormalMessage( // or sending a story to a group where all other users don't have the stories // capabilities (effectively a 'lonely group' in the context of stories) log.info('sending sync message only'); - const dataMessage = await messaging.getDataMessage({ + const dataMessage = await messaging.getDataOrEditMessage({ attachments, body, bodyRanges, diff --git a/ts/jobs/helpers/sendReaction.ts b/ts/jobs/helpers/sendReaction.ts index f9f05f929f65..5cd7019eac5c 100644 --- a/ts/jobs/helpers/sendReaction.ts +++ b/ts/jobs/helpers/sendReaction.ts @@ -168,7 +168,7 @@ export async function sendReaction( if (recipientIdentifiersWithoutMe.length === 0) { log.info('sending sync reaction message only'); - const dataMessage = await messaging.getDataMessage({ + const dataMessage = await messaging.getDataOrEditMessage({ attachments: [], expireTimer, groupV2: conversation.getGroupV2Info({ diff --git a/ts/textsecure/SendMessage.ts b/ts/textsecure/SendMessage.ts index dff921c6a5b2..e0aa4b6c7b76 100644 --- a/ts/textsecure/SendMessage.ts +++ b/ts/textsecure/SendMessage.ts @@ -566,10 +566,6 @@ class Message { this.dataMessage = proto; return proto; } - - encode(): Uint8Array { - return Proto.DataMessage.encode(this.toProto()).finish(); - } } type AddPniSignatureMessageToProtoOptionsType = Readonly<{ @@ -687,11 +683,21 @@ export default class MessageSender { return textAttachment; } - async getDataMessage( + async getDataOrEditMessage( options: Readonly ): Promise { const message = await this.getHydratedMessage(options); - return message.encode(); + const dataMessage = message.toProto(); + + if (options.editedMessageTimestamp) { + const editMessage = new Proto.EditMessage(); + editMessage.dataMessage = dataMessage; + editMessage.targetSentTimestamp = Long.fromNumber( + options.editedMessageTimestamp + ); + return Proto.EditMessage.encode(editMessage).finish(); + } + return Proto.DataMessage.encode(dataMessage).finish(); } async getStoryMessage({