From 37aa3146bb81eb03e0c24e0261031878fde6a5d5 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 7 Jan 2021 11:33:27 -0800 Subject: [PATCH] Be resilient to missing data in MessageReceiver constructor --- ts/textsecure/MessageReceiver.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index e7dafafa2886..041c032b71b1 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -113,7 +113,7 @@ class MessageReceiverInner extends EventTarget { count: number; - deviceId: number; + deviceId?: number; hasConnected?: boolean; @@ -121,7 +121,7 @@ class MessageReceiverInner extends EventTarget { isEmptied?: boolean; - number_id: string | null; + number_id?: string; password: string; @@ -143,7 +143,7 @@ class MessageReceiverInner extends EventTarget { uuid: string; - uuid_id: string | null; + uuid_id?: string; wsr?: WebSocketResource; @@ -176,12 +176,14 @@ class MessageReceiverInner extends EventTarget { options.serverTrustRoot ); - this.number_id = oldUsername ? utils.unencodeNumber(oldUsername)[0] : null; - this.uuid_id = username ? utils.unencodeNumber(username)[0] : null; - this.deviceId = parseInt( - utils.unencodeNumber(username || oldUsername)[1], - 10 - ); + this.number_id = oldUsername + ? utils.unencodeNumber(oldUsername)[0] + : undefined; + this.uuid_id = username ? utils.unencodeNumber(username)[0] : undefined; + this.deviceId = + username || oldUsername + ? parseInt(utils.unencodeNumber(username || oldUsername)[1], 10) + : undefined; this.incomingQueue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 }); this.pendingQueue = new PQueue({ concurrency: 1, timeout: 1000 * 60 * 2 });