From 3a726ad311eb2c0f8d2737049fb7edd08057fb53 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 11 Jan 2021 13:59:46 -0800 Subject: [PATCH] Adjust timeouts for better performance --- ts/background.ts | 10 +++++++++- ts/textsecure/AccountManager.ts | 10 ++++------ ts/textsecure/ProvisioningCipher.ts | 1 + ts/textsecure/WebAPI.ts | 2 ++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ts/background.ts b/ts/background.ts index f833a4c238..f4545fbe81 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -765,7 +765,15 @@ type WhatIsThis = import('./window.d').WhatIsThis; if (!conversation) { return; } - conversationChanged(conversation.id, conversation.format()); + + // This delay ensures that the .format() call isn't synchronous as a + // Backbone property is changed. Important because our _byUuid/_byE164 + // lookups aren't up-to-date as the change happens; just a little bit + // after. + setTimeout( + () => conversationChanged(conversation.id, conversation.format()), + 1 + ); }); convoCollection.on('reset', removeAllConversations); diff --git a/ts/textsecure/AccountManager.ts b/ts/textsecure/AccountManager.ts index be5da7ab6c..bc14928b85 100644 --- a/ts/textsecure/AccountManager.ts +++ b/ts/textsecure/AccountManager.ts @@ -487,7 +487,7 @@ export default class AccountManager extends EventTarget { readReceipts?: boolean | null, options: { accessKey?: ArrayBuffer; uuid?: string } = {} ): Promise { - const { accessKey } = options; + const { accessKey, uuid } = options; let password = btoa( utils.getString(window.libsignal.crypto.getRandomBytes(16)) ); @@ -526,8 +526,7 @@ export default class AccountManager extends EventTarget { ); const numberChanged = previousNumber && previousNumber !== number; - const uuidChanged = - previousUuid && response.uuid && previousUuid !== response.uuid; + const uuidChanged = previousUuid && uuid && previousUuid !== uuid; if (numberChanged || uuidChanged) { if (numberChanged) { @@ -576,10 +575,9 @@ export default class AccountManager extends EventTarget { deviceName ); - const setUuid = response.uuid; - if (setUuid) { + if (uuid) { await window.textsecure.storage.user.setUuidAndDeviceId( - setUuid, + uuid, response.deviceId || 1 ); } diff --git a/ts/textsecure/ProvisioningCipher.ts b/ts/textsecure/ProvisioningCipher.ts index 74426e9d73..299525f9a2 100644 --- a/ts/textsecure/ProvisioningCipher.ts +++ b/ts/textsecure/ProvisioningCipher.ts @@ -66,6 +66,7 @@ class ProvisioningCipherInner { const ret: ProvisionDecryptResult = { identityKeyPair: keyPair, number: provisionMessage.number, + uuid: provisionMessage.uuid, provisioningCode: provisionMessage.provisioningCode, userAgent: provisionMessage.userAgent, readReceipts: provisionMessage.readReceipts, diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index d83fa1662b..ca77e5e8ee 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -2366,6 +2366,7 @@ export function initialize({ password: auth.password, responseType: 'jsonwithdetails', data, + timeout: 30000, version, }); @@ -2489,6 +2490,7 @@ export function initialize({ user: directoryAuth.username, password: directoryAuth.password, responseType: 'json', + timeout: 30000, data: JSON.stringify(data), version, });