Skip to content

fix: Allow to send to chats after failed securejoin again #6817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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<u64> {
if self.typ != Chattype::Single || self.protected != ProtectionStatus::Unprotected {
return Ok((true, 0));
return Ok(0);
}

// chat is single and unprotected:
Expand All @@ -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();
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/securejoin/securejoin_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}

Expand Down
Loading