Skip to content

Commit dca6881

Browse files
committed
refactor(timeline): Extract a function to calculate which events to retry decryption
In later commits, we will make this cleverer, so it can calculate which non-UTD events need updating too.
1 parent 5cc10ba commit dca6881

File tree

1 file changed

+22
-18
lines changed
  • crates/matrix-sdk-ui/src/timeline/controller

1 file changed

+22
-18
lines changed

crates/matrix-sdk-ui/src/timeline/controller/mod.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use crate::{
8080
date_dividers::DateDividerAdjuster,
8181
event_item::EventTimelineItemKind,
8282
pinned_events_loader::{PinnedEventsLoader, PinnedEventsLoaderError},
83-
TimelineEventFilterFn,
83+
EncryptedMessage, TimelineEventFilterFn,
8484
},
8585
unable_to_decrypt_hook::UtdHookManager,
8686
};
@@ -1062,8 +1062,6 @@ impl<P: RoomDataProvider> TimelineController<P> {
10621062
decryptor: impl Decryptor,
10631063
session_ids: Option<BTreeSet<String>>,
10641064
) {
1065-
use super::EncryptedMessage;
1066-
10671065
let mut state = self.state.clone().write_owned().await;
10681066

10691067
let should_retry = move |session_id: &str| {
@@ -1074,21 +1072,7 @@ impl<P: RoomDataProvider> TimelineController<P> {
10741072
}
10751073
};
10761074

1077-
let retry_indices: Vec<_> = state
1078-
.items
1079-
.iter()
1080-
.enumerate()
1081-
.filter_map(|(idx, item)| match item.as_event()?.content().as_unable_to_decrypt()? {
1082-
EncryptedMessage::MegolmV1AesSha2 { session_id, .. }
1083-
if should_retry(session_id) =>
1084-
{
1085-
Some(idx)
1086-
}
1087-
EncryptedMessage::MegolmV1AesSha2 { .. }
1088-
| EncryptedMessage::OlmV1Curve25519AesSha2 { .. }
1089-
| EncryptedMessage::Unknown => None,
1090-
})
1091-
.collect();
1075+
let retry_indices = event_indices_to_retry_decryption(&state, &should_retry);
10921076

10931077
if retry_indices.is_empty() {
10941078
return;
@@ -1433,6 +1417,26 @@ impl<P: RoomDataProvider> TimelineController<P> {
14331417
}
14341418
}
14351419

1420+
fn event_indices_to_retry_decryption(
1421+
state: &tokio::sync::OwnedRwLockWriteGuard<TimelineState>,
1422+
should_retry: impl Fn(&str) -> bool,
1423+
) -> Vec<usize> {
1424+
let retry_indices: Vec<_> = state
1425+
.items
1426+
.iter()
1427+
.enumerate()
1428+
.filter_map(|(idx, item)| match item.as_event()?.content().as_unable_to_decrypt()? {
1429+
EncryptedMessage::MegolmV1AesSha2 { session_id, .. } if should_retry(session_id) => {
1430+
Some(idx)
1431+
}
1432+
EncryptedMessage::MegolmV1AesSha2 { .. }
1433+
| EncryptedMessage::OlmV1Curve25519AesSha2 { .. }
1434+
| EncryptedMessage::Unknown => None,
1435+
})
1436+
.collect();
1437+
retry_indices
1438+
}
1439+
14361440
impl TimelineController {
14371441
pub(super) fn room(&self) -> &Room {
14381442
&self.room_data_provider

0 commit comments

Comments
 (0)