Skip to content

Commit 555fe6b

Browse files
committed
fix: Allow to send to chats after failed securejoin again
1 parent 1db9b77 commit 555fe6b

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/chat.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,13 +1695,13 @@ impl Chat {
16951695
return Ok(Some(reason));
16961696
}
16971697
let reason = SecurejoinWait;
1698-
if !skip_fn(&reason) {
1699-
let (can_write, _) = self
1698+
if !skip_fn(&reason)
1699+
&& self
17001700
.check_securejoin_wait(context, constants::SECUREJOIN_WAIT_TIMEOUT)
1701-
.await?;
1702-
if !can_write {
1703-
return Ok(Some(reason));
1704-
}
1701+
.await?
1702+
> 0
1703+
{
1704+
return Ok(Some(reason));
17051705
}
17061706
Ok(None)
17071707
}
@@ -1713,18 +1713,17 @@ impl Chat {
17131713
Ok(self.why_cant_send(context).await?.is_none())
17141714
}
17151715

1716-
/// Returns if the chat can be sent to
1717-
/// and the remaining timeout for the 1:1 chat in-progress SecureJoin.
1716+
/// Returns the remaining timeout for the 1:1 chat in-progress SecureJoin.
17181717
///
1719-
/// If the timeout has expired, adds an info message with additional information;
1720-
/// the chat still cannot be sent to in this case. See also [`CantSendReason::SecurejoinWait`].
1718+
/// If the timeout has expired, adds an info message with additional information.
1719+
/// See also [`CantSendReason::SecurejoinWait`].
17211720
pub(crate) async fn check_securejoin_wait(
17221721
&self,
17231722
context: &Context,
17241723
timeout: u64,
1725-
) -> Result<(bool, u64)> {
1724+
) -> Result<u64> {
17261725
if self.typ != Chattype::Single || self.protected != ProtectionStatus::Unprotected {
1727-
return Ok((true, 0));
1726+
return Ok(0);
17281727
}
17291728

17301729
// chat is single and unprotected:
@@ -1748,11 +1747,10 @@ impl Chat {
17481747
)
17491748
.await?
17501749
else {
1751-
return Ok((true, 0));
1750+
return Ok(0);
17521751
};
1753-
17541752
if param == param_timeout {
1755-
return Ok((false, 0));
1753+
return Ok(0);
17561754
}
17571755

17581756
let now = time();
@@ -1762,10 +1760,9 @@ impl Chat {
17621760
.saturating_add(timeout.try_into()?)
17631761
.saturating_sub(now);
17641762
if timeout > 0 {
1765-
return Ok((false, timeout as u64));
1763+
return Ok(timeout as u64);
17661764
}
17671765
}
1768-
17691766
add_info_msg_with_cmd(
17701767
context,
17711768
self.id,
@@ -1780,8 +1777,8 @@ impl Chat {
17801777
None,
17811778
)
17821779
.await?;
1783-
1784-
Ok((false, 0))
1780+
context.emit_event(EventType::ChatModified(self.id));
1781+
Ok(0)
17851782
}
17861783

17871784
/// Checks if the user is part of a chat
@@ -2584,7 +2581,7 @@ pub(crate) async fn resume_securejoin_wait(context: &Context) -> Result<()> {
25842581

25852582
for chat_id in chat_ids {
25862583
let chat = Chat::load_from_db(context, chat_id).await?;
2587-
let (_, timeout) = chat
2584+
let timeout = chat
25882585
.check_securejoin_wait(context, constants::SECUREJOIN_WAIT_TIMEOUT)
25892586
.await?;
25902587
if timeout > 0 {

src/securejoin/securejoin_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ async fn test_setup_contact_ex(case: SetupContactCase) {
149149
);
150150
if case == SetupContactCase::SecurejoinWaitTimeout {
151151
SystemTime::shift(Duration::from_secs(constants::SECUREJOIN_WAIT_TIMEOUT));
152-
assert_eq!(bob_chat.can_send(&bob).await.unwrap(), false);
152+
assert_eq!(bob_chat.can_send(&bob).await.unwrap(), true);
153153
}
154154

155155
// Step 4: Bob receives vc-auth-required, sends vc-request-with-auth
@@ -318,7 +318,7 @@ async fn test_setup_contact_ex(case: SetupContactCase) {
318318
.check_securejoin_wait(&bob, constants::SECUREJOIN_WAIT_TIMEOUT)
319319
.await
320320
.unwrap(),
321-
(true, 0)
321+
0
322322
);
323323
}
324324

@@ -336,7 +336,7 @@ async fn test_setup_contact_ex(case: SetupContactCase) {
336336
assert!(msg.is_info());
337337
assert_eq!(
338338
msg.get_text(),
339-
stock_str::securejoin_takes_longer(&bob).await
339+
stock_str::securejoin_wait_timeout(&bob).await
340340
);
341341
}
342342
let msg = get_chat_msg(&bob, bob_chat.get_id(), i.next().unwrap(), msg_cnt).await;

0 commit comments

Comments
 (0)