@@ -424,11 +424,10 @@ async fn test_msg_with_implicit_member_removed() -> Result<()> {
424
424
let mut tcm = TestContextManager :: new ( ) ;
425
425
let alice = tcm. alice ( ) . await ;
426
426
let bob = tcm. bob ( ) . await ;
427
- let alice_bob_contact_id =
428
- Contact :: create ( & alice, "Bob" , & bob. get_config ( Config :: Addr ) . await ?. unwrap ( ) ) . await ?;
429
- let fiona_addr =
"[email protected] " ;
430
- let alice_fiona_contact_id = Contact :: create ( & alice, "Fiona" , fiona_addr) . await ?;
431
- let bob_fiona_contact_id = Contact :: create ( & bob, "Fiona" , fiona_addr) . await ?;
427
+ let fiona = tcm. fiona ( ) . await ;
428
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( & bob) . await ;
429
+ let alice_fiona_contact_id = alice. add_or_lookup_contact_id ( & fiona) . await ;
430
+ let bob_fiona_contact_id = bob. add_or_lookup_contact_id ( & fiona) . await ;
432
431
let alice_chat_id =
433
432
create_group_chat ( & alice, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
434
433
add_contact_to_chat ( & alice, alice_chat_id, alice_bob_contact_id) . await ?;
@@ -470,8 +469,9 @@ async fn test_msg_with_implicit_member_removed() -> Result<()> {
470
469
471
470
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
472
471
async fn test_modify_chat_multi_device ( ) -> Result < ( ) > {
473
- let a1 = TestContext :: new_alice ( ) . await ;
474
- let a2 = TestContext :: new_alice ( ) . await ;
472
+ let mut tcm = TestContextManager :: new ( ) ;
473
+ let a1 = tcm. alice ( ) . await ;
474
+ let a2 = tcm. alice ( ) . await ;
475
475
a1. set_config_bool ( Config :: BccSelf , true ) . await ?;
476
476
477
477
// create group and sync it to the second device
@@ -495,8 +495,9 @@ async fn test_modify_chat_multi_device() -> Result<()> {
495
495
assert_eq ! ( get_chat_contacts( & a2, a2_chat_id) . await ?. len( ) , 1 ) ;
496
496
497
497
// add a member to the group
498
- let bob =
Contact :: create ( & a1
, "" , "[email protected] " ) . await ?
;
499
- add_contact_to_chat ( & a1, a1_chat_id, bob) . await ?;
498
+ let bob = tcm. bob ( ) . await ;
499
+ let bob_id = a1. add_or_lookup_contact_id ( & bob) . await ;
500
+ add_contact_to_chat ( & a1, a1_chat_id, bob_id) . await ?;
500
501
let a1_msg = a1. get_last_msg ( ) . await ;
501
502
502
503
let a2_msg = a2. recv_msg ( & a1. pop_sent_msg ( ) . await ) . await ;
@@ -524,7 +525,7 @@ async fn test_modify_chat_multi_device() -> Result<()> {
524
525
assert_eq ! ( Chat :: load_from_db( & a2, a2_chat_id) . await ?. name, "bar" ) ;
525
526
526
527
// remove member from group
527
- remove_contact_from_chat ( & a1, a1_chat_id, bob ) . await ?;
528
+ remove_contact_from_chat ( & a1, a1_chat_id, bob_id ) . await ?;
528
529
let a1_msg = a1. get_last_msg ( ) . await ;
529
530
530
531
let a2_msg = a2. recv_msg ( & a1. pop_sent_msg ( ) . await ) . await ;
@@ -551,35 +552,40 @@ async fn test_modify_chat_multi_device() -> Result<()> {
551
552
async fn test_modify_chat_disordered ( ) -> Result < ( ) > {
552
553
let _n = TimeShiftFalsePositiveNote ;
553
554
554
- // Alice creates a group with Bob, Claire and Daisy and then removes Claire and Daisy
555
+ let mut tcm = TestContextManager :: new ( ) ;
556
+
557
+ // Alice creates a group with Bob, Charlie and Fiona and then removes Charlie and Fiona
555
558
// (time shift is needed as otherwise smeared time from Alice looks to Bob like messages from the future which are all set to "now" then)
556
- let alice = TestContext :: new_alice ( ) . await ;
559
+ let alice = tcm . alice ( ) . await ;
557
560
558
- let bob_id =
Contact :: create ( & alice
, "" , "[email protected] " ) . await ?
;
559
- let claire_id =
Contact :: create ( & alice
, "" , "[email protected] " ) . await ?
;
560
- let daisy_id =
Contact :: create ( & alice
, "" , "[email protected] " ) . await ?
;
561
+ let bob = tcm. bob ( ) . await ;
562
+ let bob_id = alice. add_or_lookup_contact_id ( & bob) . await ;
563
+ let charlie = tcm. charlie ( ) . await ;
564
+ let charlie_id = alice. add_or_lookup_contact_id ( & charlie) . await ;
565
+ let fiona = tcm. fiona ( ) . await ;
566
+ let fiona_id = alice. add_or_lookup_contact_id ( & fiona) . await ;
561
567
562
568
let alice_chat_id = create_group_chat ( & alice, ProtectionStatus :: Unprotected , "foo" ) . await ?;
563
569
send_text_msg ( & alice, alice_chat_id, "populate" . to_string ( ) ) . await ?;
564
570
565
571
add_contact_to_chat ( & alice, alice_chat_id, bob_id) . await ?;
566
572
let add1 = alice. pop_sent_msg ( ) . await ;
567
573
568
- add_contact_to_chat ( & alice, alice_chat_id, claire_id ) . await ?;
574
+ add_contact_to_chat ( & alice, alice_chat_id, charlie_id ) . await ?;
569
575
let add2 = alice. pop_sent_msg ( ) . await ;
570
576
SystemTime :: shift ( Duration :: from_millis ( 1100 ) ) ;
571
577
572
- add_contact_to_chat ( & alice, alice_chat_id, daisy_id ) . await ?;
578
+ add_contact_to_chat ( & alice, alice_chat_id, fiona_id ) . await ?;
573
579
let add3 = alice. pop_sent_msg ( ) . await ;
574
580
SystemTime :: shift ( Duration :: from_millis ( 1100 ) ) ;
575
581
576
582
assert_eq ! ( get_chat_contacts( & alice, alice_chat_id) . await ?. len( ) , 4 ) ;
577
583
578
- remove_contact_from_chat ( & alice, alice_chat_id, claire_id ) . await ?;
584
+ remove_contact_from_chat ( & alice, alice_chat_id, charlie_id ) . await ?;
579
585
let remove1 = alice. pop_sent_msg ( ) . await ;
580
586
SystemTime :: shift ( Duration :: from_millis ( 1100 ) ) ;
581
587
582
- remove_contact_from_chat ( & alice, alice_chat_id, daisy_id ) . await ?;
588
+ remove_contact_from_chat ( & alice, alice_chat_id, fiona_id ) . await ?;
583
589
let remove2 = alice. pop_sent_msg ( ) . await ;
584
590
585
591
assert_eq ! ( get_chat_contacts( & alice, alice_chat_id) . await ?. len( ) , 2 ) ;
@@ -630,24 +636,27 @@ async fn test_modify_chat_lost() -> Result<()> {
630
636
let mut tcm = TestContextManager :: new ( ) ;
631
637
let alice = tcm. alice ( ) . await ;
632
638
633
- let bob_id =
Contact :: create ( & alice
, "" , "[email protected] " ) . await ?
;
634
- let claire_id =
Contact :: create ( & alice
, "" , "[email protected] " ) . await ?
;
635
- let daisy_id =
Contact :: create ( & alice
, "" , "[email protected] " ) . await ?
;
639
+ let bob = tcm. bob ( ) . await ;
640
+ let bob_id = alice. add_or_lookup_contact_id ( & bob) . await ;
641
+ let charlie = tcm. charlie ( ) . await ;
642
+ let charlie_id = alice. add_or_lookup_contact_id ( & charlie) . await ;
643
+ let fiona = tcm. fiona ( ) . await ;
644
+ let fiona_id = alice. add_or_lookup_contact_id ( & fiona) . await ;
636
645
637
646
let alice_chat_id = create_group_chat ( & alice, ProtectionStatus :: Unprotected , "foo" ) . await ?;
638
647
add_contact_to_chat ( & alice, alice_chat_id, bob_id) . await ?;
639
- add_contact_to_chat ( & alice, alice_chat_id, claire_id ) . await ?;
640
- add_contact_to_chat ( & alice, alice_chat_id, daisy_id ) . await ?;
648
+ add_contact_to_chat ( & alice, alice_chat_id, charlie_id ) . await ?;
649
+ add_contact_to_chat ( & alice, alice_chat_id, fiona_id ) . await ?;
641
650
642
651
send_text_msg ( & alice, alice_chat_id, "populate" . to_string ( ) ) . await ?;
643
652
let add = alice. pop_sent_msg ( ) . await ;
644
653
SystemTime :: shift ( Duration :: from_millis ( 1100 ) ) ;
645
654
646
- remove_contact_from_chat ( & alice, alice_chat_id, claire_id ) . await ?;
655
+ remove_contact_from_chat ( & alice, alice_chat_id, charlie_id ) . await ?;
647
656
let remove1 = alice. pop_sent_msg ( ) . await ;
648
657
SystemTime :: shift ( Duration :: from_millis ( 1100 ) ) ;
649
658
650
- remove_contact_from_chat ( & alice, alice_chat_id, daisy_id ) . await ?;
659
+ remove_contact_from_chat ( & alice, alice_chat_id, fiona_id ) . await ?;
651
660
let remove2 = alice. pop_sent_msg ( ) . await ;
652
661
653
662
let bob = tcm. bob ( ) . await ;
@@ -2008,20 +2017,22 @@ async fn test_forward() -> Result<()> {
2008
2017
2009
2018
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2010
2019
async fn test_forward_info_msg ( ) -> Result < ( ) > {
2011
- let t = TestContext :: new_alice ( ) . await ;
2020
+ let mut tcm = TestContextManager :: new ( ) ;
2021
+ let alice = & tcm. alice ( ) . await ;
2022
+ let bob = & tcm. bob ( ) . await ;
2012
2023
2013
- let chat_id1 = create_group_chat ( & t , ProtectionStatus :: Unprotected , "a" ) . await ?;
2014
- send_text_msg ( & t , chat_id1, "msg one" . to_string ( ) ) . await ?;
2015
- let bob_id = Contact :: create ( & t , "" , " bob@example.net" ) . await ? ;
2016
- add_contact_to_chat ( & t , chat_id1, bob_id) . await ?;
2017
- let msg1 = t . get_last_msg_in ( chat_id1) . await ;
2024
+ let chat_id1 = create_group_chat ( alice , ProtectionStatus :: Unprotected , "a" ) . await ?;
2025
+ send_text_msg ( alice , chat_id1, "msg one" . to_string ( ) ) . await ?;
2026
+ let bob_id = alice . add_or_lookup_contact_id ( bob) . await ;
2027
+ add_contact_to_chat ( alice , chat_id1, bob_id) . await ?;
2028
+ let msg1 = alice . get_last_msg_in ( chat_id1) . await ;
2018
2029
assert ! ( msg1. is_info( ) ) ;
2019
2030
assert ! ( msg1
. get_text
( ) . contains
( "[email protected] " ) ) ;
2020
2031
2021
- let chat_id2 = ChatId :: create_for_contact ( & t , bob_id) . await ?;
2022
- assert_eq ! ( get_chat_msgs( & t , chat_id2) . await ?. len( ) , 0 ) ;
2023
- forward_msgs ( & t , & [ msg1. id ] , chat_id2) . await ?;
2024
- let msg2 = t . get_last_msg_in ( chat_id2) . await ;
2032
+ let chat_id2 = ChatId :: create_for_contact ( alice , bob_id) . await ?;
2033
+ assert_eq ! ( get_chat_msgs( alice , chat_id2) . await ?. len( ) , 0 ) ;
2034
+ forward_msgs ( alice , & [ msg1. id ] , chat_id2) . await ?;
2035
+ let msg2 = alice . get_last_msg_in ( chat_id2) . await ;
2025
2036
assert ! ( !msg2. is_info( ) ) ; // forwarded info-messages lose their info-state
2026
2037
assert_eq ! ( msg2. get_info_type( ) , SystemMessage :: Unknown ) ;
2027
2038
assert_ne ! ( msg2. from_id, ContactId :: INFO ) ;
@@ -3328,9 +3339,10 @@ async fn test_add_member_bug() -> Result<()> {
3328
3339
3329
3340
let alice = & tcm. alice ( ) . await ;
3330
3341
let bob = & tcm. bob ( ) . await ;
3342
+ let fiona = & tcm. fiona ( ) . await ;
3331
3343
3332
- let alice_bob_contact_id =
Contact :: create ( alice
, "Bob" , "[email protected] " ) . await ? ;
3333
- let alice_fiona_contact_id =
Contact :: create ( alice
, "Fiona" , "[email protected] " ) . await ? ;
3344
+ let alice_bob_contact_id = alice. add_or_lookup_contact_id ( bob ) . await ;
3345
+ let alice_fiona_contact_id = alice. add_or_lookup_contact_id ( fiona ) . await ;
3334
3346
3335
3347
// Create a group.
3336
3348
let alice_chat_id =
@@ -3506,11 +3518,15 @@ async fn test_expire_past_members_after_60_days() -> Result<()> {
3506
3518
/// Test that past members are ordered by the timestamp of their removal.
3507
3519
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
3508
3520
async fn test_past_members_order ( ) -> Result < ( ) > {
3509
- let t = & TestContext :: new_alice ( ) . await ;
3521
+ let mut tcm = TestContextManager :: new ( ) ;
3522
+ let t = & tcm. alice ( ) . await ;
3510
3523
3511
- let bob_contact_id =
Contact :: create ( t
, "Bob" , "[email protected] " ) . await ?
;
3512
- let charlie_contact_id =
Contact :: create ( t
, "Charlie" , "[email protected] " ) . await ?
;
3513
- let fiona_contact_id =
Contact :: create ( t
, "Fiona" , "[email protected] " ) . await ?
;
3524
+ let bob = tcm. bob ( ) . await ;
3525
+ let bob_contact_id = t. add_or_lookup_contact_id ( & bob) . await ;
3526
+ let charlie = tcm. charlie ( ) . await ;
3527
+ let charlie_contact_id = t. add_or_lookup_contact_id ( & charlie) . await ;
3528
+ let fiona = tcm. fiona ( ) . await ;
3529
+ let fiona_contact_id = t. add_or_lookup_contact_id ( & fiona) . await ;
3514
3530
3515
3531
let chat_id = create_group_chat ( t, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
3516
3532
add_contact_to_chat ( t, chat_id, bob_contact_id) . await ?;
0 commit comments