From d447342cbd6f2d5d96853cc15f16122d3be93f50 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Mon, 24 Feb 2025 16:13:56 +0000 Subject: [PATCH] refactor(timeline): Split finding retry indices into its own function --- .../controller/decryption_retry_task.rs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/controller/decryption_retry_task.rs b/crates/matrix-sdk-ui/src/timeline/controller/decryption_retry_task.rs index b50242da7..9b1e8fc20 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/decryption_retry_task.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/decryption_retry_task.rs @@ -47,6 +47,15 @@ impl DecryptionRetryTask

{ decryptor: impl Decryptor, session_ids: Option>, ) { + let retry_indices = self.retry_indices(&session_ids).await; + + if !retry_indices.is_empty() { + debug!("Retrying decryption"); + self.decrypt_by_index(decryptor, session_ids, retry_indices).await; + } + } + + async fn retry_indices(&self, session_ids: &Option>) -> Vec { let state = self.state.clone().read_owned().await; let should_retry = |session_id: &str| { @@ -57,7 +66,7 @@ impl DecryptionRetryTask

{ } }; - let retry_indices: Vec<_> = state + state .items .iter() .enumerate() @@ -71,17 +80,7 @@ impl DecryptionRetryTask

{ | EncryptedMessage::OlmV1Curve25519AesSha2 { .. } | EncryptedMessage::Unknown => None, }) - .collect(); - - if retry_indices.is_empty() { - return; - } - - drop(state); - - debug!("Retrying decryption"); - - self.decrypt_by_index(decryptor, session_ids, retry_indices).await; + .collect() } async fn decrypt_by_index(