diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index 0ca45abbf..c94e4a904 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -1679,6 +1679,36 @@ def test_qr_join_chat(acfactory, lp): ac1._evtracker.wait_securejoin_inviter_progress(1000) +def test_qr_new_group_unblocked(acfactory, lp): + """Regression test for a bug intoduced in core v1.113.0. + ac2 scans a verified group QR code created by ac1. + This results in creation of a blocked 1:1 chat with ac1 on ac2, + but ac1 contact is not blocked on ac2. + Then ac1 creates a group, adds ac2 there and promotes it by sending a message. + ac2 should receive a message and create a contact request for the group. + Due to a bug previously ac2 created a blocked group. + """ + + ac1, ac2 = acfactory.get_online_accounts(2) + ac1_chat = ac1.create_group_chat("Group for joining", verified=True) + qr = ac1_chat.get_join_qr() + ac2.qr_join_chat(qr) + + ac1._evtracker.wait_securejoin_inviter_progress(1000) + + ac1_new_chat = ac1.create_group_chat("Another group") + ac1_new_chat.add_contact(ac2) + ac1_new_chat.send_text("Hello!") + + # Receive "Member added" message. + ac2._evtracker.wait_next_incoming_message() + + # Receive "Hello!" message. + ac2_msg = ac2._evtracker.wait_next_incoming_message() + assert ac2_msg.text == "Hello!" + assert ac2_msg.chat.is_contact_request() + + def test_qr_email_capitalization(acfactory, lp): """Regression test for a bug that resulted in failure to propagate verification via gossip in a verified group diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 755301ae5..2179356d7 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -546,19 +546,30 @@ async fn add_parts( // signals whether the current user is a bot let is_bot = context.get_config_bool(Config::Bot).await?; - let create_blocked = match test_normal_chat { - Some(ChatIdBlocked { - id: _, - blocked: Blocked::Request, - }) if is_bot => Blocked::Not, - Some(ChatIdBlocked { id: _, blocked }) => blocked, - None => { - if is_bot { - Blocked::Not - } else { - Blocked::Request + let create_blocked_default = if is_bot { + Blocked::Not + } else { + Blocked::Request + }; + let create_blocked = if let Some(ChatIdBlocked { id: _, blocked }) = test_normal_chat { + match blocked { + Blocked::Request => create_blocked_default, + Blocked::Not => Blocked::Not, + Blocked::Yes => { + if Contact::is_blocked_load(context, from_id).await? { + // User has blocked the contact. + // Block the group contact created as well. + Blocked::Yes + } else { + // 1:1 chat is blocked, but the contact is not. + // This happens when 1:1 chat is hidden + // during scanning of a group invitation code. + Blocked::Request + } } } + } else { + create_blocked_default }; if chat_id.is_none() {