From 5c0fcad6b1acfeff427a396d6e57f340d2165acd Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Sat, 24 Oct 2020 08:11:18 -0700 Subject: [PATCH] Properly prepare, await and hand response for sync message send --- ts/models/conversations.ts | 45 ++++++++++++++++++++++++-------- ts/textsecure/OutgoingMessage.ts | 3 ++- ts/textsecure/SendMessage.ts | 15 ++++++----- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 2febf59d6b67..6784da96e7b1 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -1381,17 +1381,40 @@ export class ConversationModel extends window.Backbone.Model< } ); - await wrap( - window.textsecure.messaging.syncMessageRequestResponse( - { - threadE164: this.get('e164'), - threadUuid: this.get('uuid'), - groupId: this.get('groupId'), - type: response, - }, - sendOptions - ) - ); + const groupId = this.get('groupId'); + let groupIdBuffer; + if (groupId && this.isGroupV1()) { + groupIdBuffer = fromEncodedBinaryToArrayBuffer(groupId); + } else if (groupId && this.isGroupV2()) { + groupIdBuffer = base64ToArrayBuffer(groupId); + } + + try { + await wrap( + window.textsecure.messaging.syncMessageRequestResponse( + { + threadE164: this.get('e164'), + threadUuid: this.get('uuid'), + groupId: groupIdBuffer, + type: response, + }, + sendOptions + ) + ); + } catch (result) { + if (result instanceof Error) { + throw result; + } else if (result && result.errors) { + // We filter out unregistered user errors, because we ignore those in groups + const wasThereARealError = window._.some( + result.errors, + error => error.name !== 'UnregisteredUserError' + ); + if (wasThereARealError) { + throw result; + } + } + } } onMessageError(): void { diff --git a/ts/textsecure/OutgoingMessage.ts b/ts/textsecure/OutgoingMessage.ts index 36d249bece47..beb0b3d6b7e4 100644 --- a/ts/textsecure/OutgoingMessage.ts +++ b/ts/textsecure/OutgoingMessage.ts @@ -14,6 +14,7 @@ import { CallbackResultType, SendMetadataType, SendOptionsType, + CustomError, } from './SendMessage'; import { OutgoingIdentityKeyError, @@ -44,7 +45,7 @@ export default class OutgoingMessage { identifiersCompleted: number; - errors: Array; + errors: Array; successfulIdentifiers: Array; diff --git a/ts/textsecure/SendMessage.ts b/ts/textsecure/SendMessage.ts index b4772e7a6cad..c11d068c0a0a 100644 --- a/ts/textsecure/SendMessage.ts +++ b/ts/textsecure/SendMessage.ts @@ -67,10 +67,15 @@ export type SendOptionsType = { online?: boolean; }; +export interface CustomError extends Error { + identifier?: string; + number?: string; +} + export type CallbackResultType = { successfulIdentifiers?: Array; failoverIdentifiers?: Array; - errors?: Array; + errors?: Array; unidentifiedDeliveries?: Array; dataMessage?: ArrayBuffer; discoveredIdentifierPairs: Array<{ @@ -1216,7 +1221,7 @@ export default class MessageSender { responseArgs: { threadE164?: string; threadUuid?: string; - groupId?: string; + groupId?: ArrayBuffer; type: number; }, sendOptions?: SendOptionsType @@ -1233,11 +1238,7 @@ export default class MessageSender { const response = new window.textsecure.protobuf.SyncMessage.MessageRequestResponse(); response.threadE164 = responseArgs.threadE164; response.threadUuid = responseArgs.threadUuid; - response.groupId = responseArgs.groupId - ? window.Signal.Crypto.fromEncodedBinaryToArrayBuffer( - responseArgs.groupId - ) - : null; + response.groupId = responseArgs.groupId || null; response.type = responseArgs.type; syncMessage.messageRequestResponse = response;