Merge pull request #1071 from vector-im/dispose-handler

Dispose cross-signing and subscriptions
This commit is contained in:
Bruno Windels 2023-03-31 14:22:55 +02:00 committed by GitHub
commit a925ec622a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -252,7 +252,9 @@ export class Session {
this._keyBackup.get().dispose();
this._keyBackup.set(undefined);
}
if (this._crossSigning.get()) {
const crossSigning = this._crossSigning.get();
if (crossSigning) {
crossSigning.dispose();
this._crossSigning.set(undefined);
}
const key = await ssssKeyFromCredential(type, credential, this._storage, this._platform, this._olm);
@ -317,7 +319,9 @@ export class Session {
this._keyBackup.get().dispose();
this._keyBackup.set(undefined);
}
if (this._crossSigning.get()) {
const crossSigning = this._crossSigning.get();
if (crossSigning) {
crossSigning.dispose();
this._crossSigning.set(undefined);
}
}
@ -374,6 +378,9 @@ export class Session {
if (await crossSigning.load(log)) {
this._crossSigning.set(crossSigning);
}
else {
crossSigning.dispose();
}
});
}
} catch (err) {
@ -547,6 +554,7 @@ export class Session {
this._e2eeAccount = undefined;
this._callHandler?.dispose();
this._callHandler = undefined;
this._crossSigning.get()?.dispose();
for (const room of this._rooms.values()) {
room.dispose();
}

View File

@ -119,10 +119,8 @@ export class CrossSigning {
this.deviceId = options.deviceId;
this.e2eeAccount = options.e2eeAccount
this.deviceMessageHandler = options.deviceMessageHandler;
this.deviceMessageHandler.on("message", async ({ unencrypted: unencryptedEvent }) => {
this._handleSASDeviceMessage(unencryptedEvent);
})
this.handleSASDeviceMessage = this.handleSASDeviceMessage.bind(this);
this.deviceMessageHandler.on("message", this.handleSASDeviceMessage);
}
/** @return {boolean} whether cross signing has been enabled on this account */
@ -209,7 +207,7 @@ export class CrossSigning {
return this.sasVerificationInProgress;
}
private _handleSASDeviceMessage(event: any) {
private handleSASDeviceMessage({ unencrypted: event }) {
const txnId = event.content.transaction_id;
/**
* If we receive an event for the current/previously finished
@ -376,6 +374,10 @@ export class CrossSigning {
});
}
dispose(): void {
this.deviceMessageHandler.off("message", this.handleSASDeviceMessage);
}
observeUserTrust(userId: string, log: ILogItem): BaseObservableValue<UserTrust | undefined> {
const existingValue = this.observedUsers.get(userId);
if (existingValue) {