diff --git a/src/chat.rs b/src/chat.rs index 5764b9ab0..ce34ceef0 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -266,7 +266,7 @@ impl ChatId { /// Updates chat blocked status. /// /// Returns true if the value was modified. - async fn set_blocked(self, context: &Context, new_blocked: Blocked) -> Result { + pub(crate) async fn set_blocked(self, context: &Context, new_blocked: Blocked) -> Result { if self.is_special() { bail!("ignoring setting of Block-status for {}", self); } diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 4a40771e2..60dfba1f1 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -664,11 +664,12 @@ async fn add_parts( } if let Some(chat_id) = chat_id { - if Blocked::Not != chat_id_blocked { - if Blocked::Not == create_blocked { - chat_id.unblock(context).await?; - chat_id_blocked = Blocked::Not; - } else if parent.is_some() { + if chat_id_blocked != Blocked::Not { + if chat_id_blocked != create_blocked { + chat_id.set_blocked(context, create_blocked).await?; + chat_id_blocked = create_blocked; + } + if create_blocked == Blocked::Request && parent.is_some() { // we do not want any chat to be created implicitly. Because of the origin-scale-up, // the contact requests will pop up and this should be just fine. Contact::scaleup_origin_by_id(context, from_id, Origin::IncomingReplyTo) @@ -806,9 +807,9 @@ async fn add_parts( } if let Some(chat_id) = chat_id { - if Blocked::Not != chat_id_blocked && Blocked::Not == create_blocked { - chat_id.unblock(context).await?; - chat_id_blocked = Blocked::Not; + if chat_id_blocked != Blocked::Not && chat_id_blocked != create_blocked { + chat_id.set_blocked(context, create_blocked).await?; + chat_id_blocked = create_blocked; } } } diff --git a/src/securejoin.rs b/src/securejoin.rs index f8d7049ae..7ae4d27ea 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -499,6 +499,12 @@ pub(crate) async fn handle_securejoin_handshake( inviter_progress!(context, contact_id, 300); + // for setup-contact, make Alice's one-to-one chat with Bob visible + // (secure-join-information are shown in the group chat) + if !join_vg { + ChatId::create_for_contact(context, contact_id).await?; + } + // Alice -> Bob send_alice_handshake_msg( context, @@ -936,6 +942,8 @@ mod tests { async fn test_setup_contact() -> Result<()> { let alice = TestContext::new_alice().await; let bob = TestContext::new_bob().await; + assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 0); + assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 0); // Setup JoinerProgress sinks. let (joiner_progress_tx, joiner_progress_rx) = async_std::channel::bounded(100); @@ -954,6 +962,7 @@ mod tests { // Step 2: Bob scans QR-code, sends vc-request dc_join_securejoin(&bob.ctx, &qr).await?; + assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 1); let sent = bob.pop_sent_msg().await; assert!(!bob.ctx.has_ongoing().await); @@ -965,6 +974,7 @@ mod tests { // Step 3: Alice receives vc-request, sends vc-auth-required alice.recv_msg(&sent).await; + assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 1); let sent = alice.pop_sent_msg().await; let msg = bob.parse_msg(&sent).await; @@ -1041,6 +1051,11 @@ mod tests { VerifiedStatus::BidirectVerified ); + // exactly one one-to-one chat should be visible for both now + // (check this before calling alice.create_chat() explicitly below) + assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 1); + assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 1); + // Check Alice got the verified message in her 1:1 chat. { let chat = alice.create_chat(&bob).await; @@ -1302,6 +1317,8 @@ mod tests { async fn test_secure_join() -> Result<()> { let alice = TestContext::new_alice().await; let bob = TestContext::new_bob().await; + assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 0); + assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 0); // Setup JoinerProgress sinks. let (joiner_progress_tx, joiner_progress_rx) = async_std::channel::bounded(100); @@ -1323,12 +1340,9 @@ mod tests { .await .unwrap(); - // Step 2: Bob scans QR-code, sends vg-request; blocks on ongoing process - let joiner = { - let qr = qr.clone(); - let ctx = bob.ctx.clone(); - async_std::task::spawn(async move { dc_join_securejoin(&ctx, &qr).await.unwrap() }) - }; + // Step 2: Bob scans QR-code, sends vg-request + let bob_chatid = dc_join_securejoin(&bob.ctx, &qr).await?; + assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 1); let sent = bob.pop_sent_msg().await; assert_eq!(sent.recipient(), "alice@example.com".parse().unwrap()); @@ -1444,9 +1458,9 @@ mod tests { "vg-member-added-received" ); - let bob_chatid = joiner.await; let bob_chat = Chat::load_from_db(&bob.ctx, bob_chatid).await?; assert!(bob_chat.is_protected()); + assert!(bob_chat.typ == Chattype::Group); assert!(!bob.ctx.has_ongoing().await); // On this "happy path", Alice and Bob get only a group-chat where all information are added to. @@ -1454,6 +1468,14 @@ mod tests { // however, should not be visible in the UIs. assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 1); assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 1); + + // If Bob then sends a direct message to alice, however, the one-to-one with Alice should appear. + let bobs_chat_with_alice = bob.create_chat(&alice).await; + let sent = bob.send_text(bobs_chat_with_alice.id, "Hello").await; + alice.recv_msg(&sent).await; + assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 2); + assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 2); + Ok(()) } }