Skip to content

Commit

Permalink
Attempt to reword the complex if
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Dec 12, 2024
1 parent ffe7486 commit 0542c05
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions crates/matrix-sdk-crypto/src/types/events/utd_cause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 0542c05

Please sign in to comment.