Skip to content

Commit

Permalink
refactor: Use a match arm when evaluating session comparison results
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Oct 1, 2024
1 parent 2fc4aac commit e5bd760
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions crates/matrix-sdk-crypto/src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,9 @@ impl OlmMachine {

#[instrument(
skip_all,
// This function is only ever called by add_room_key via
// handle_decrypted_to_device_event, so sender, sender_key, and algorithm are
// already recorded.
// This function is only ever called by add_room_key via
// handle_decrypted_to_device_event, so sender, sender_key, and algorithm are
// already recorded.
fields(room_id = ? content.room_id, session_id)
)]
async fn handle_key(
Expand Down Expand Up @@ -888,17 +888,21 @@ impl OlmMachine {

session.sender_data = sender_data;

if self.store().compare_group_session(&session).await? == SessionOrdering::Better {
info!("Received a new megolm room key");
match self.store().compare_group_session(&session).await? {
SessionOrdering::Better => {
info!("Received a new megolm room key");

Ok(Some(session))
} else {
warn!(
"Received a megolm room key that we already have a better version of, \
discarding",
);

Ok(None)
Ok(Some(session))
}
comparison_result => {
warn!(
?comparison_result,
"Received a megolm room key that we already have a better version \
of, discarding"
);

Ok(None)
}
}
}
Err(e) => {
Expand Down

0 comments on commit e5bd760

Please sign in to comment.