@@ -43,17 +43,7 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul
4343 // A 1:1 chat is needed to send messages to Alice. When joining a group this chat is
4444 // hidden, if a user starts sending messages in it it will be unhidden in
4545 // receive_imf.
46- let hidden = match invite {
47- QrInvite :: Contact { .. } => Blocked :: Not ,
48- QrInvite :: Group { .. } => Blocked :: Yes ,
49- QrInvite :: Broadcast { .. } => Blocked :: Yes ,
50- } ;
51-
52- // The 1:1 chat with the inviter
53- let private_chat_id =
54- ChatId :: create_for_contact_with_blocked ( context, invite. contact_id ( ) , hidden)
55- . await
56- . with_context ( || format ! ( "can't create chat for contact {}" , invite. contact_id( ) ) ) ?;
46+ let private_chat_id = private_chat_id ( context, & invite) . await ?;
5747
5848 ContactId :: scaleup_origin ( context, & [ invite. contact_id ( ) ] , Origin :: SecurejoinJoined ) . await ?;
5949 context. emit_event ( EventType :: ContactsChanged ( None ) ) ;
@@ -175,6 +165,9 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul
175165///
176166/// Returns the ID of the newly inserted entry.
177167async fn insert_new_db_entry ( context : & Context , invite : QrInvite , chat_id : ChatId ) -> Result < i64 > {
168+ // The `chat_id` isn't actually needed anymore,
169+ // but we still save it;
170+ // can be removed as a future improvement.
178171 context
179172 . sql
180173 . insert (
@@ -195,11 +188,10 @@ pub(super) async fn handle_auth_required(
195188 // Load all Bob states that expect `vc-auth-required` or `vg-auth-required`.
196189 let bob_states = context
197190 . sql
198- . query_map_vec ( "SELECT id, invite, chat_id FROM bobstate" , ( ) , |row| {
191+ . query_map_vec ( "SELECT id, invite FROM bobstate" , ( ) , |row| {
199192 let row_id: i64 = row. get ( 0 ) ?;
200193 let invite: QrInvite = row. get ( 1 ) ?;
201- let chat_id: ChatId = row. get ( 2 ) ?;
202- Ok ( ( row_id, invite, chat_id) )
194+ Ok ( ( row_id, invite) )
203195 } )
204196 . await ?;
205197
@@ -209,7 +201,7 @@ pub(super) async fn handle_auth_required(
209201 ) ;
210202
211203 let mut auth_sent = false ;
212- for ( bobstate_row_id, invite, chat_id ) in bob_states {
204+ for ( bobstate_row_id, invite) in bob_states {
213205 if !encrypted_and_signed ( context, message, invite. fingerprint ( ) ) {
214206 continue ;
215207 }
@@ -220,6 +212,7 @@ pub(super) async fn handle_auth_required(
220212 }
221213
222214 info ! ( context, "Fingerprint verified." , ) ;
215+ let chat_id = private_chat_id ( context, & invite) . await ?;
223216 send_handshake_message ( context, & invite, chat_id, BobHandshakeMsg :: RequestWithAuth ) . await ?;
224217 context
225218 . sql
@@ -348,6 +341,22 @@ impl BobHandshakeMsg {
348341 }
349342}
350343
344+ /// Returns the 1:1 chat with the inviter.
345+ ///
346+ /// This is the chat in which securejoin messages are sent.
347+ /// The 1:1 chat will be created if it does not yet exist.
348+ async fn private_chat_id ( context : & Context , invite : & QrInvite ) -> Result < ChatId > {
349+ let hidden = match invite {
350+ QrInvite :: Contact { .. } => Blocked :: Not ,
351+ QrInvite :: Group { .. } => Blocked :: Yes ,
352+ QrInvite :: Broadcast { .. } => Blocked :: Yes ,
353+ } ;
354+
355+ ChatId :: create_for_contact_with_blocked ( context, invite. contact_id ( ) , hidden)
356+ . await
357+ . with_context ( || format ! ( "can't create chat for contact {}" , invite. contact_id( ) ) )
358+ }
359+
351360/// Returns the [`ChatId`] of the chat being joined.
352361///
353362/// This is the chat in which you want to notify the user as well.
0 commit comments