From 8a815583f15764288178e1ac012b903b9558e05f Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Mon, 30 Mar 2026 16:37:11 +0100 Subject: [PATCH] Remove now-unneeded initial 'all is ok' check in DeviceListener --- .../DeviceListenerCurrentDevice.ts | 83 ++++++++----------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts b/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts index d99fa6bd56..5e9946abad 100644 --- a/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts +++ b/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts @@ -181,56 +181,45 @@ export class DeviceListenerCurrentDevice { const keyBackupDownloadIsOk = !keyBackupUploadActive || backupDisabled || (await crypto.getSessionBackupPrivateKey()) !== null; - const allSystemsReady = - isCurrentDeviceTrusted && - allCrossSigningSecretsCached && - keyBackupUploadIsOk && - recoveryIsOk && - keyBackupDownloadIsOk; + if (!isCurrentDeviceTrusted) { + // The current device is not trusted: prompt the user to verify + await this.failedCheck("verify_this_session", logSpan, "info", "Current device not verified"); + } else if (!allCrossSigningSecretsCached) { + // cross signing ready & device trusted, but we are missing secrets from our local cache. + // prompt the user to enter their recovery key. + const newState = crossSigningStatus.privateKeysInSecretStorage + ? "key_storage_out_of_sync" + : "identity_needs_reset"; - if (allSystemsReady) { + await this.failedCheck( + newState, + logSpan, + "info", + "Some secrets not cached", + crossSigningStatus.privateKeysCachedLocally, + crossSigningStatus.privateKeysInSecretStorage, + ); + } else if (!keyBackupUploadIsOk) { + await this.failedCheck( + "turn_on_key_storage", + logSpan, + "info", + "Key backup upload is unexpectedly turned off", + ); + } else if (!recoveryIsOk) { + if (secretStorageStatus.defaultKeyId === null) { + await this.failedCheck("set_up_recovery", logSpan, "info", "No default 4S key"); + } else { + await this.failedCheck("key_storage_out_of_sync", logSpan, "warn", "4S is missing secrets", { + secretStorageStatus, + }); + } + } else if (!keyBackupDownloadIsOk) { + await this.failedCheck("key_storage_out_of_sync", logSpan, "warn", "Backup key is not cached locally"); + } else { + // Everything is OK - no need to show a toast logSpan.info("No toast needed"); await this.setDeviceState("ok", logSpan); - } else { - if (!isCurrentDeviceTrusted) { - // The current device is not trusted: prompt the user to verify - await this.failedCheck("verify_this_session", logSpan, "info", "Current device not verified"); - } else if (!allCrossSigningSecretsCached) { - // cross signing ready & device trusted, but we are missing secrets from our local cache. - // prompt the user to enter their recovery key. - const newState = crossSigningStatus.privateKeysInSecretStorage - ? "key_storage_out_of_sync" - : "identity_needs_reset"; - - await this.failedCheck( - newState, - logSpan, - "info", - "Some secrets not cached", - crossSigningStatus.privateKeysCachedLocally, - crossSigningStatus.privateKeysInSecretStorage, - ); - } else if (!keyBackupUploadIsOk) { - await this.failedCheck( - "turn_on_key_storage", - logSpan, - "info", - "Key backup upload is unexpectedly turned off", - ); - } else if (!recoveryIsOk) { - if (secretStorageStatus.defaultKeyId === null) { - await this.failedCheck("set_up_recovery", logSpan, "info", "No default 4S key"); - } else { - await this.failedCheck("key_storage_out_of_sync", logSpan, "warn", "4S is missing secrets", { - secretStorageStatus, - }); - } - } else if (!keyBackupDownloadIsOk) { - await this.failedCheck("key_storage_out_of_sync", logSpan, "warn", "Backup key is not cached locally"); - } else { - // We should not get here - throw new Error("DeviceListenerCurrentDevice is in an unexpected state"); - } } }