Skip to content

Commit ff1dde9

Browse files
committed
refactor(timeline): Extract a function for retrying decryption
Future commits will add code to try non-UTDs too, in another function.
1 parent dca6881 commit ff1dde9

File tree

1 file changed

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

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,10 @@ impl<P: RoomDataProvider> TimelineController<P> {
10621062
decryptor: impl Decryptor,
10631063
session_ids: Option<BTreeSet<String>>,
10641064
) {
1065-
let mut state = self.state.clone().write_owned().await;
1065+
let state = self.state.clone().write_owned().await;
10661066

1067+
// We should retry an event if its session is included in the list, or the list
1068+
// is None.
10671069
let should_retry = move |session_id: &str| {
10681070
if let Some(session_ids) = &session_ids {
10691071
session_ids.contains(session_id)
@@ -1072,8 +1074,27 @@ impl<P: RoomDataProvider> TimelineController<P> {
10721074
}
10731075
};
10741076

1077+
// Find which messages need retrying
10751078
let retry_indices = event_indices_to_retry_decryption(&state, &should_retry);
10761079

1080+
// Retry decrypting
1081+
self.retry_event_decryption_by_index(state, retry_indices, should_retry, decryptor).await;
1082+
}
1083+
1084+
/// Retry decryption of the supplied events, which are expected to be UTDs.
1085+
///
1086+
/// `state` is the [`TimelineState`] state of the timeline.
1087+
/// `retry_indices` contains the indices of events to try within the
1088+
/// `state.items` `should_retry` checks that a session is included in
1089+
/// the list of updated sessions. `decryptor` does the actual work of
1090+
/// decrypting events.
1091+
async fn retry_event_decryption_by_index(
1092+
&self,
1093+
mut state: tokio::sync::OwnedRwLockWriteGuard<TimelineState>,
1094+
retry_indices: Vec<usize>,
1095+
should_retry: impl Fn(&str) -> bool + Send + Sync + 'static,
1096+
decryptor: impl Decryptor,
1097+
) {
10771098
if retry_indices.is_empty() {
10781099
return;
10791100
}

0 commit comments

Comments
 (0)