Skip to content

Commit ef798cd

Browse files
authored
fix: Allow to send to chats after failed securejoin again (#6817)
Revert the biggest part of #6722 in order to fix #6816. Reopens #6706. Rationale for reverting instead of fixing is that it's not trivial to implement "if the chat is encrypted, can_send() returns true": When sending a message, in order to check whether to encrypt, we load all peerstates and check whether all of them can be encrypted to (`should_encrypt()`). We could do this in `can_send()`, but this would make it quite slow for groups. With multi-transport, the ways of checking whether to encrypt will be different, so in order not to do unnecessary work now, this PR just revert parts of [https://github.com/chatmail/core/pull/6722/](https://github.com/chatmail/core/pull/6817#), so that we can make things work nicely when multi-transport is merged. As a quick mitigation, we could increase the timeout from 15s to something like 1 minute or 1 day: Long enough that usually securejoin will finish before, but short enough that it's possible to send to old chats that had a failed securejoin long in the past.
1 parent 9d3450f commit ef798cd

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/chat.rs

+17-20
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

+2-2
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

0 commit comments

Comments
 (0)