From 0542c057386c71b87abc7525663732a422cafb7d Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 12 Dec 2024 16:34:06 +0000 Subject: [PATCH] Attempt to reword the complex if --- .../src/types/events/utd_cause.rs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/types/events/utd_cause.rs b/crates/matrix-sdk-crypto/src/types/events/utd_cause.rs index ea39c61dae3..cb010796522 100644 --- a/crates/matrix-sdk-crypto/src/types/events/utd_cause.rs +++ b/crates/matrix-sdk-crypto/src/types/events/utd_cause.rs @@ -217,19 +217,24 @@ impl UtdCause { * ``` */ fn determine_historical(crypto_context_info: CryptoContextInfo) -> UtdCause { - let backup_exist = crypto_context_info.backup_exists_on_server; - let is_backup_configured = crypto_context_info.is_backup_configured; - let are_we_verified = crypto_context_info.this_device_is_verified; - - match (backup_exist, is_backup_configured || are_we_verified) { - (true, true) => { - // Either backup download is working but we still don't have the key, or backup - // download *isn't* working despite being verified. In either - // case, we shrug and give an `Unknown` cause. - UtdCause::Unknown - } - (true, false) => UtdCause::HistoricalMessageAndDeviceIsUnverified, - (false, _) => UtdCause::HistoricalMessageAndBackupIsDisabled, + let backup_disabled = !crypto_context_info.backup_exists_on_server; + let backup_failing = !crypto_context_info.is_backup_configured; + let unverified = !crypto_context_info.this_device_is_verified; + + if backup_disabled { + UtdCause::HistoricalMessageAndBackupIsDisabled + } else if backup_failing && unverified { + UtdCause::HistoricalMessageAndDeviceIsUnverified + } else { + // We didn't get the key from key storage backup, but we think we should have, + // because either: + // + // * backup is working (so why didn't we get it?), or + // * backup is not working for an unknown reason (because the device is + // verified, and that is the only reason we check). + // + // In either case, we shrug and give an `Unknown` cause. + UtdCause::Unknown } } }