Skip to content

Commit 7750215

Browse files
committed
Send Bob's verified message to the correct chat.
The reasoning is that both Alice and Bob will already get the group chat opened and focussed. Sending the verified messages to 1:1 chats will create a lot of unused chats for Alice (when adding multiple members) and also Bob to a lesser extend. If they do start chatting 1:1 then the 1:1 chat will be created.
1 parent 1e8f6e0 commit 7750215

File tree

2 files changed

+73
-25
lines changed

2 files changed

+73
-25
lines changed

src/securejoin.rs

+71-23
Original file line numberDiff line numberDiff line change
@@ -1133,14 +1133,16 @@ mod tests {
11331133
.with_log_sink(log_tx)
11341134
.build()
11351135
.await;
1136+
1137+
// We start with empty chatlists.
11361138
assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 0);
11371139
assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 0);
11381140

1139-
let chatid =
1141+
let alice_chatid =
11401142
chat::create_group_chat(&alice.ctx, ProtectionStatus::Protected, "the chat").await?;
11411143

11421144
// Step 1: Generate QR-code, secure-join implied by chatid
1143-
let qr = dc_get_securejoin_qr(&alice.ctx, Some(chatid))
1145+
let qr = dc_get_securejoin_qr(&alice.ctx, Some(alice_chatid))
11441146
.await
11451147
.unwrap();
11461148

@@ -1232,9 +1234,9 @@ mod tests {
12321234
);
12331235

12341236
{
1235-
// TODO: Check if Alice has a hidden 1:1 chat in which there is an info message
1236-
// saying bob is verified. However currently this is purposefully sent to
1237-
// Alice's group chat by commit 3b7b8ea0f1f8b9c9d300388768eed069be59c8be?
1237+
// Now Alice's chat with Bob should still be hidden, the verified message should
1238+
// appear in the group chat.
1239+
12381240
let chat = alice
12391241
.get_chat(&bob)
12401242
.await
@@ -1244,20 +1246,20 @@ mod tests {
12441246
Blocked::Yes,
12451247
"Alice's 1:1 chat with Bob is not hidden"
12461248
);
1247-
// let msg_id = chat::get_chat_msgs(&alice.ctx, chat.get_id(), 0x1, None)
1248-
// .await
1249-
// .unwrap()
1250-
// .into_iter()
1251-
// .filter_map(|item| match item {
1252-
// chat::ChatItem::Message { msg_id } => Some(msg_id),
1253-
// _ => None,
1254-
// })
1255-
// .max()
1256-
// .expect("No messages in Alice's 1:1 chat");
1257-
// let msg = Message::load_from_db(&alice.ctx, msg_id).await.unwrap();
1258-
// assert!(msg.is_info());
1259-
// let text = msg.get_text().unwrap();
1260-
// assert!(text.contains("[email protected] verified"));
1249+
let msg_id = chat::get_chat_msgs(&alice.ctx, alice_chatid, 0x1, None)
1250+
.await
1251+
.unwrap()
1252+
.into_iter()
1253+
.filter_map(|item| match item {
1254+
chat::ChatItem::Message { msg_id } => Some(msg_id),
1255+
_ => None,
1256+
})
1257+
.min()
1258+
.expect("No messages in Alice's group chat");
1259+
let msg = Message::load_from_db(&alice.ctx, msg_id).await.unwrap();
1260+
assert!(msg.is_info());
1261+
let text = msg.get_text().unwrap();
1262+
assert!(text.contains("[email protected] verified"));
12611263
}
12621264

12631265
// Bob should not yet have Alice verified
@@ -1274,10 +1276,56 @@ mod tests {
12741276

12751277
// Step 7: Bob receives vg-member-added, sends vg-member-added-received
12761278
bob.recv_msg(&sent).await;
1277-
assert_eq!(
1278-
contact_alice.is_verified(&bob.ctx).await?,
1279-
VerifiedStatus::BidirectVerified
1280-
);
1279+
{
1280+
// Bob has Alice verified, message shows up in the group chat.
1281+
assert_eq!(
1282+
contact_alice.is_verified(&bob.ctx).await?,
1283+
VerifiedStatus::BidirectVerified
1284+
);
1285+
let chat = bob
1286+
.get_chat(&alice)
1287+
.await
1288+
.expect("Bob has no 1:1 chat with Alice");
1289+
assert_eq!(
1290+
chat.blocked,
1291+
Blocked::Yes,
1292+
"Bob's 1:1 chat with Alice is not hidden"
1293+
);
1294+
for item in chat::get_chat_msgs(&bob.ctx, bob_chatid, 0x1, None)
1295+
.await
1296+
.unwrap()
1297+
{
1298+
match item {
1299+
chat::ChatItem::Message { msg_id } => {
1300+
let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap();
1301+
let text = msg.get_text().unwrap();
1302+
println!("msg {} text: {}", msg_id, text);
1303+
}
1304+
_ => (),
1305+
}
1306+
}
1307+
let mut msg_iter = chat::get_chat_msgs(&bob.ctx, bob_chatid, 0x1, None)
1308+
.await
1309+
.unwrap()
1310+
.into_iter();
1311+
loop {
1312+
match msg_iter.next() {
1313+
Some(chat::ChatItem::Message { msg_id }) => {
1314+
let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap();
1315+
let text = msg.get_text().unwrap();
1316+
match text.contains("[email protected] verified") {
1317+
true => {
1318+
assert!(msg.is_info());
1319+
break;
1320+
}
1321+
false => continue,
1322+
}
1323+
}
1324+
Some(_) => continue,
1325+
None => panic!("Verified message not found in Bob's group chat"),
1326+
}
1327+
}
1328+
}
12811329

12821330
let sent = bob.pop_sent_msg().await;
12831331
let msg = alice.parse_msg(&sent).await;

src/securejoin/bob.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ impl BobState {
220220

221221
/// Notifies the user that the SecureJoin peer is verified.
222222
///
223-
/// This creates an info message in the 1:1 chat with the peer.
223+
/// This creates an info message in the chat being joined.
224224
async fn notify_peer_verified(&self, context: &Context) -> Result<()> {
225225
let contact = Contact::get_by_id(context, self.invite().contact_id()).await?;
226226
let msg = stock_str::contact_verified(context, &contact).await;
227-
let chat_id = self.alice_chat();
227+
let chat_id = self.joining_chat_id(context).await?;
228228
chat::add_info_msg(context, chat_id, &msg, time()).await?;
229229
context.emit_event(EventType::ChatModified(chat_id));
230230
Ok(())

0 commit comments

Comments
 (0)