From d4d96884472aeb6fec2919f0438748dd15489d5e Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 6 Nov 2020 11:06:21 -0800 Subject: [PATCH] Ensure authorUuid is set in outgoing quotes --- ts/models/conversations.ts | 8 ++++---- ts/textsecure.d.ts | 18 +++++++++--------- ts/textsecure/SendMessage.ts | 32 ++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index ba98805a3a93..6003ea1e5871 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -2521,6 +2521,10 @@ export class ConversationModel extends window.Backbone.Model< // sending functionality. It will not be saved to the datbase. const message = new window.Whisper.Message(attributes); + // This is to ensure that the functions in send() and sendSyncMessage() don't save + // anything to the database. + message.doNotSave = true; + // We're offline! if (!window.textsecure.messaging) { throw new Error('Cannot send reaction while offline!'); @@ -2579,10 +2583,6 @@ export class ConversationModel extends window.Backbone.Model< ); })(); - // This is to ensure that the functions in send() and sendSyncMessage() don't save - // anything to the database. - message.doNotSave = true; - return message.send(this.wrapSend(promise)); }).catch(error => { window.log.error('Error sending reaction', reaction, target, error); diff --git a/ts/textsecure.d.ts b/ts/textsecure.d.ts index 6af49700d2d7..ead342ba67ac 100644 --- a/ts/textsecure.d.ts +++ b/ts/textsecure.d.ts @@ -606,10 +606,10 @@ export declare namespace DataMessageClass { // Note: deep nesting class Quote { - id?: ProtoBigNumberType; - author?: string; - authorUuid?: string; - text?: string; + id: ProtoBigNumberType | null; + author: string | null; + authorUuid: string | null; + text: string | null; attachments?: Array; bodyRanges?: Array; } @@ -621,11 +621,11 @@ export declare namespace DataMessageClass { } class Reaction { - emoji?: string; - remove?: boolean; - targetAuthorE164?: string; - targetAuthorUuid?: string; - targetTimestamp?: ProtoBigNumberType; + emoji: string | null; + remove: boolean | null; + targetAuthorE164: string | null; + targetAuthorUuid: string | null; + targetTimestamp: ProtoBigNumberType | null; } class Delete { diff --git a/ts/textsecure/SendMessage.ts b/ts/textsecure/SendMessage.ts index b39c404cbcbe..b0e6857638b9 100644 --- a/ts/textsecure/SendMessage.ts +++ b/ts/textsecure/SendMessage.ts @@ -148,13 +148,26 @@ class Message { profileKey?: ArrayBuffer; - quote?: any; + quote?: { + id?: number; + author?: string; + authorUuid?: string; + text?: string; + attachments?: Array; + bodyRanges?: BodyRangesType; + }; recipients: Array; sticker?: any; - reaction?: any; + reaction?: { + emoji?: string; + remove?: boolean; + targetAuthorE164?: string; + targetAuthorUuid?: string; + targetTimestamp?: number; + }; timestamp: number; @@ -288,8 +301,14 @@ class Message { } } if (this.reaction) { - proto.reaction = this.reaction; + proto.reaction = new window.textsecure.protobuf.DataMessage.Reaction(); + proto.reaction.emoji = this.reaction.emoji || null; + proto.reaction.remove = this.reaction.remove || null; + proto.reaction.targetAuthorE164 = this.reaction.targetAuthorE164 || null; + proto.reaction.targetAuthorUuid = this.reaction.targetAuthorUuid || null; + proto.reaction.targetTimestamp = this.reaction.targetTimestamp || null; } + if (Array.isArray(this.preview)) { proto.preview = this.preview.map(preview => { const item = new window.textsecure.protobuf.DataMessage.Preview(); @@ -308,9 +327,10 @@ class Message { proto.quote = new Quote(); const { quote } = proto; - quote.id = this.quote.id; - quote.author = this.quote.author; - quote.text = this.quote.text; + quote.id = this.quote.id || null; + quote.author = this.quote.author || null; + quote.authorUuid = this.quote.authorUuid || null; + quote.text = this.quote.text || null; quote.attachments = (this.quote.attachments || []).map( (attachment: AttachmentType) => { const quotedAttachment = new QuotedAttachment();