@@ -298,9 +298,11 @@ async fn test_member_add_remove() -> Result<()> {
298
298
299
299
let alice = tcm. alice ( ) . await ;
300
300
let bob = tcm. bob ( ) . await ;
301
+ let fiona = tcm. fiona ( ) . await ;
301
302
302
303
// Create contact for Bob on the Alice side with name "robert".
303
- let alice_bob_contact_id =
Contact :: create ( & alice
, "robert" , "[email protected] " ) . await ?
;
304
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( & bob) . await ;
305
+ alice_bob_contact_id. set_name ( & alice, "robert" ) . await ?;
304
306
305
307
// Set Bob authname to "Bob" and send it to Alice.
306
308
bob. set_config ( Config :: Displayname , Some ( "Bob" ) ) . await ?;
@@ -320,19 +322,15 @@ async fn test_member_add_remove() -> Result<()> {
320
322
// Create and promote a group.
321
323
let alice_chat_id =
322
324
create_group_chat ( & alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
323
- let alice_fiona_contact_id = Contact :: create ( & alice , "Fiona" , " fiona@example.net" ) . await ? ;
325
+ let alice_fiona_contact_id = alice . add_or_lookup_contact_id ( & fiona) . await ;
324
326
add_contact_to_chat ( & alice, alice_chat_id, alice_fiona_contact_id) . await ?;
325
- let sent = alice
327
+ alice
326
328
. send_text ( alice_chat_id, "Hi! I created a group." )
327
329
. await ;
328
- assert ! ( sent. payload. contains( "Hi! I created a group." ) ) ;
329
330
330
331
// Alice adds Bob to the chat.
331
332
add_contact_to_chat ( & alice, alice_chat_id, alice_bob_contact_id) . await ?;
332
333
let sent = alice. pop_sent_msg ( ) . await ;
333
- assert ! ( sent
334
- . payload
335
- . contains
( "I added member Bob ([email protected] )." ) ) ;
336
334
// Locally set name "robert" should not leak.
337
335
assert ! ( !sent. payload. contains( "robert" ) ) ;
338
336
assert_eq ! (
@@ -343,9 +341,6 @@ async fn test_member_add_remove() -> Result<()> {
343
341
// Alice removes Bob from the chat.
344
342
remove_contact_from_chat ( & alice, alice_chat_id, alice_bob_contact_id) . await ?;
345
343
let sent = alice. pop_sent_msg ( ) . await ;
346
- assert ! ( sent
347
- . payload
348
- . contains
( "I removed member Bob ([email protected] )." ) ) ;
349
344
assert ! ( !sent. payload. contains( "robert" ) ) ;
350
345
assert_eq ! (
351
346
sent. load_from_db( ) . await . get_text( ) ,
@@ -355,7 +350,6 @@ async fn test_member_add_remove() -> Result<()> {
355
350
// Alice leaves the chat.
356
351
remove_contact_from_chat ( & alice, alice_chat_id, ContactId :: SELF ) . await ?;
357
352
let sent = alice. pop_sent_msg ( ) . await ;
358
- assert ! ( sent. payload. contains( "I left the group." ) ) ;
359
353
assert_eq ! ( sent. load_from_db( ) . await . get_text( ) , "You left the group." ) ;
360
354
361
355
Ok ( ( ) )
@@ -368,10 +362,12 @@ async fn test_parallel_member_remove() -> Result<()> {
368
362
369
363
let alice = tcm. alice ( ) . await ;
370
364
let bob = tcm. bob ( ) . await ;
365
+ let charlie = tcm. charlie ( ) . await ;
366
+ let fiona = tcm. fiona ( ) . await ;
371
367
372
- let alice_bob_contact_id = Contact :: create ( & alice , "Bob" , " bob@example.net" ) . await ? ;
373
- let alice_fiona_contact_id = Contact :: create ( & alice , "Fiona" , " fiona@example.net" ) . await ? ;
374
- let alice_claire_contact_id =
Contact :: create ( & alice
, "Claire" , "[email protected] " ) . await ? ;
368
+ let alice_bob_contact_id = alice . add_or_lookup_contact_id ( & bob) . await ;
369
+ let alice_fiona_contact_id = alice . add_or_lookup_contact_id ( & fiona) . await ;
370
+ let alice_charlie_contact_id = alice. add_or_lookup_contact_id ( & charlie ) . await ;
375
371
376
372
// Create and promote a group.
377
373
let alice_chat_id =
@@ -387,7 +383,7 @@ async fn test_parallel_member_remove() -> Result<()> {
387
383
bob_chat_id. accept ( & bob) . await ?;
388
384
389
385
// Alice adds Claire to the chat.
390
- add_contact_to_chat ( & alice, alice_chat_id, alice_claire_contact_id ) . await ?;
386
+ add_contact_to_chat ( & alice, alice_chat_id, alice_charlie_contact_id ) . await ?;
391
387
let alice_sent_add_msg = alice. pop_sent_msg ( ) . await ;
392
388
393
389
// Bob leaves the chat.
@@ -680,7 +676,7 @@ async fn test_leave_group() -> Result<()> {
680
676
681
677
// Create group chat with Bob.
682
678
let alice_chat_id = create_group_chat ( & alice, ProtectionStatus :: Unprotected , "foo" ) . await ?;
683
- let bob_contact = Contact :: create ( & alice , "" , " bob@example.net" ) . await ? ;
679
+ let bob_contact = alice . add_or_lookup_contact ( & bob) . await . id ;
684
680
add_contact_to_chat ( & alice, alice_chat_id, bob_contact) . await ?;
685
681
686
682
// Alice sends first message to group.
@@ -2264,11 +2260,13 @@ async fn test_save_from_saved_to_saved_failing() -> Result<()> {
2264
2260
async fn test_resend_own_message ( ) -> Result < ( ) > {
2265
2261
// Alice creates group with Bob and sends an initial message
2266
2262
let alice = TestContext :: new_alice ( ) . await ;
2263
+ let bob = TestContext :: new_bob ( ) . await ;
2264
+ let fiona = TestContext :: new_fiona ( ) . await ;
2267
2265
let alice_grp = create_group_chat ( & alice, ProtectionStatus :: Unprotected , "grp" ) . await ?;
2268
2266
add_contact_to_chat (
2269
2267
& alice,
2270
2268
alice_grp,
2271
- Contact :: create ( & alice , "" , " bob@example.net" ) . await ? ,
2269
+ alice . add_or_lookup_contact_id ( & bob) . await ,
2272
2270
)
2273
2271
. await ?;
2274
2272
let sent1 = alice. send_text ( alice_grp, "alice->bob" ) . await ;
@@ -2277,7 +2275,7 @@ async fn test_resend_own_message() -> Result<()> {
2277
2275
add_contact_to_chat (
2278
2276
& alice,
2279
2277
alice_grp,
2280
- Contact :: create ( & alice
, "" , "[email protected] " ) . await ? ,
2278
+ alice. add_or_lookup_contact_id ( & fiona ) . await ,
2281
2279
)
2282
2280
. await ?;
2283
2281
let sent2 = alice. pop_sent_msg ( ) . await ;
@@ -2321,15 +2319,13 @@ async fn test_resend_own_message() -> Result<()> {
2321
2319
assert_eq ! ( get_chat_contacts( & bob, msg. chat_id) . await ?. len( ) , 3 ) ;
2322
2320
assert_eq ! ( get_chat_msgs( & bob, msg. chat_id) . await ?. len( ) , 2 ) ;
2323
2321
2324
- // Claire does not receive the first message, however, due to resending, she has a similar view as Alice and Bob
2325
- let claire = TestContext :: new ( ) . await ;
2326
- claire
. configure_addr ( "[email protected] " ) . await ;
2327
- claire. recv_msg ( & sent2) . await ;
2328
- let msg = claire. recv_msg ( & sent3) . await ;
2322
+ // Fiona does not receive the first message, however, due to resending, she has a similar view as Alice and Bob
2323
+ fiona. recv_msg ( & sent2) . await ;
2324
+ let msg = fiona. recv_msg ( & sent3) . await ;
2329
2325
assert_eq ! ( msg. get_text( ) , "alice->bob" ) ;
2330
- assert_eq ! ( get_chat_contacts( & claire , msg. chat_id) . await ?. len( ) , 3 ) ;
2331
- assert_eq ! ( get_chat_msgs( & claire , msg. chat_id) . await ?. len( ) , 2 ) ;
2332
- let msg_from = Contact :: get_by_id ( & claire , msg. get_from_id ( ) ) . await ?;
2326
+ assert_eq ! ( get_chat_contacts( & fiona , msg. chat_id) . await ?. len( ) , 3 ) ;
2327
+ assert_eq ! ( get_chat_msgs( & fiona , msg. chat_id) . await ?. len( ) , 2 ) ;
2328
+ let msg_from = Contact :: get_by_id ( & fiona , msg. get_from_id ( ) ) . await ?;
2333
2329
assert_eq ! ( msg_from
. get_addr
( ) , "[email protected] " ) ;
2334
2330
assert ! ( sent1_ts_sent < msg. timestamp_sent) ;
2335
2331
@@ -2813,12 +2809,7 @@ async fn test_blob_renaming() -> Result<()> {
2813
2809
let alice = TestContext :: new_alice ( ) . await ;
2814
2810
let bob = TestContext :: new_bob ( ) . await ;
2815
2811
let chat_id = create_group_chat ( & alice, ProtectionStatus :: Unprotected , "Group" ) . await ?;
2816
- add_contact_to_chat (
2817
- & alice,
2818
- chat_id,
2819
- Contact :: create ( & alice
, "bob" , "[email protected] " ) . await ?
,
2820
- )
2821
- . await ?;
2812
+ add_contact_to_chat ( & alice, chat_id, alice. add_or_lookup_contact_id ( & bob) . await ) . await ?;
2822
2813
let file = alice. get_blobdir ( ) . join ( "harmless_file.\u{202e} txt.exe" ) ;
2823
2814
fs:: write ( & file, "aaa" ) . await ?;
2824
2815
let mut msg = Message :: new ( Viewtype :: File ) ;
@@ -2850,7 +2841,7 @@ async fn test_sync_blocked() -> Result<()> {
2850
2841
let sent_msg = bob. send_text ( ba_chat. id , "hi" ) . await ;
2851
2842
let a0b_chat_id = alice0. recv_msg ( & sent_msg) . await . chat_id ;
2852
2843
alice1. recv_msg ( & sent_msg) . await ;
2853
- let a0b_contact_id = alice0. add_or_lookup_contact ( & bob) . await . id ;
2844
+ let a0b_contact_id = alice0. add_or_lookup_contact_id ( & bob) . await ;
2854
2845
2855
2846
assert_eq ! ( alice1. get_chat( & bob) . await . blocked, Blocked :: Request ) ;
2856
2847
a0b_chat_id. accept ( alice0) . await ?;
@@ -3351,7 +3342,8 @@ async fn test_past_members() -> Result<()> {
3351
3342
let mut tcm = TestContextManager :: new ( ) ;
3352
3343
3353
3344
let alice = & tcm. alice ( ) . await ;
3354
- let alice_fiona_contact_id =
Contact :: create ( alice
, "Fiona" , "[email protected] " ) . await ?
;
3345
+ let fiona = & tcm. fiona ( ) . await ;
3346
+ let alice_fiona_contact_id = alice. add_or_lookup_contact_id ( fiona) . await ;
3355
3347
3356
3348
let alice_chat_id =
3357
3349
create_group_chat ( alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
@@ -3363,8 +3355,7 @@ async fn test_past_members() -> Result<()> {
3363
3355
assert_eq ! ( get_past_chat_contacts( alice, alice_chat_id) . await ?. len( ) , 1 ) ;
3364
3356
3365
3357
let bob = & tcm. bob ( ) . await ;
3366
- let bob_addr = bob. get_config ( Config :: Addr ) . await ?. unwrap ( ) ;
3367
- let alice_bob_contact_id = Contact :: create ( alice, "Bob" , & bob_addr) . await ?;
3358
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( bob) . await ;
3368
3359
add_contact_to_chat ( alice, alice_chat_id, alice_bob_contact_id) . await ?;
3369
3360
3370
3361
let add_message = alice. pop_sent_msg ( ) . await ;
@@ -3383,8 +3374,7 @@ async fn non_member_cannot_modify_member_list() -> Result<()> {
3383
3374
let alice = & tcm. alice ( ) . await ;
3384
3375
let bob = & tcm. bob ( ) . await ;
3385
3376
3386
- let bob_addr = bob. get_config ( Config :: Addr ) . await ?. unwrap ( ) ;
3387
- let alice_bob_contact_id = Contact :: create ( alice, "Bob" , & bob_addr) . await ?;
3377
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( bob) . await ;
3388
3378
3389
3379
let alice_chat_id =
3390
3380
create_group_chat ( alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
@@ -3396,7 +3386,8 @@ async fn non_member_cannot_modify_member_list() -> Result<()> {
3396
3386
let bob_chat_id = bob_received_msg. get_chat_id ( ) ;
3397
3387
bob_chat_id. accept ( bob) . await ?;
3398
3388
3399
- let bob_fiona_contact_id =
Contact :: create ( bob
, "Fiona" , "[email protected] " ) . await ?
;
3389
+ let fiona = & tcm. fiona ( ) . await ;
3390
+ let bob_fiona_contact_id = bob. add_or_lookup_contact_id ( fiona) . await ;
3400
3391
3401
3392
// Alice removes Bob and Bob adds Fiona at the same time.
3402
3393
remove_contact_from_chat ( alice, alice_chat_id, alice_bob_contact_id) . await ?;
@@ -3418,11 +3409,10 @@ async fn unpromoted_group_no_tombstones() -> Result<()> {
3418
3409
3419
3410
let alice = & tcm. alice ( ) . await ;
3420
3411
let bob = & tcm. bob ( ) . await ;
3412
+ let fiona = & tcm. fiona ( ) . await ;
3421
3413
3422
- let bob_addr = bob. get_config ( Config :: Addr ) . await ?. unwrap ( ) ;
3423
- let alice_bob_contact_id = Contact :: create ( alice, "Bob" , & bob_addr) . await ?;
3424
- let fiona_addr =
"[email protected] " ;
3425
- let alice_fiona_contact_id = Contact :: create ( alice, "Fiona" , fiona_addr) . await ?;
3414
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( bob) . await ;
3415
+ let alice_fiona_contact_id = alice. add_or_lookup_contact_id ( fiona) . await ;
3426
3416
3427
3417
let alice_chat_id =
3428
3418
create_group_chat ( alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
@@ -3438,10 +3428,6 @@ async fn unpromoted_group_no_tombstones() -> Result<()> {
3438
3428
assert_eq ! ( get_past_chat_contacts( alice, alice_chat_id) . await ?. len( ) , 0 ) ;
3439
3429
3440
3430
let sent = alice. send_text ( alice_chat_id, "Hello group!" ) . await ;
3441
- let payload = sent. payload ( ) ;
3442
- assert_eq ! ( payload. contains( "Hello group!" ) , true ) ;
3443
- assert_eq ! ( payload. contains( & bob_addr) , true ) ;
3444
- assert_eq ! ( payload. contains( fiona_addr) , false ) ;
3445
3431
3446
3432
let bob_msg = bob. recv_msg ( & sent) . await ;
3447
3433
let bob_chat_id = bob_msg. chat_id ;
@@ -3457,8 +3443,8 @@ async fn test_expire_past_members_after_60_days() -> Result<()> {
3457
3443
let mut tcm = TestContextManager :: new ( ) ;
3458
3444
3459
3445
let alice = & tcm. alice ( ) . await ;
3460
- let fiona_addr = " fiona@example.net" ;
3461
- let alice_fiona_contact_id = Contact :: create ( alice, "Fiona" , fiona_addr ) . await ? ;
3446
+ let fiona = & tcm . fiona ( ) . await ;
3447
+ let alice_fiona_contact_id = alice. add_or_lookup_contact_id ( fiona ) . await ;
3462
3448
3463
3449
let alice_chat_id =
3464
3450
create_group_chat ( alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
@@ -3473,12 +3459,10 @@ async fn test_expire_past_members_after_60_days() -> Result<()> {
3473
3459
assert_eq ! ( get_past_chat_contacts( alice, alice_chat_id) . await ?. len( ) , 0 ) ;
3474
3460
3475
3461
let bob = & tcm. bob ( ) . await ;
3476
- let bob_addr = bob. get_config ( Config :: Addr ) . await ?. unwrap ( ) ;
3477
- let alice_bob_contact_id = Contact :: create ( alice, "Bob" , & bob_addr) . await ?;
3462
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( bob) . await ;
3478
3463
add_contact_to_chat ( alice, alice_chat_id, alice_bob_contact_id) . await ?;
3479
3464
3480
3465
let add_message = alice. pop_sent_msg ( ) . await ;
3481
- assert_eq ! ( add_message. payload. contains( fiona_addr) , false ) ;
3482
3466
let bob_add_message = bob. recv_msg ( & add_message) . await ;
3483
3467
let bob_chat_id = bob_add_message. chat_id ;
3484
3468
assert_eq ! ( get_chat_contacts( bob, bob_chat_id) . await ?. len( ) , 2 ) ;
@@ -3552,13 +3536,11 @@ async fn test_restore_backup_after_60_days() -> Result<()> {
3552
3536
3553
3537
let alice = & tcm. alice ( ) . await ;
3554
3538
let bob = & tcm. bob ( ) . await ;
3539
+ let charlie = & tcm. charlie ( ) . await ;
3555
3540
let fiona = & tcm. fiona ( ) . await ;
3556
3541
3557
- let bob_addr = bob. get_config ( Config :: Addr ) . await ?. unwrap ( ) ;
3558
- let alice_bob_contact_id = Contact :: create ( alice, "Bob" , & bob_addr) . await ?;
3559
-
3560
- let charlie_addr =
"[email protected] " ;
3561
- let alice_charlie_contact_id = Contact :: create ( alice, "Charlie" , charlie_addr) . await ?;
3542
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( bob) . await ;
3543
+ let alice_charlie_contact_id = alice. add_or_lookup_contact_id ( charlie) . await ;
3562
3544
3563
3545
let alice_chat_id =
3564
3546
create_group_chat ( alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
@@ -3580,7 +3562,6 @@ async fn test_restore_backup_after_60_days() -> Result<()> {
3580
3562
assert_eq ! ( get_past_chat_contacts( alice, alice_chat_id) . await ?. len( ) , 1 ) ;
3581
3563
3582
3564
let remove_message = alice. pop_sent_msg ( ) . await ;
3583
- assert_eq ! ( remove_message. payload. contains( charlie_addr) , true ) ;
3584
3565
bob. recv_msg ( & remove_message) . await ;
3585
3566
3586
3567
// 60 days pass.
@@ -3589,8 +3570,7 @@ async fn test_restore_backup_after_60_days() -> Result<()> {
3589
3570
assert_eq ! ( get_past_chat_contacts( alice, alice_chat_id) . await ?. len( ) , 0 ) ;
3590
3571
3591
3572
// Bob adds Fiona to the chat.
3592
- let fiona_addr = fiona. get_config ( Config :: Addr ) . await ?. unwrap ( ) ;
3593
- let bob_fiona_contact_id = Contact :: create ( bob, "Fiona" , & fiona_addr) . await ?;
3573
+ let bob_fiona_contact_id = bob. add_or_lookup_contact_id ( fiona) . await ;
3594
3574
add_contact_to_chat ( bob, bob_chat_id, bob_fiona_contact_id) . await ?;
3595
3575
3596
3576
let add_message = bob. pop_sent_msg ( ) . await ;
@@ -3654,7 +3634,7 @@ async fn test_restore_backup_after_60_days() -> Result<()> {
3654
3634
// Charlie is not part of the chat.
3655
3635
assert_eq ! ( get_chat_contacts( bob, bob_chat_id) . await ?. len( ) , 3 ) ;
3656
3636
assert_eq ! ( get_past_chat_contacts( bob, bob_chat_id) . await ?. len( ) , 0 ) ;
3657
- let bob_charlie_contact_id = Contact :: create ( bob, "Charlie" , charlie_addr ) . await ? ;
3637
+ let bob_charlie_contact_id = bob. add_or_lookup_contact_id ( charlie ) . await ;
3658
3638
assert ! ( !is_contact_in_chat( bob, bob_chat_id, bob_charlie_contact_id) . await ?) ;
3659
3639
3660
3640
assert_eq ! ( get_chat_contacts( fiona, fiona_chat_id) . await ?. len( ) , 3 ) ;
0 commit comments