From a582aa1746e6ee116bdb6d5687d5ecd529947e36 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 17 May 2023 12:28:57 +0530 Subject: [PATCH] We don't need this to be an observable Since we treat related messages as context events, we don't need to make sasVerificationInProgress an observable. --- .../room/timeline/tiles/VerificationTile.ts | 30 ------------------- src/matrix/verification/CrossSigning.ts | 14 ++++----- 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/src/domain/session/room/timeline/tiles/VerificationTile.ts b/src/domain/session/room/timeline/tiles/VerificationTile.ts index dcfcb0e4..89d4c2f1 100644 --- a/src/domain/session/room/timeline/tiles/VerificationTile.ts +++ b/src/domain/session/room/timeline/tiles/VerificationTile.ts @@ -19,7 +19,6 @@ import {TileShape} from "./ITile"; import {SimpleTile} from "./SimpleTile"; import {UpdateAction} from "../UpdateAction.js" import {VerificationEventType} from "../../../../../matrix/verification/SAS/channel/types"; -import type {SASVerification} from "../../../../../matrix/verification/SAS/SASVerification"; import type {EventEntry} from "../../../../../matrix/room/timeline/entries/EventEntry.js"; import type {Options} from "./SimpleTile"; @@ -38,12 +37,6 @@ export class VerificationTile extends SimpleTile { constructor(entry: EventEntry, options: Options) { super(entry, options); this.request = new SASRequest(this.lowerEntry); - const crossSigning = this.getOption("session").crossSigning.get(); - this.track( - crossSigning.sasVerificationObservable.subscribe((sas) => { - this.subscribeToSASVerification(sas); - }) - ); // Calculate status based on available context-for entries this.updateStatusFromAvailableContextForEntries(); } @@ -82,29 +75,6 @@ export class VerificationTile extends SimpleTile { this.navigation.applyPath(path); } - private subscribeToSASVerification(sas: SASVerification | undefined) { - if (!sas || sas.channel.id !== this.eventId) { - return; - } - /** - * Subscribe to SAS events so that we can update the UI when each stage is - * completed. - */ - this.track( - sas.disposableOn("VerificationCancelled", (cancellation) => { - this.isCancelledByUs = cancellation?.cancelledByUs!; - this.status = Status.Cancelled; - this.emitChange("status"); - }) - ); - this.track( - sas.disposableOn("VerificationCompleted", () => { - this.status = Status.Completed; - this.emitChange("status"); - }) - ); - } - updateEntry(entry: any, param: any) { if (param === "context-added") { // We received a new contextForEntry, maybe it tells us that diff --git a/src/matrix/verification/CrossSigning.ts b/src/matrix/verification/CrossSigning.ts index d240a56f..8e569f2d 100644 --- a/src/matrix/verification/CrossSigning.ts +++ b/src/matrix/verification/CrossSigning.ts @@ -16,7 +16,6 @@ limitations under the License. import {verifyEd25519Signature, SignatureVerification} from "../e2ee/common"; import {BaseObservableValue, RetainedObservableValue} from "../../observable/value"; -import {ObservableValue} from "../../observable/value"; import {pkSign} from "./common"; import {SASVerification} from "./SAS/SASVerification"; import {ToDeviceChannel} from "./SAS/channel/ToDeviceChannel"; @@ -101,7 +100,7 @@ export class CrossSigning { private _isMasterKeyTrusted: boolean = false; private readonly observedUsers: Map> = new Map(); private readonly deviceId: string; - public sasVerificationObservable: ObservableValue = new ObservableValue(undefined); + private sasVerificationInProgress?: SASVerification; public receivedSASVerifications: ObservableMap = new ObservableMap(); constructor(options: { @@ -187,8 +186,7 @@ export class CrossSigning { startVerification(requestOrUserId: string, logOrRoom: Room, _log: ILogItem): SASVerification | undefined; startVerification(requestOrUserId: string | SASRequest, logOrRoom: Room | ILogItem, _log?: ILogItem): SASVerification | undefined { const log: ILogItem = _log ?? logOrRoom; - const sasVerificationInProgress = this.sasVerificationObservable.get(); - if (sasVerificationInProgress && !sasVerificationInProgress.finished) { + if (this.sasVerificationInProgress && !this.sasVerificationInProgress.finished) { log.log({ sasVerificationAlreadyInProgress: true }); return; } @@ -216,7 +214,7 @@ export class CrossSigning { }, startingMessage); } - const sas = new SASVerification({ + this.sasVerificationInProgress = new SASVerification({ olm: this.olm, olmUtil: this.olmUtil, ourUserId: this.ownUserId, @@ -229,8 +227,7 @@ export class CrossSigning { hsApi: this.hsApi, clock: this.platform.clock, }); - this.sasVerificationObservable.set(sas); - return sas; + return this.sasVerificationInProgress; } private handleSASDeviceMessage({ unencrypted: event }) { @@ -240,8 +237,7 @@ export class CrossSigning { * SAS verification, we should ignore it because the device channel * object (who also listens for to_device messages) will take care of it (if needed). */ - const sasVerificationInProgress = this.sasVerificationObservable.get(); - const shouldIgnoreEvent = sasVerificationInProgress?.channel.id === txnId; + const shouldIgnoreEvent = this.sasVerificationInProgress?.channel.id === txnId; if (shouldIgnoreEvent) { return; } /** * 1. If we receive the cancel message, we need to update the requests map.