Skip to content

Commit 927c82f

Browse files
committed
refactor(timeilne): Add a method to compute redecryption candidates
1 parent 4fbc83a commit 927c82f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,40 @@ impl Drop for CryptoDropHandles {
6969
}
7070
}
7171

72+
/// Decide which events should be retried, either for re-decryption, or, if they
73+
/// are already decrypted, for re-checking their encryption info.
74+
///
75+
/// Returns two sets of session IDs, one for the UTDs and one for the events
76+
/// that have an encryption info that might need to be updated.
77+
pub(super) fn compute_redecryption_candidates(
78+
timeline_items: &Vector<Arc<TimelineItem>>,
79+
) -> (BTreeSet<String>, BTreeSet<String>) {
80+
timeline_items
81+
.iter()
82+
.filter_map(|event| {
83+
event.as_event().and_then(|e| {
84+
let session_id = e.encryption_info().and_then(|info| info.session_id());
85+
86+
let session_id = if let Some(session_id) = session_id {
87+
Some(session_id)
88+
} else {
89+
event.as_event().and_then(|e| {
90+
e.content.as_unable_to_decrypt().and_then(|utd| utd.session_id())
91+
})
92+
};
93+
94+
session_id.map(|id| id.to_owned()).zip(Some(e))
95+
})
96+
})
97+
.partition_map(|(session_id, event)| {
98+
if event.content.is_unable_to_decrypt() {
99+
Either::Left(session_id)
100+
} else {
101+
Either::Right(session_id)
102+
}
103+
})
104+
}
105+
72106
/// The task that handles the room keys from backups.
73107
async fn room_keys_from_backups_task<S>(stream: S, timeline_controller: TimelineController)
74108
where

0 commit comments

Comments
 (0)