From cc221fb678ee3f4c629c397c0fe8d338b8f3225a Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 4 Aug 2023 10:18:28 -0400 Subject: [PATCH] Apply review recommendations --- src/e2ee/RustEngine.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/e2ee/RustEngine.ts b/src/e2ee/RustEngine.ts index 69c9576e..135085e6 100644 --- a/src/e2ee/RustEngine.ts +++ b/src/e2ee/RustEngine.ts @@ -125,7 +125,7 @@ export class RustEngine { if (keysClaim) { await this.processKeysClaimRequest(keysClaim); // Back up keys asynchronously - this.backupRoomKeysIfEnabled(); + void this.backupRoomKeysIfEnabled(); } }); @@ -140,6 +140,7 @@ export class RustEngine { public enableKeyBackup(info: IKeyBackupInfoRetrieved): Promise { this.keyBackupWaiter = this.keyBackupWaiter.then(async () => { if (this.isBackupEnabled) { + // Finish any pending backups before changing the backup version/pubkey await this.actuallyDisableKeyBackup(); } // TODO Error with message if the key backup uses an unsupported auth_data type @@ -151,15 +152,17 @@ export class RustEngine { } public disableKeyBackup(): Promise { - this.keyBackupWaiter = this.keyBackupWaiter.then(this.actuallyDisableKeyBackup); + this.keyBackupWaiter = this.keyBackupWaiter.then(async () => { + await this.actuallyDisableKeyBackup(); + }); return this.keyBackupWaiter; } - private readonly actuallyDisableKeyBackup = async () => { + private async actuallyDisableKeyBackup(): Promise { await this.machine.disableBackup(); this.keyBackupVersion = undefined; this.isBackupEnabled = false; - }; + } public backupRoomKeys(): Promise { this.keyBackupWaiter = this.keyBackupWaiter.then(async () => { @@ -180,12 +183,12 @@ export class RustEngine { return this.keyBackupWaiter; } - private readonly actuallyBackupRoomKeys = async () => { + private async actuallyBackupRoomKeys(): Promise { const request = await this.machine.backupRoomKeys(); if (request) { await this.processKeysBackupRequest(request); } - }; + } private async processKeysClaimRequest(request: KeysClaimRequest) { const resp = await this.client.doRequest("POST", "/_matrix/client/v3/keys/claim", null, JSON.parse(request.body));