Commit 44bc8680c1

44bc8680c1104443720bf6d6dec94c37cbed6ef4

parent: 55ad2d3402

Unregistered key

vaw <git@nlih.de> · 2026-11-11 15:17 UTC
committer: <noreply@github.com>

Implement redecryption of encrypted events (#855)

Layout: unified · split

src/main.rs +15
@@ -968,6 +968,7 @@ impl Application {
968968
969969 let store = self.store.clone();
970970
971 tracing::info!("starting main loop");
971972 while self.screen.tabs() != 0 {
972973 let key = self.step().await?;
973974
@@ -1105,6 +1106,14 @@ async fn login_normal(
11051106 println!("* Logging in for {}...", settings.user_id);
11061107 login(worker, settings).await?;
11071108 println!("* Syncing...");
1109
1110 // Only subscribe after the encryption session has been restored.
1111 worker
1112 .client
1113 .event_cache()
1114 .subscribe()
1115 .expect("Failed to start event cache");
1116
11081117 worker.spawn_sync()?;
11091118 worker.setup_persistent_tokens();
11101119 worker::do_first_sync(&worker.client, store)
@@ -1123,10 +1132,12 @@ async fn run(
11231132 settings.probe_enhanced_keys();
11241133
11251134 // Set up client state.
1135 tracing::info!("setting up client");
11261136 create_dir_all(settings.sqlite_dir.as_path())?;
11271137 let client = worker::create_client(&settings).await;
11281138
11291139 // Set up the async worker thread and global store.
1140 tracing::debug!("setting up worker");
11301141 let worker = ClientWorker::spawn(client.clone(), settings.clone()).await;
11311142 let store = ChatStore::new(worker.clone(), settings.clone())?;
11321143 let mut store = Store::new(store);
@@ -1137,9 +1148,11 @@ async fn run(
11371148 store.registers.set_default_register(r.clone());
11381149 }
11391150
1151 tracing::debug!("initializing worker");
11401152 let store = Arc::new(AsyncMutex::new(store));
11411153 worker.init(store.clone());
11421154
1155 tracing::info!("logging in");
11431156 let res = login_normal(&worker, &settings, &store).await;
11441157
11451158 match res {
@@ -1157,6 +1170,7 @@ async fn run(
11571170 Ok(()) => (),
11581171 }
11591172
1173 tracing::debug!("setting up tty");
11601174 // Set up the terminal for drawing, and cleanup properly on panics.
11611175 setup_tty(&settings)?;
11621176
@@ -1170,6 +1184,7 @@ async fn run(
11701184 }));
11711185
11721186 // And finally, start running the terminal UI.
1187 tracing::debug!("creating application");
11731188 let mut application = Application::new(settings, store, initial_room)
11741189 .await
11751190 .inspect_err(|_| restore_tty(enable_enhanced_keys, enable_mouse))?;
src/worker.rs +21 −3
@@ -3,6 +3,7 @@
33//! The worker thread handles asynchronous work, and can receive messages from the main thread that
44//! block on a reply from the async worker.
55
6use std::collections::BTreeSet;
67use std::fmt::{Debug, Formatter};
78use std::sync::mpsc::{Receiver, SyncSender, sync_channel};
89
@@ -15,6 +16,7 @@ use matrix_sdk::config::{RequestConfig, SyncSettings};
1516use matrix_sdk::deserialized_responses::RawSyncOrStrippedState;
1617use matrix_sdk::deserialized_responses::{TimelineEvent, TimelineEventKind};
1718use matrix_sdk::encryption::{BackupDownloadStrategy, EncryptionSettings};
19use matrix_sdk::event_cache::DecryptionRetryRequest;
1820use matrix_sdk::event_handler::Ctx;
1921use matrix_sdk::notification_settings::RoomNotificationMode;
2022use matrix_sdk::room::RoomMember;
@@ -382,6 +384,7 @@ async fn get_receipts_for_timeline_events(
382384 events: Vec<TimelineEvent>,
383385) -> Vec<MessageAndReceipts> {
384386 let mut msgs = vec![];
387 let mut redecryption_requests = BTreeSet::new();
385388
386389 for ev in events.into_iter() {
387390 let event_id = ev.event_id().map(ToOwned::to_owned);
@@ -401,9 +404,13 @@ async fn get_receipts_for_timeline_events(
401404 }
402405 },
403406 TimelineEventKind::UnableToDecrypt { event, utd_info, .. } => {
407 if let Some(session_id) = &utd_info.session_id {
408 redecryption_requests.insert(session_id.to_string());
409 }
410
404411 let event = match event.deserialize() {
405412 Ok(event) => {
406 tracing::debug!(
413 tracing::trace!(
407414 ?utd_info,
408415 room_id = room.room_id().as_str(),
409416 ?event_id,
@@ -458,6 +465,19 @@ async fn get_receipts_for_timeline_events(
458465 msgs.push((msg, thread, receipts));
459466 }
460467
468 if !redecryption_requests.is_empty() {
469 tracing::debug!(
470 room_id = room.room_id().as_str(),
471 "Requesting redecryption of {} events",
472 redecryption_requests.len()
473 );
474 room.client().event_cache().request_decryption(DecryptionRetryRequest {
475 room_id: room.room_id().to_owned(),
476 utd_session_ids: redecryption_requests,
477 refresh_info_session_ids: Default::default(),
478 });
479 }
480
461481 msgs
462482}
463483
@@ -1371,8 +1391,6 @@ pub async fn create_client(settings: &ApplicationSettings) -> Client {
13711391
13721392 let client = res.expect("Failed to instantiate client");
13731393
1374 client.event_cache().subscribe().expect("Failed to start event cache");
1375
13761394 client
13771395 .media()
13781396 .set_media_retention_policy(settings.tunables.cache_policy)