From 9fba86cb9947b54e982ce71a68e1adf4909d6df5 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 21 Nov 2024 17:46:18 +0100 Subject: [PATCH] Review changes --- src/DeviceListener.ts | 9 +++++---- src/components/structures/MatrixChat.tsx | 2 +- .../views/dialogs/security/RestoreKeyBackupDialog.tsx | 2 +- src/components/views/settings/SecureBackupPanel.tsx | 2 +- src/stores/SetupEncryptionStore.ts | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/DeviceListener.ts b/src/DeviceListener.ts index 8990c2303b..84d83827da 100644 --- a/src/DeviceListener.ts +++ b/src/DeviceListener.ts @@ -231,11 +231,12 @@ export default class DeviceListener { if (!this.client) return null; const now = new Date().getTime(); const crypto = this.client.getCrypto(); + if (!crypto) return null; + if ( - crypto && - (!this.keyBackupInfo || - !this.keyBackupFetchedAt || - this.keyBackupFetchedAt < now - KEY_BACKUP_POLL_INTERVAL) + !this.keyBackupInfo || + !this.keyBackupFetchedAt || + this.keyBackupFetchedAt < now - KEY_BACKUP_POLL_INTERVAL ) { this.keyBackupInfo = await crypto.getKeyBackupInfo(); this.keyBackupFetchedAt = now; diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 119895f65c..9f9e225352 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1638,7 +1638,7 @@ export default class MatrixChat extends React.PureComponent { } else { // otherwise check the server to see if there's a new one try { - newVersionInfo = (await cli.getCrypto()?.getKeyBackupInfo()) || null; + newVersionInfo = (await cli.getCrypto()?.getKeyBackupInfo()) ?? null; if (newVersionInfo !== null) haveNewVersion = true; } catch (e) { logger.error("Saw key backup error but failed to check backup version!", e); diff --git a/src/components/views/dialogs/security/RestoreKeyBackupDialog.tsx b/src/components/views/dialogs/security/RestoreKeyBackupDialog.tsx index 3799a3e8f1..fddba10948 100644 --- a/src/components/views/dialogs/security/RestoreKeyBackupDialog.tsx +++ b/src/components/views/dialogs/security/RestoreKeyBackupDialog.tsx @@ -258,7 +258,7 @@ export default class RestoreKeyBackupDialog extends React.PureComponent { this.getUpdatedDiagnostics(); try { const cli = MatrixClientPeg.safeGet(); - const backupInfo = (await cli.getCrypto()?.getKeyBackupInfo()) || null; + const backupInfo = (await cli.getCrypto()?.getKeyBackupInfo()) ?? null; const backupTrustInfo = backupInfo ? await cli.getCrypto()?.isKeyBackupTrusted(backupInfo) : undefined; const activeBackupVersion = (await cli.getCrypto()?.getActiveSessionBackupVersion()) ?? null; diff --git a/src/stores/SetupEncryptionStore.ts b/src/stores/SetupEncryptionStore.ts index de8289de56..70c721b1ca 100644 --- a/src/stores/SetupEncryptionStore.ts +++ b/src/stores/SetupEncryptionStore.ts @@ -125,7 +125,7 @@ export class SetupEncryptionStore extends EventEmitter { this.emit("update"); try { const cli = MatrixClientPeg.safeGet(); - const backupInfo = (await cli.getCrypto()?.getKeyBackupInfo()) || null; + const backupInfo = (await cli.getCrypto()?.getKeyBackupInfo()) ?? null; this.backupInfo = backupInfo; this.emit("update");