Skip to content

Commit

Permalink
refactor(timeline): retry_event_decryption: re-use utd cause
Browse files Browse the repository at this point in the history
Rather than calling `UtdCause::determine` again when an event is successfully
decrypted on retry, re-use the cause we already determined.
  • Loading branch information
richvdh committed Oct 21, 2024
1 parent 106036f commit dac9f06
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions crates/matrix-sdk-ui/src/timeline/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,6 @@ impl<P: RoomDataProvider> TimelineController<P> {
decryptor: impl Decryptor,
session_ids: Option<BTreeSet<String>>,
) {
use matrix_sdk::crypto::types::events::UtdCause;

use super::EncryptedMessage;

let mut state = self.state.clone().write_owned().await;
Expand Down Expand Up @@ -1038,16 +1036,17 @@ impl<P: RoomDataProvider> TimelineController<P> {
async move {
let event_item = item.as_event()?;

let session_id = match event_item.content().as_unable_to_decrypt()? {
EncryptedMessage::MegolmV1AesSha2 { session_id, .. }
if should_retry(session_id) =>
{
session_id
}
EncryptedMessage::MegolmV1AesSha2 { .. }
| EncryptedMessage::OlmV1Curve25519AesSha2 { .. }
| EncryptedMessage::Unknown => return None,
};
let (session_id, utd_cause) =
match event_item.content().as_unable_to_decrypt()? {
EncryptedMessage::MegolmV1AesSha2 { session_id, cause, .. }
if should_retry(session_id) =>
{
(session_id, cause)
}
EncryptedMessage::MegolmV1AesSha2 { .. }
| EncryptedMessage::OlmV1Curve25519AesSha2 { .. }
| EncryptedMessage::Unknown => return None,
};

tracing::Span::current().record("session_id", session_id);

Expand All @@ -1069,11 +1068,9 @@ impl<P: RoomDataProvider> TimelineController<P> {
"Successfully decrypted event that previously failed to decrypt"
);

let cause = UtdCause::determine(Some(original_json));

// Notify observers that we managed to eventually decrypt an event.
if let Some(hook) = unable_to_decrypt_hook {
hook.on_late_decrypt(&remote_event.event_id, cause).await;
hook.on_late_decrypt(&remote_event.event_id, *utd_cause).await;
}

Some(event)
Expand Down

0 comments on commit dac9f06

Please sign in to comment.