@@ -5,13 +5,15 @@ use serde_json::json;
55
66use super :: * ;
77use crate :: chat:: {
8- ChatId , MuteDuration , add_contact_to_chat, create_broadcast, create_group, forward_msgs,
9- remove_contact_from_chat, resend_msgs, send_msg, send_text_msg, set_muted,
8+ ChatId , MuteDuration , add_contact_to_chat, add_contact_to_chat_ex, create_broadcast,
9+ create_group, forward_msgs, remove_contact_from_chat, resend_msgs, send_msg, send_text_msg,
10+ set_muted,
1011} ;
1112use crate :: chatlist:: Chatlist ;
1213use crate :: config:: Config ;
1314use crate :: ephemeral;
1415use crate :: receive_imf:: receive_imf;
16+ use crate :: sync:: Sync ;
1517use crate :: test_utils:: { E2EE_INFO_MSGS , TestContext , TestContextManager } ;
1618use crate :: tools:: { self , SystemTime } ;
1719use crate :: { message, sql} ;
@@ -2195,3 +2197,75 @@ async fn test_self_addr_consistency() -> Result<()> {
21952197 assert_eq ! ( db_msg. get_webxdc_self_addr( alice) . await ?, self_addr) ;
21962198 Ok ( ( ) )
21972199}
2200+
2201+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2202+ async fn test_webxdc_info_fields ( ) -> Result < ( ) > {
2203+ let mut tcm = TestContextManager :: new ( ) ;
2204+ let alice = tcm. alice ( ) . await ;
2205+ let bob = tcm. bob ( ) . await ;
2206+
2207+ alice. set_config ( Config :: Displayname , Some ( "alice" ) ) . await ?;
2208+ bob. set_config ( Config :: Displayname , Some ( "bob" ) ) . await ?;
2209+
2210+ // Alice sends webxdc in a group chat
2211+ let alice_grp = create_group ( & alice, "Alice & Bob" ) . await ?;
2212+ add_contact_to_chat (
2213+ & alice,
2214+ alice_grp,
2215+ alice. add_or_lookup_contact_id ( & bob) . await ,
2216+ )
2217+ . await ?;
2218+ let alice_instance = send_webxdc_instance ( & alice, alice_grp) . await ?;
2219+ let sent = alice. pop_sent_msg ( ) . await ;
2220+
2221+ let alice_info = alice_instance. get_webxdc_info ( & alice) . await ?;
2222+ assert_eq ! ( alice_info. self_addr, alice_info. app_sender_addr) ;
2223+ assert ! ( !alice_info. can_only_send_updates_to_app_sender) ;
2224+
2225+ // Bob receives it
2226+ let bob_instance = bob. recv_msg ( & sent) . await ;
2227+ let bob_info = bob_instance. get_webxdc_info ( & bob) . await ?;
2228+
2229+ assert_ne ! ( bob_info. self_addr, bob_info. app_sender_addr) ;
2230+ assert_eq ! ( bob_info. app_sender_addr, alice_info. app_sender_addr) ;
2231+ assert ! ( !bob_info. can_only_send_updates_to_app_sender) ;
2232+
2233+ // Now testing broadcast chat
2234+ let alice_broadcast = create_broadcast ( & alice, "Broadcast" . to_string ( ) ) . await ?;
2235+ add_contact_to_chat_ex (
2236+ & alice,
2237+ Sync :: Sync ,
2238+ alice_broadcast,
2239+ alice. add_or_lookup_contact_id ( & bob) . await ,
2240+ true ,
2241+ )
2242+ . await ?;
2243+ let sent_join = alice. pop_sent_msg ( ) . await ;
2244+
2245+ let alice_broadcast_instance = send_webxdc_instance ( & alice, alice_broadcast) . await ?;
2246+ let sent_app_broadcast = alice. pop_sent_msg ( ) . await ;
2247+
2248+ let alice_broadcast_info = alice_broadcast_instance. get_webxdc_info ( & alice) . await ?;
2249+ assert_eq ! (
2250+ alice_broadcast_info. self_addr,
2251+ alice_broadcast_info. app_sender_addr
2252+ ) ;
2253+ assert ! ( alice_broadcast_info. can_only_send_updates_to_app_sender) ;
2254+
2255+ // Bob receives broadcast webxdc
2256+ bob. recv_msg ( & sent_join) . await ;
2257+ let bob_broadcast_instance = bob. recv_msg ( & sent_app_broadcast) . await ;
2258+ let bob_broadcast_info = bob_broadcast_instance. get_webxdc_info ( & bob) . await ?;
2259+
2260+ assert_ne ! (
2261+ bob_broadcast_info. self_addr,
2262+ bob_broadcast_info. app_sender_addr
2263+ ) ;
2264+ assert_eq ! (
2265+ bob_broadcast_info. app_sender_addr,
2266+ alice_broadcast_info. app_sender_addr
2267+ ) ;
2268+ assert ! ( bob_broadcast_info. can_only_send_updates_to_app_sender) ;
2269+
2270+ Ok ( ( ) )
2271+ }
0 commit comments