mirror of
https://github.com/chatmail/core.git
synced 2026-04-02 05:22:14 +03:00
feat: do not run SecureJoin if we are already in the group
This commit is contained in:
@@ -65,7 +65,21 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul
|
||||
)
|
||||
.await?;
|
||||
|
||||
if has_key
|
||||
// Chat ID of the group we are joining, unused otherwise.
|
||||
let group_chat_id = joining_chat_id(context, &invite, chat_id).await?;
|
||||
if matches!(invite, QrInvite::Group { .. })
|
||||
&& is_contact_in_chat(context, group_chat_id, ContactId::SELF).await?
|
||||
{
|
||||
// If QR code is a group invite
|
||||
// and we are already in the chat,
|
||||
// nothing needs to be done.
|
||||
// Even if Alice is not verified, we don't send anything.
|
||||
context.emit_event(EventType::SecurejoinJoinerProgress {
|
||||
contact_id: invite.contact_id(),
|
||||
progress: JoinerProgress::Succeeded.to_usize(),
|
||||
});
|
||||
return Ok(group_chat_id);
|
||||
} else if has_key
|
||||
&& verify_sender_by_fingerprint(context, invite.fingerprint(), invite.contact_id())
|
||||
.await?
|
||||
{
|
||||
|
||||
@@ -959,3 +959,46 @@ async fn test_expired_synced_auth_token() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Tests that attempting to join already joined group does nothing.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_rejoin_group() -> Result<()> {
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = &tcm.alice().await;
|
||||
let bob = &tcm.bob().await;
|
||||
|
||||
let alice_chat_id = chat::create_group(alice, "the chat").await?;
|
||||
|
||||
let qr = get_securejoin_qr(alice, Some(alice_chat_id)).await?;
|
||||
tcm.exec_securejoin_qr(bob, alice, &qr).await;
|
||||
|
||||
// Bob gets two progress events.
|
||||
for expected_progress in [400, 1000] {
|
||||
let EventType::SecurejoinJoinerProgress { progress, .. } = bob
|
||||
.evtracker
|
||||
.get_matching(|evt| matches!(evt, EventType::SecurejoinJoinerProgress { .. }))
|
||||
.await
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
assert_eq!(progress, expected_progress);
|
||||
}
|
||||
|
||||
// Bob scans the QR code again.
|
||||
join_securejoin(bob, &qr).await?;
|
||||
|
||||
// Bob immediately receives progress 1000 event.
|
||||
let EventType::SecurejoinJoinerProgress { progress, .. } = bob
|
||||
.evtracker
|
||||
.get_matching(|evt| matches!(evt, EventType::SecurejoinJoinerProgress { .. }))
|
||||
.await
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
assert_eq!(progress, 1000);
|
||||
|
||||
// Bob does not send any more messages by scanning the QR code.
|
||||
assert!(bob.pop_sent_msg_opt(Duration::ZERO).await.is_none());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ Msg#6004: info (Contact#Contact#Info): alice@example.org invited you to join thi
|
||||
|
||||
Waiting for the device of alice@example.org to reply… [NOTICED][INFO]
|
||||
Msg#6006: info (Contact#Contact#Info): alice@example.org replied, waiting for being added to the group… [NOTICED][INFO]
|
||||
Msg#6003: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
|
||||
Msg#6002: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
|
||||
Msg#6008🔒: (Contact#Contact#6001): Member Me added by alice@example.org. [FRESH][INFO]
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@@ -4,7 +4,7 @@ Msg#3004: info (Contact#Contact#Info): alice@example.org invited you to join thi
|
||||
|
||||
Waiting for the device of alice@example.org to reply… [NOTICED][INFO]
|
||||
Msg#3006: info (Contact#Contact#Info): alice@example.org replied, waiting for being added to the group… [NOTICED][INFO]
|
||||
Msg#3003: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
|
||||
Msg#3002: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
|
||||
Msg#3008🔒: (Contact#Contact#3002): [FRESH]
|
||||
Msg#3009: info (Contact#Contact#Info): Member bob@example.net added. [NOTICED][INFO]
|
||||
Msg#3010🔒: (Contact#Contact#3001): Member Me added by alice@example.org. [FRESH][INFO]
|
||||
|
||||
Reference in New Issue
Block a user