diff --git a/src/chat.rs b/src/chat.rs index 57ab53084..307aa6d12 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -257,7 +257,11 @@ impl ChatId { ChatIdBlocked::get_for_contact(context, contact_id, create_blocked) .await .map(|chat| chat.id)?; - ContactId::scaleup_origin(context, &[contact_id], Origin::CreateChat).await?; + if create_blocked != Blocked::Yes { + info!(context, "Scale up origin of {contact_id} to CreateChat."); + ContactId::scaleup_origin(context, &[contact_id], Origin::CreateChat) + .await?; + } chat_id } else { warn!( diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 7a9a9b780..70914ae8a 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -4835,6 +4835,22 @@ async fn test_sync_create_group() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_broadcast_contacts_are_hidden() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + + let alice_chat_id = create_broadcast(alice, "Channel".to_string()).await?; + let qr = get_securejoin_qr(alice, Some(alice_chat_id)).await?; + tcm.exec_securejoin_qr(bob, alice, &qr).await; + send_text_msg(alice, alice_chat_id, "hello".to_string()).await?; + bob.recv_msg(&alice.pop_sent_msg().await).await; + assert_eq!(Contact::get_all(alice, 0, None).await?.len(), 0); + assert_eq!(Contact::get_all(bob, 0, None).await?.len(), 0); + Ok(()) +} + /// Tests sending JPEG image with .png extension. /// /// This is a regression test, previously sending failed diff --git a/src/mimefactory.rs b/src/mimefactory.rs index a1f7bb0f3..b2090b27c 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -456,9 +456,16 @@ impl MimeFactory { .filter(|id| *id != ContactId::SELF) .collect(); if recipient_ids.len() == 1 - && msg.param.get_cmd() != SystemMessage::MemberRemovedFromGroup - && chat.typ != Chattype::OutBroadcast + && !matches!( + msg.param.get_cmd(), + SystemMessage::MemberRemovedFromGroup | SystemMessage::SecurejoinMessage + ) + && !matches!(chat.typ, Chattype::OutBroadcast | Chattype::InBroadcast) { + info!( + context, + "Scale up origin of {} recipients to OutgoingTo.", chat.id + ); ContactId::scaleup_origin(context, &recipient_ids, Origin::OutgoingTo).await?; } diff --git a/src/securejoin.rs b/src/securejoin.rs index 46e56cf92..8484fbc42 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -641,15 +641,12 @@ pub(crate) async fn handle_securejoin_handshake( mark_contact_id_as_verified(context, contact_id, Some(ContactId::SELF)).await?; } contact_id.regossip_keys(context).await?; - ContactId::scaleup_origin(context, &[contact_id], Origin::SecurejoinInvited).await?; // for setup-contact, make Alice's one-to-one chat with Bob visible // (secure-join-information are shown in the group chat) if grpid.is_empty() { ChatId::create_for_contact(context, contact_id).await?; } - context.emit_event(EventType::ContactsChanged(Some(contact_id))); if let Some(joining_chat_id) = joining_chat_id { - // Join group. chat::add_contact_to_chat_ex(context, Nosync, joining_chat_id, contact_id, true) .await?; @@ -659,6 +656,10 @@ pub(crate) async fn handle_securejoin_handshake( // We don't use the membership consistency algorithm for broadcast channels, // so, sync the memberlist when adding a contact chat.sync_contacts(context).await.log_err(context).ok(); + } else { + ContactId::scaleup_origin(context, &[contact_id], Origin::SecurejoinInvited) + .await?; + context.emit_event(EventType::ContactsChanged(Some(contact_id))); } inviter_progress(context, contact_id, joining_chat_id, chat.typ)?; diff --git a/src/securejoin/bob.rs b/src/securejoin/bob.rs index e676b274a..db26f6ad7 100644 --- a/src/securejoin/bob.rs +++ b/src/securejoin/bob.rs @@ -49,8 +49,14 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul // receive_imf. let private_chat_id = private_chat_id(context, &invite).await?; - ContactId::scaleup_origin(context, &[invite.contact_id()], Origin::SecurejoinJoined).await?; - context.emit_event(EventType::ContactsChanged(None)); + match invite { + QrInvite::Group { .. } | QrInvite::Contact { .. } => { + ContactId::scaleup_origin(context, &[invite.contact_id()], Origin::SecurejoinJoined) + .await?; + context.emit_event(EventType::ContactsChanged(None)); + } + QrInvite::Broadcast { .. } => {} + } let has_key = context .sql