Commit 44bc8680c1
Unregistered key
Layout: unified · split
src/main.rs +15
| @@ -968,6 +968,7 @@ impl Application { | ||
| 968 | 968 | |
| 969 | 969 | let store = self.store.clone(); |
| 970 | 970 | |
| 971 | tracing::info!("starting main loop"); | |
| 971 | 972 | while self.screen.tabs() != 0 { |
| 972 | 973 | let key = self.step().await?; |
| 973 | 974 | |
| @@ -1105,6 +1106,14 @@ async fn login_normal( | ||
| 1105 | 1106 | println!("* Logging in for {}...", settings.user_id); |
| 1106 | 1107 | login(worker, settings).await?; |
| 1107 | 1108 | 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 | ||
| 1108 | 1117 | worker.spawn_sync()?; |
| 1109 | 1118 | worker.setup_persistent_tokens(); |
| 1110 | 1119 | worker::do_first_sync(&worker.client, store) |
| @@ -1123,10 +1132,12 @@ async fn run( | ||
| 1123 | 1132 | settings.probe_enhanced_keys(); |
| 1124 | 1133 | |
| 1125 | 1134 | // Set up client state. |
| 1135 | tracing::info!("setting up client"); | |
| 1126 | 1136 | create_dir_all(settings.sqlite_dir.as_path())?; |
| 1127 | 1137 | let client = worker::create_client(&settings).await; |
| 1128 | 1138 | |
| 1129 | 1139 | // Set up the async worker thread and global store. |
| 1140 | tracing::debug!("setting up worker"); | |
| 1130 | 1141 | let worker = ClientWorker::spawn(client.clone(), settings.clone()).await; |
| 1131 | 1142 | let store = ChatStore::new(worker.clone(), settings.clone())?; |
| 1132 | 1143 | let mut store = Store::new(store); |
| @@ -1137,9 +1148,11 @@ async fn run( | ||
| 1137 | 1148 | store.registers.set_default_register(r.clone()); |
| 1138 | 1149 | } |
| 1139 | 1150 | |
| 1151 | tracing::debug!("initializing worker"); | |
| 1140 | 1152 | let store = Arc::new(AsyncMutex::new(store)); |
| 1141 | 1153 | worker.init(store.clone()); |
| 1142 | 1154 | |
| 1155 | tracing::info!("logging in"); | |
| 1143 | 1156 | let res = login_normal(&worker, &settings, &store).await; |
| 1144 | 1157 | |
| 1145 | 1158 | match res { |
| @@ -1157,6 +1170,7 @@ async fn run( | ||
| 1157 | 1170 | Ok(()) => (), |
| 1158 | 1171 | } |
| 1159 | 1172 | |
| 1173 | tracing::debug!("setting up tty"); | |
| 1160 | 1174 | // Set up the terminal for drawing, and cleanup properly on panics. |
| 1161 | 1175 | setup_tty(&settings)?; |
| 1162 | 1176 | |
| @@ -1170,6 +1184,7 @@ async fn run( | ||
| 1170 | 1184 | })); |
| 1171 | 1185 | |
| 1172 | 1186 | // And finally, start running the terminal UI. |
| 1187 | tracing::debug!("creating application"); | |
| 1173 | 1188 | let mut application = Application::new(settings, store, initial_room) |
| 1174 | 1189 | .await |
| 1175 | 1190 | .inspect_err(|_| restore_tty(enable_enhanced_keys, enable_mouse))?; |
src/worker.rs +21 −3
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | //! The worker thread handles asynchronous work, and can receive messages from the main thread that |
| 4 | 4 | //! block on a reply from the async worker. |
| 5 | 5 | |
| 6 | use std::collections::BTreeSet; | |
| 6 | 7 | use std::fmt::{Debug, Formatter}; |
| 7 | 8 | use std::sync::mpsc::{Receiver, SyncSender, sync_channel}; |
| 8 | 9 | |
| @@ -15,6 +16,7 @@ use matrix_sdk::config::{RequestConfig, SyncSettings}; | ||
| 15 | 16 | use matrix_sdk::deserialized_responses::RawSyncOrStrippedState; |
| 16 | 17 | use matrix_sdk::deserialized_responses::{TimelineEvent, TimelineEventKind}; |
| 17 | 18 | use matrix_sdk::encryption::{BackupDownloadStrategy, EncryptionSettings}; |
| 19 | use matrix_sdk::event_cache::DecryptionRetryRequest; | |
| 18 | 20 | use matrix_sdk::event_handler::Ctx; |
| 19 | 21 | use matrix_sdk::notification_settings::RoomNotificationMode; |
| 20 | 22 | use matrix_sdk::room::RoomMember; |
| @@ -382,6 +384,7 @@ async fn get_receipts_for_timeline_events( | ||
| 382 | 384 | events: Vec<TimelineEvent>, |
| 383 | 385 | ) -> Vec<MessageAndReceipts> { |
| 384 | 386 | let mut msgs = vec![]; |
| 387 | let mut redecryption_requests = BTreeSet::new(); | |
| 385 | 388 | |
| 386 | 389 | for ev in events.into_iter() { |
| 387 | 390 | let event_id = ev.event_id().map(ToOwned::to_owned); |
| @@ -401,9 +404,13 @@ async fn get_receipts_for_timeline_events( | ||
| 401 | 404 | } |
| 402 | 405 | }, |
| 403 | 406 | 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 | ||
| 404 | 411 | let event = match event.deserialize() { |
| 405 | 412 | Ok(event) => { |
| 406 | tracing::debug!( | |
| 413 | tracing::trace!( | |
| 407 | 414 | ?utd_info, |
| 408 | 415 | room_id = room.room_id().as_str(), |
| 409 | 416 | ?event_id, |
| @@ -458,6 +465,19 @@ async fn get_receipts_for_timeline_events( | ||
| 458 | 465 | msgs.push((msg, thread, receipts)); |
| 459 | 466 | } |
| 460 | 467 | |
| 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 | ||
| 461 | 481 | msgs |
| 462 | 482 | } |
| 463 | 483 | |
| @@ -1371,8 +1391,6 @@ pub async fn create_client(settings: &ApplicationSettings) -> Client { | ||
| 1371 | 1391 | |
| 1372 | 1392 | let client = res.expect("Failed to instantiate client"); |
| 1373 | 1393 | |
| 1374 | client.event_cache().subscribe().expect("Failed to start event cache"); | |
| 1375 | ||
| 1376 | 1394 | client |
| 1377 | 1395 | .media() |
| 1378 | 1396 | .set_media_retention_policy(settings.tunables.cache_policy) |