@@ -4,7 +4,7 @@ use deltachat_contact_tools::EmailAddress;
44use regex:: Regex ;
55
66use super :: * ;
7- use crate :: chat:: { CantSendReason , add_contact_to_chat, remove_contact_from_chat} ;
7+ use crate :: chat:: { CantSendReason , ChatItem , add_contact_to_chat, remove_contact_from_chat} ;
88use crate :: chatlist:: Chatlist ;
99use crate :: constants:: Chattype ;
1010use crate :: constants:: DC_CHAT_ID_TRASH ;
@@ -1584,3 +1584,71 @@ async fn test_auth_token_is_synchronized() -> Result<()> {
15841584
15851585 Ok ( ( ) )
15861586}
1587+
1588+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
1589+ async fn test_channel_sync_message_reorder ( ) -> Result < ( ) > {
1590+ let mut tcm = TestContextManager :: new ( ) ;
1591+ let alice = & tcm. alice ( ) . await ;
1592+ let alice2 = & tcm. alice ( ) . await ;
1593+ let bob = & tcm. bob ( ) . await ;
1594+ bob. set_config ( Config :: Displayname , Some ( "Bob" ) )
1595+ . await
1596+ . unwrap ( ) ;
1597+
1598+ alice. set_config_bool ( Config :: SyncMsgs , true ) . await ?;
1599+ alice2. set_config_bool ( Config :: SyncMsgs , true ) . await ?;
1600+
1601+ let alice_chat_id = chat:: create_broadcast ( alice, "Channel" . to_string ( ) ) . await ?;
1602+ let qr = get_securejoin_qr ( alice, Some ( alice_chat_id) ) . await ?;
1603+ alice. send_sync_msg ( ) . await . unwrap ( ) ;
1604+ let sync_msg = alice. pop_sent_msg ( ) . await ;
1605+ alice2. recv_msg_trash ( & sync_msg) . await ;
1606+
1607+ tcm. section ( "Bob scans the QR code" ) ;
1608+ join_securejoin ( & bob, & qr) . await ?;
1609+
1610+ // vc-request-pubkey
1611+ let sent = bob. pop_sent_msg ( ) . await ;
1612+ alice. recv_msg_trash ( & sent) . await ;
1613+
1614+ // vc-pubkey
1615+ let sent = alice. pop_sent_msg ( ) . await ;
1616+ bob. recv_msg_trash ( & sent) . await ;
1617+
1618+ // vc-request-with-auth
1619+ let sent = bob. pop_sent_msg ( ) . await ;
1620+ alice. recv_msg_trash ( & sent) . await ;
1621+
1622+ // Alice sends to self a sync message about member addition.
1623+ alice. send_sync_msg ( ) . await . unwrap ( ) ;
1624+ let sync_msg = alice. pop_sent_msg ( ) . await ;
1625+ alice2. recv_msg_trash ( & sync_msg) . await ;
1626+
1627+ // Member added.
1628+ let sent = alice. pop_sent_msg ( ) . await ;
1629+ assert_eq ! ( sent. recipients, "bob@example.net alice@example.org" ) ;
1630+ bob. recv_msg ( & sent) . await ;
1631+
1632+ // Bob addition is already synced.
1633+ alice2. recv_msg_trash ( & sent) . await ;
1634+
1635+ let alice2_chatlist = Chatlist :: try_load ( alice2, 0 , None , None ) . await ?;
1636+ assert_eq ! ( alice2_chatlist. len( ) , 1 ) ;
1637+
1638+ let alice2_chat_id = alice2_chatlist. get_chat_id ( 0 ) ?;
1639+ let alice2_msgs = crate :: chat:: get_chat_msgs ( alice2, alice2_chat_id) . await ?;
1640+
1641+ assert_eq ! ( alice2_msgs. len( ) , 2 ) ;
1642+ let ChatItem :: Message { msg_id } = alice2_msgs[ 0 ] else {
1643+ panic ! ( "Wrong item type" ) ;
1644+ } ;
1645+ let msg1 = Message :: load_from_db ( alice2, msg_id) . await ?;
1646+ assert_eq ! ( msg1. text, "Messages are end-to-end encrypted." ) ;
1647+ let ChatItem :: Message { msg_id } = alice2_msgs[ 1 ] else {
1648+ panic ! ( "Wrong item type" ) ;
1649+ } ;
1650+ let msg2 = Message :: load_from_db ( alice2, msg_id) . await ?;
1651+ assert_eq ! ( msg2. text, "Member Bob added." ) ;
1652+
1653+ Ok ( ( ) )
1654+ }
0 commit comments