Skip to content

Commit 6a6881b

Browse files
committed
Adapt the rest of the code to the new QR code type
1 parent 4397067 commit 6a6881b

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

src/securejoin/bob.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,24 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul
114114
chat::add_info_msg(context, group_chat_id, &msg, time()).await?;
115115
Ok(group_chat_id)
116116
}
117-
QrInvite::Broadcast { .. } => {}
117+
QrInvite::Broadcast { .. } => {
118+
// For a secure-join we need to create the group and add the contact. The group will
119+
// only become usable once the protocol is finished.
120+
let group_chat_id = joining_chat_id(context, &invite, chat_id).await?;
121+
if !is_contact_in_chat(context, group_chat_id, invite.contact_id()).await? {
122+
chat::add_to_chat_contacts_table(
123+
context,
124+
time(),
125+
group_chat_id,
126+
&[invite.contact_id()],
127+
)
128+
.await?;
129+
}
130+
// TODO this message should be translatable:
131+
let msg = "You were invited to join this channel. Waiting for the channel owner's device to reply…";
132+
chat::add_info_msg(context, group_chat_id, msg, time()).await?;
133+
Ok(group_chat_id)
134+
}
118135
QrInvite::Contact { .. } => {
119136
// For setup-contact the BobState already ensured the 1:1 chat exists because it
120137
// uses it to send the handshake messages.
@@ -206,7 +223,7 @@ pub(super) async fn handle_auth_required(
206223
.await?;
207224

208225
match invite {
209-
QrInvite::Contact { .. } => {}
226+
QrInvite::Contact { .. } | QrInvite::Broadcast { .. } => {}
210227
QrInvite::Group { .. } => {
211228
// The message reads "Alice replied, waiting to be added to the group…",
212229
// so only show it on secure-join and not on setup-contact.
@@ -325,10 +342,14 @@ impl BobHandshakeMsg {
325342
Self::Request => match invite {
326343
QrInvite::Contact { .. } => "vc-request",
327344
QrInvite::Group { .. } => "vg-request",
345+
QrInvite::Broadcast { .. } => "broadcast-request",
328346
},
329347
Self::RequestWithAuth => match invite {
330348
QrInvite::Contact { .. } => "vc-request-with-auth",
331349
QrInvite::Group { .. } => "vg-request-with-auth",
350+
QrInvite::Broadcast { .. } => {
351+
panic!("There is no request-with-auth for broadcasts")
352+
} // TODO remove panic
332353
},
333354
}
334355
}
@@ -348,16 +369,27 @@ async fn joining_chat_id(
348369
) -> Result<ChatId> {
349370
match invite {
350371
QrInvite::Contact { .. } => Ok(alice_chat_id),
351-
QrInvite::Group { grpid, name, .. } => {
352-
let group_chat_id = match chat::get_chat_id_by_grpid(context, grpid).await? {
372+
QrInvite::Group { grpid, name, .. }
373+
| QrInvite::Broadcast {
374+
broadcast_name: name,
375+
grpid,
376+
..
377+
} => {
378+
let chattype = if matches!(invite, QrInvite::Group { .. }) {
379+
Chattype::Group
380+
} else {
381+
Chattype::InBroadcast
382+
};
383+
384+
let chat_id = match chat::get_chat_id_by_grpid(context, grpid).await? {
353385
Some((chat_id, _protected, _blocked)) => {
354386
chat_id.unblock_ex(context, Nosync).await?;
355387
chat_id
356388
}
357389
None => {
358390
ChatId::create_multiuser_record(
359391
context,
360-
Chattype::Group,
392+
chattype,
361393
grpid,
362394
name,
363395
Blocked::Not,
@@ -368,7 +400,7 @@ async fn joining_chat_id(
368400
.await?
369401
}
370402
};
371-
Ok(group_chat_id)
403+
Ok(chat_id)
372404
}
373405
}
374406
}

src/securejoin/qrinvite.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,34 @@ impl QrInvite {
4545
/// translated to a contact ID.
4646
pub fn contact_id(&self) -> ContactId {
4747
match self {
48-
Self::Contact { contact_id, .. } | Self::Group { contact_id, .. } => *contact_id,
48+
Self::Contact { contact_id, .. }
49+
| Self::Group { contact_id, .. }
50+
| Self::Broadcast { contact_id, .. } => *contact_id,
4951
}
5052
}
5153

5254
/// The fingerprint of the inviter.
5355
pub fn fingerprint(&self) -> &Fingerprint {
5456
match self {
55-
Self::Contact { fingerprint, .. } | Self::Group { fingerprint, .. } => fingerprint,
57+
Self::Contact { fingerprint, .. }
58+
| Self::Group { fingerprint, .. }
59+
| Self::Broadcast { fingerprint, .. } => fingerprint,
5660
}
5761
}
5862

5963
/// The `INVITENUMBER` of the setup-contact/secure-join protocol.
6064
pub fn invitenumber(&self) -> &str {
6165
match self {
6266
Self::Contact { invitenumber, .. } | Self::Group { invitenumber, .. } => invitenumber,
67+
Self::Broadcast { .. } => panic!("broadcast invite has no invite number"), // TODO panic
6368
}
6469
}
6570

6671
/// The `AUTH` code of the setup-contact/secure-join protocol.
6772
pub fn authcode(&self) -> &str {
6873
match self {
6974
Self::Contact { authcode, .. } | Self::Group { authcode, .. } => authcode,
75+
Self::Broadcast { .. } => panic!("broadcast invite has no authcode"), // TODO panic
7076
}
7177
}
7278
}

0 commit comments

Comments
 (0)