mirror of
https://github.com/chatmail/core.git
synced 2026-05-12 19:36:32 +03:00
fix: Make syncing of QR tokens work, make test_sync_broadcast pass
This commit is contained in:
@@ -3846,8 +3846,13 @@ async fn test_sync_broadcast() -> Result<()> {
|
|||||||
assert_eq!(a1_broadcast_chat.get_type(), Chattype::OutBroadcast);
|
assert_eq!(a1_broadcast_chat.get_type(), Chattype::OutBroadcast);
|
||||||
assert_eq!(a1_broadcast_chat.get_name(), a0_broadcast_chat.get_name());
|
assert_eq!(a1_broadcast_chat.get_name(), a0_broadcast_chat.get_name());
|
||||||
assert!(get_chat_contacts(alice1, a1_broadcast_id).await?.is_empty());
|
assert!(get_chat_contacts(alice1, a1_broadcast_id).await?.is_empty());
|
||||||
add_contact_to_chat(alice0, a0_broadcast_id, a0b_contact_id).await?;
|
|
||||||
sync(alice0, alice1).await;
|
let qr = get_securejoin_qr(alice0, Some(a0_broadcast_id))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
sync(alice0, alice1).await; // Sync QR code
|
||||||
|
tcm.exec_securejoin_qr_multi_device(bob, &[alice0, alice1], &qr)
|
||||||
|
.await;
|
||||||
|
|
||||||
// This also imports Bob's key from the vCard.
|
// This also imports Bob's key from the vCard.
|
||||||
// Otherwise it is possible that second device
|
// Otherwise it is possible that second device
|
||||||
|
|||||||
@@ -99,6 +99,13 @@ pub async fn get_securejoin_qr(context: &Context, chat: Option<ChatId>) -> Resul
|
|||||||
utf8_percent_encode(&self_name, NON_ALPHANUMERIC_WITHOUT_DOT).to_string();
|
utf8_percent_encode(&self_name, NON_ALPHANUMERIC_WITHOUT_DOT).to_string();
|
||||||
|
|
||||||
let qr = if let Some(chat) = chat {
|
let qr = if let Some(chat) = chat {
|
||||||
|
if sync_token {
|
||||||
|
context
|
||||||
|
.sync_qr_code_tokens(Some(chat.grpid.as_str()))
|
||||||
|
.await?;
|
||||||
|
context.scheduler.interrupt_inbox().await;
|
||||||
|
}
|
||||||
|
|
||||||
if chat.typ == Chattype::OutBroadcast {
|
if chat.typ == Chattype::OutBroadcast {
|
||||||
let broadcast_name = chat.get_name();
|
let broadcast_name = chat.get_name();
|
||||||
let broadcast_name_urlencoded =
|
let broadcast_name_urlencoded =
|
||||||
@@ -106,7 +113,6 @@ pub async fn get_securejoin_qr(context: &Context, chat: Option<ChatId>) -> Resul
|
|||||||
let broadcast_secret = load_broadcast_shared_secret(context, chat.id)
|
let broadcast_secret = load_broadcast_shared_secret(context, chat.id)
|
||||||
.await?
|
.await?
|
||||||
.context("Could not find broadcast secret")?;
|
.context("Could not find broadcast secret")?;
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"https://i.delta.chat/#{}&a={}&g={}&x={}&s={}&b={}",
|
"https://i.delta.chat/#{}&a={}&g={}&x={}&s={}&b={}",
|
||||||
fingerprint.hex(),
|
fingerprint.hex(),
|
||||||
@@ -121,12 +127,6 @@ pub async fn get_securejoin_qr(context: &Context, chat: Option<ChatId>) -> Resul
|
|||||||
let group_name = chat.get_name();
|
let group_name = chat.get_name();
|
||||||
let group_name_urlencoded =
|
let group_name_urlencoded =
|
||||||
utf8_percent_encode(group_name, NON_ALPHANUMERIC).to_string();
|
utf8_percent_encode(group_name, NON_ALPHANUMERIC).to_string();
|
||||||
if sync_token {
|
|
||||||
context
|
|
||||||
.sync_qr_code_tokens(Some(chat.grpid.as_str()))
|
|
||||||
.await?;
|
|
||||||
context.scheduler.interrupt_inbox().await;
|
|
||||||
}
|
|
||||||
format!(
|
format!(
|
||||||
"https://i.delta.chat/#{}&a={}&g={}&x={}&i={}&s={}",
|
"https://i.delta.chat/#{}&a={}&g={}&x={}&i={}&s={}",
|
||||||
fingerprint.hex(),
|
fingerprint.hex(),
|
||||||
|
|||||||
@@ -228,18 +228,42 @@ impl TestContextManager {
|
|||||||
/// chat with `scanned`, for a SecureJoin QR this is the group chat.
|
/// chat with `scanned`, for a SecureJoin QR this is the group chat.
|
||||||
pub async fn exec_securejoin_qr(
|
pub async fn exec_securejoin_qr(
|
||||||
&self,
|
&self,
|
||||||
scanner: &TestContext,
|
joiner: &TestContext,
|
||||||
inviter: &TestContext,
|
inviter: &TestContext,
|
||||||
qr: &str,
|
qr: &str,
|
||||||
) -> ChatId {
|
) -> ChatId {
|
||||||
let chat_id = join_securejoin(&scanner.ctx, qr).await.unwrap();
|
self.exec_securejoin_qr_multi_device(joiner, &[inviter], qr)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Executes SecureJoin initiated by `scanner` scanning `qr` generated by `scanned`.
|
||||||
|
///
|
||||||
|
/// The [`ChatId`] of the created chat is returned, for a SetupContact QR this is the 1:1
|
||||||
|
/// chat with `scanned`, for a SecureJoin QR this is the group chat.
|
||||||
|
pub async fn exec_securejoin_qr_multi_device(
|
||||||
|
&self,
|
||||||
|
joiner: &TestContext,
|
||||||
|
inviters: &[&TestContext],
|
||||||
|
qr: &str,
|
||||||
|
) -> ChatId {
|
||||||
|
let chat_id = join_securejoin(&joiner.ctx, qr).await.unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(sent) = scanner.pop_sent_msg_opt(Duration::ZERO).await {
|
let mut something_sent = false;
|
||||||
inviter.recv_msg_opt(&sent).await;
|
if let Some(sent) = joiner.pop_sent_msg_opt(Duration::ZERO).await {
|
||||||
} else if let Some(sent) = inviter.pop_sent_msg_opt(Duration::ZERO).await {
|
for inviter in inviters {
|
||||||
scanner.recv_msg_opt(&sent).await;
|
inviter.recv_msg_opt(&sent).await;
|
||||||
} else {
|
}
|
||||||
|
something_sent = true;
|
||||||
|
}
|
||||||
|
for inviter in inviters {
|
||||||
|
if let Some(sent) = inviter.pop_sent_msg_opt(Duration::ZERO).await {
|
||||||
|
joiner.recv_msg_opt(&sent).await;
|
||||||
|
something_sent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !something_sent {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user