Skip to content

Commit 4e71b7c

Browse files
committed
feat(ui): Create a task to listen to redecryptor reports in the timeline
This task is still necessary because the redecryptor in the event cache might miss some room keys. In this case the timeline can tell the redecryptor which events it should retry to decrypt. We're collecting all the UTDs in the timeline and telling the redecryptor to do its best.
1 parent e042776 commit 4e71b7c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use matrix_sdk::{
2525
Client, Room,
2626
deserialized_responses::TimelineEventKind as SdkTimelineEventKind,
2727
encryption::backups::BackupState,
28+
event_cache::{self, RedecryptorReport},
2829
event_handler::EventHandlerHandle,
2930
executor::{JoinHandle, spawn},
3031
};
@@ -103,6 +104,32 @@ pub(super) fn compute_redecryption_candidates(
103104
})
104105
}
105106

107+
async fn redecryption_report_task(timeline_controller: TimelineController) {
108+
let client = timeline_controller.room().client();
109+
let stream = client.event_cache().subscribe_to_decryption_reports();
110+
111+
pin_mut!(stream);
112+
113+
while let Some(report) = stream.next().await {
114+
match report {
115+
Ok(RedecryptorReport::ResolvedUtds { events, .. }) => {
116+
let state = timeline_controller.state.read().await;
117+
118+
if let Some(utd_hook) = &state.meta.unable_to_decrypt_hook {
119+
for event_id in events {
120+
utd_hook.on_late_decrypt(&event_id).await;
121+
}
122+
}
123+
}
124+
Ok(RedecryptorReport::Lagging) | Err(_) => {
125+
// The room key stream lagged or the OlmMachine got regenerated. Let's tell the
126+
// redecryptor to attempt redecryption of our timeline items.
127+
timeline_controller.retry_event_decryption(None).await;
128+
}
129+
}
130+
}
131+
}
132+
106133
/// The task that handles the room keys from backups.
107134
async fn room_keys_from_backups_task<S>(stream: S, timeline_controller: TimelineController)
108135
where

0 commit comments

Comments
 (0)