From 92460c16e3625890b520ac66e1868ed6bf225cc6 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Wed, 23 Apr 2025 16:23:53 +0200 Subject: [PATCH] fix: Allow to send to chats after failed securejoin again --- src/chat.rs | 37 ++++++++++++++---------------- src/securejoin/securejoin_tests.rs | 4 ++-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 40ec59f186..b5d8d5d61d 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1695,13 +1695,13 @@ impl Chat { return Ok(Some(reason)); } let reason = SecurejoinWait; - if !skip_fn(&reason) { - let (can_write, _) = self + if !skip_fn(&reason) + && self .check_securejoin_wait(context, constants::SECUREJOIN_WAIT_TIMEOUT) - .await?; - if !can_write { - return Ok(Some(reason)); - } + .await? + > 0 + { + return Ok(Some(reason)); } Ok(None) } @@ -1713,18 +1713,17 @@ impl Chat { Ok(self.why_cant_send(context).await?.is_none()) } - /// Returns if the chat can be sent to - /// and the remaining timeout for the 1:1 chat in-progress SecureJoin. + /// Returns the remaining timeout for the 1:1 chat in-progress SecureJoin. /// - /// If the timeout has expired, adds an info message with additional information; - /// the chat still cannot be sent to in this case. See also [`CantSendReason::SecurejoinWait`]. + /// If the timeout has expired, adds an info message with additional information. + /// See also [`CantSendReason::SecurejoinWait`]. pub(crate) async fn check_securejoin_wait( &self, context: &Context, timeout: u64, - ) -> Result<(bool, u64)> { + ) -> Result { if self.typ != Chattype::Single || self.protected != ProtectionStatus::Unprotected { - return Ok((true, 0)); + return Ok(0); } // chat is single and unprotected: @@ -1748,11 +1747,10 @@ impl Chat { ) .await? else { - return Ok((true, 0)); + return Ok(0); }; - if param == param_timeout { - return Ok((false, 0)); + return Ok(0); } let now = time(); @@ -1762,10 +1760,9 @@ impl Chat { .saturating_add(timeout.try_into()?) .saturating_sub(now); if timeout > 0 { - return Ok((false, timeout as u64)); + return Ok(timeout as u64); } } - add_info_msg_with_cmd( context, self.id, @@ -1780,8 +1777,8 @@ impl Chat { None, ) .await?; - - Ok((false, 0)) + context.emit_event(EventType::ChatModified(self.id)); + Ok(0) } /// Checks if the user is part of a chat @@ -2584,7 +2581,7 @@ pub(crate) async fn resume_securejoin_wait(context: &Context) -> Result<()> { for chat_id in chat_ids { let chat = Chat::load_from_db(context, chat_id).await?; - let (_, timeout) = chat + let timeout = chat .check_securejoin_wait(context, constants::SECUREJOIN_WAIT_TIMEOUT) .await?; if timeout > 0 { diff --git a/src/securejoin/securejoin_tests.rs b/src/securejoin/securejoin_tests.rs index 3fb997e2c1..663341fe16 100644 --- a/src/securejoin/securejoin_tests.rs +++ b/src/securejoin/securejoin_tests.rs @@ -149,7 +149,7 @@ async fn test_setup_contact_ex(case: SetupContactCase) { ); if case == SetupContactCase::SecurejoinWaitTimeout { SystemTime::shift(Duration::from_secs(constants::SECUREJOIN_WAIT_TIMEOUT)); - assert_eq!(bob_chat.can_send(&bob).await.unwrap(), false); + assert_eq!(bob_chat.can_send(&bob).await.unwrap(), true); } // Step 4: Bob receives vc-auth-required, sends vc-request-with-auth @@ -318,7 +318,7 @@ async fn test_setup_contact_ex(case: SetupContactCase) { .check_securejoin_wait(&bob, constants::SECUREJOIN_WAIT_TIMEOUT) .await .unwrap(), - (true, 0) + 0 ); }