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.
This commit is contained in:
RMidhunSuresh 2023-05-17 12:28:57 +05:30
parent 901c149e9e
commit a582aa1746
2 changed files with 5 additions and 39 deletions

View File

@ -19,7 +19,6 @@ import {TileShape} from "./ITile";
import {SimpleTile} from "./SimpleTile"; import {SimpleTile} from "./SimpleTile";
import {UpdateAction} from "../UpdateAction.js" import {UpdateAction} from "../UpdateAction.js"
import {VerificationEventType} from "../../../../../matrix/verification/SAS/channel/types"; 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 {EventEntry} from "../../../../../matrix/room/timeline/entries/EventEntry.js";
import type {Options} from "./SimpleTile"; import type {Options} from "./SimpleTile";
@ -38,12 +37,6 @@ export class VerificationTile extends SimpleTile {
constructor(entry: EventEntry, options: Options) { constructor(entry: EventEntry, options: Options) {
super(entry, options); super(entry, options);
this.request = new SASRequest(this.lowerEntry); 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 // Calculate status based on available context-for entries
this.updateStatusFromAvailableContextForEntries(); this.updateStatusFromAvailableContextForEntries();
} }
@ -82,29 +75,6 @@ export class VerificationTile extends SimpleTile {
this.navigation.applyPath(path); 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) { updateEntry(entry: any, param: any) {
if (param === "context-added") { if (param === "context-added") {
// We received a new contextForEntry, maybe it tells us that // We received a new contextForEntry, maybe it tells us that

View File

@ -16,7 +16,6 @@ limitations under the License.
import {verifyEd25519Signature, SignatureVerification} from "../e2ee/common"; import {verifyEd25519Signature, SignatureVerification} from "../e2ee/common";
import {BaseObservableValue, RetainedObservableValue} from "../../observable/value"; import {BaseObservableValue, RetainedObservableValue} from "../../observable/value";
import {ObservableValue} from "../../observable/value";
import {pkSign} from "./common"; import {pkSign} from "./common";
import {SASVerification} from "./SAS/SASVerification"; import {SASVerification} from "./SAS/SASVerification";
import {ToDeviceChannel} from "./SAS/channel/ToDeviceChannel"; import {ToDeviceChannel} from "./SAS/channel/ToDeviceChannel";
@ -101,7 +100,7 @@ export class CrossSigning {
private _isMasterKeyTrusted: boolean = false; private _isMasterKeyTrusted: boolean = false;
private readonly observedUsers: Map<string, RetainedObservableValue<UserTrust | undefined>> = new Map(); private readonly observedUsers: Map<string, RetainedObservableValue<UserTrust | undefined>> = new Map();
private readonly deviceId: string; private readonly deviceId: string;
public sasVerificationObservable: ObservableValue<SASVerification | undefined> = new ObservableValue(undefined); private sasVerificationInProgress?: SASVerification;
public receivedSASVerifications: ObservableMap<string, SASRequest> = new ObservableMap(); public receivedSASVerifications: ObservableMap<string, SASRequest> = new ObservableMap();
constructor(options: { constructor(options: {
@ -187,8 +186,7 @@ export class CrossSigning {
startVerification(requestOrUserId: string, logOrRoom: Room, _log: ILogItem): SASVerification | undefined; startVerification(requestOrUserId: string, logOrRoom: Room, _log: ILogItem): SASVerification | undefined;
startVerification(requestOrUserId: string | SASRequest, logOrRoom: Room | ILogItem, _log?: ILogItem): SASVerification | undefined { startVerification(requestOrUserId: string | SASRequest, logOrRoom: Room | ILogItem, _log?: ILogItem): SASVerification | undefined {
const log: ILogItem = _log ?? logOrRoom; const log: ILogItem = _log ?? logOrRoom;
const sasVerificationInProgress = this.sasVerificationObservable.get(); if (this.sasVerificationInProgress && !this.sasVerificationInProgress.finished) {
if (sasVerificationInProgress && !sasVerificationInProgress.finished) {
log.log({ sasVerificationAlreadyInProgress: true }); log.log({ sasVerificationAlreadyInProgress: true });
return; return;
} }
@ -216,7 +214,7 @@ export class CrossSigning {
}, startingMessage); }, startingMessage);
} }
const sas = new SASVerification({ this.sasVerificationInProgress = new SASVerification({
olm: this.olm, olm: this.olm,
olmUtil: this.olmUtil, olmUtil: this.olmUtil,
ourUserId: this.ownUserId, ourUserId: this.ownUserId,
@ -229,8 +227,7 @@ export class CrossSigning {
hsApi: this.hsApi, hsApi: this.hsApi,
clock: this.platform.clock, clock: this.platform.clock,
}); });
this.sasVerificationObservable.set(sas); return this.sasVerificationInProgress;
return sas;
} }
private handleSASDeviceMessage({ unencrypted: event }) { private handleSASDeviceMessage({ unencrypted: event }) {
@ -240,8 +237,7 @@ export class CrossSigning {
* SAS verification, we should ignore it because the device channel * 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). * object (who also listens for to_device messages) will take care of it (if needed).
*/ */
const sasVerificationInProgress = this.sasVerificationObservable.get(); const shouldIgnoreEvent = this.sasVerificationInProgress?.channel.id === txnId;
const shouldIgnoreEvent = sasVerificationInProgress?.channel.id === txnId;
if (shouldIgnoreEvent) { return; } if (shouldIgnoreEvent) { return; }
/** /**
* 1. If we receive the cancel message, we need to update the requests map. * 1. If we receive the cancel message, we need to update the requests map.