From 842d32d41b50dda6fd62ee4c8d12e73a9702d18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 16 Jan 2025 16:29:08 +0100 Subject: [PATCH] refactor(ui): Prettify the two sync tasks a bit --- crates/matrix-sdk-ui/src/sync_service.rs | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/matrix-sdk-ui/src/sync_service.rs b/crates/matrix-sdk-ui/src/sync_service.rs index e2daf5cf2..6ff148ea3 100644 --- a/crates/matrix-sdk-ui/src/sync_service.rs +++ b/crates/matrix-sdk-ui/src/sync_service.rs @@ -183,33 +183,38 @@ impl SyncTaskSupervisor { (room_list_task, encryption_sync_task) } + fn check_if_expired(err: &matrix_sdk::Error) -> bool { + err.client_api_error_kind() == Some(&ruma::api::client::error::ErrorKind::UnknownPos) + } + async fn encryption_sync_task( encryption_sync: Arc, sender: Sender, sync_permit_guard: OwnedMutexGuard, ) { + use encryption_sync_service::Error; + let encryption_sync_stream = encryption_sync.sync(sync_permit_guard); pin_mut!(encryption_sync_stream); let (is_error, has_expired) = loop { - let res = encryption_sync_stream.next().await; - match res { + match encryption_sync_stream.next().await { Some(Ok(())) => { // Carry on. } Some(Err(err)) => { // If the encryption sync error was an expired session, also expire the // room list sync. - let has_expired = if let encryption_sync_service::Error::SlidingSync(err) = &err - { - err.client_api_error_kind() - == Some(&ruma::api::client::error::ErrorKind::UnknownPos) + let has_expired = if let Error::SlidingSync(err) = &err { + Self::check_if_expired(err) } else { false }; + if !has_expired { error!("Error while processing encryption in sync service: {err:#}"); } + break (true, has_expired); } None => { @@ -235,27 +240,29 @@ impl SyncTaskSupervisor { room_list_service: Arc, sender: Sender, ) { + use room_list_service::Error; + let room_list_stream = room_list_service.sync(); pin_mut!(room_list_stream); let (is_error, has_expired) = loop { - let res = room_list_stream.next().await; - match res { + match room_list_stream.next().await { Some(Ok(())) => { // Carry on. } Some(Err(err)) => { // If the room list error was an expired session, also expire the // encryption sync. - let has_expired = if let room_list_service::Error::SlidingSync(err) = &err { - err.client_api_error_kind() - == Some(&ruma::api::client::error::ErrorKind::UnknownPos) + let has_expired = if let Error::SlidingSync(err) = &err { + Self::check_if_expired(err) } else { false }; + if !has_expired { error!("Error while processing room list in sync service: {err:#}"); } + break (true, has_expired); } None => {