From 371c73377ce6f5c761835014052828b777f62b75 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 9 Mar 2023 15:33:12 -0800 Subject: [PATCH] Move setVerified to conversation queue --- ts/models/conversations.ts | 12 +++++++++--- ts/textsecure/Errors.ts | 5 ++++- ts/textsecure/OutgoingMessage.ts | 4 ++-- ts/textsecure/getKeysForIdentifier.ts | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index a4f7d6333a..9f82bc6242 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -2662,8 +2662,10 @@ export class ConversationModel extends window.Backbone await this.initialPromise; const verified = await this.safeGetVerified(); - if (this.get('verified') !== verified) { + const oldVerified = this.get('verified'); + if (oldVerified !== verified) { this.set({ verified }); + this.captureChange(`updateVerified from=${oldVerified} to=${verified}`); window.Signal.Data.updateConversation(this.attributes); } @@ -2730,7 +2732,9 @@ export class ConversationModel extends window.Backbone window.Signal.Data.updateConversation(this.attributes); if (beginningVerified !== verified) { - this.captureChange(`verified from=${beginningVerified} to=${verified}`); + this.captureChange( + `_setVerified from=${beginningVerified} to=${verified}` + ); } const didVerifiedChange = beginningVerified !== verified; @@ -2861,7 +2865,9 @@ export class ConversationModel extends window.Backbone return; } - return window.textsecure.storage.protocol.setApproval(uuid, true); + return this.queueJob('setApproved', async () => { + return window.textsecure.storage.protocol.setApproval(uuid, true); + }); } safeIsUntrusted(timestampThreshold?: number): boolean { diff --git a/ts/textsecure/Errors.ts b/ts/textsecure/Errors.ts index 8d090128e6..45fcfc6ddd 100644 --- a/ts/textsecure/Errors.ts +++ b/ts/textsecure/Errors.ts @@ -3,6 +3,8 @@ /* eslint-disable max-classes-per-file */ +import type { LibSignalErrorBase } from '@signalapp/libsignal-client'; + import { parseRetryAfter } from '../util/parseRetryAfter'; import type { CallbackResultType } from './Types.d'; @@ -76,12 +78,13 @@ export class OutgoingIdentityKeyError extends ReplayableError { public readonly identifier: string; // Note: Data to resend message is no longer captured - constructor(incomingIdentifier: string) { + constructor(incomingIdentifier: string, cause?: LibSignalErrorBase) { const identifier = incomingIdentifier.split('.')[0]; super({ name: 'OutgoingIdentityKeyError', message: `The identity of ${identifier} has changed.`, + cause, }); this.identifier = identifier; diff --git a/ts/textsecure/OutgoingMessage.ts b/ts/textsecure/OutgoingMessage.ts index ca2468a20f..af4ab33b4f 100644 --- a/ts/textsecure/OutgoingMessage.ts +++ b/ts/textsecure/OutgoingMessage.ts @@ -627,7 +627,7 @@ export default class OutgoingMessage { error instanceof LibSignalErrorBase && error.code === ErrorCode.UntrustedIdentity ) { - newError = new OutgoingIdentityKeyError(identifier); + newError = new OutgoingIdentityKeyError(identifier, error); log.error( 'Got "key changed" error from encrypt - no identityKey for application layer', identifier, @@ -736,7 +736,7 @@ export default class OutgoingMessage { error instanceof LibSignalErrorBase && error.code === ErrorCode.UntrustedIdentity ) { - const newError = new OutgoingIdentityKeyError(identifier); + const newError = new OutgoingIdentityKeyError(identifier, error); this.registerError(identifier, 'Untrusted identity', newError); } else { this.registerError( diff --git a/ts/textsecure/getKeysForIdentifier.ts b/ts/textsecure/getKeysForIdentifier.ts index a808dee56c..5a6608f12d 100644 --- a/ts/textsecure/getKeysForIdentifier.ts +++ b/ts/textsecure/getKeysForIdentifier.ts @@ -167,7 +167,7 @@ async function handleServerKeys( error instanceof LibSignalErrorBase && error.code === ErrorCode.UntrustedIdentity ) { - throw new OutgoingIdentityKeyError(identifier); + throw new OutgoingIdentityKeyError(identifier, error); } throw error; }