@@ -553,9 +553,9 @@ async fn subscribe_loop(
553
553
mod tests {
554
554
use super :: * ;
555
555
use crate :: {
556
- chat:: send_msg,
556
+ chat:: { self , add_contact_to_chat , resend_msgs , send_msg, ChatId , ProtectionStatus } ,
557
557
message:: { Message , Viewtype } ,
558
- test_utils:: TestContextManager ,
558
+ test_utils:: { TestContext , TestContextManager } ,
559
559
EventType ,
560
560
} ;
561
561
@@ -919,8 +919,30 @@ mod tests {
919
919
let alice = & mut tcm. alice ( ) . await ;
920
920
let bob = & mut tcm. bob ( ) . await ;
921
921
922
+ let chat = alice. create_chat ( & bob) . await . id ;
923
+
924
+ let mut instance = Message :: new ( Viewtype :: File ) ;
925
+ instance
926
+ . set_file_from_bytes (
927
+ alice,
928
+ "minimal.xdc" ,
929
+ include_bytes ! ( "../test-data/webxdc/minimal.xdc" ) ,
930
+ None ,
931
+ )
932
+ . unwrap ( ) ;
933
+ connect_alice_bob ( alice, bob, chat, & mut instance) . await
934
+ }
935
+
936
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
937
+ async fn test_webxdc_resend ( ) {
938
+ let mut tcm = TestContextManager :: new ( ) ;
939
+ let alice = & mut tcm. alice ( ) . await ;
940
+ let bob = & mut tcm. bob ( ) . await ;
941
+ let group = chat:: create_group_chat ( & alice, ProtectionStatus :: Unprotected , "" )
942
+ . await
943
+ . unwrap ( ) ;
944
+
922
945
// Alice sends webxdc to bob
923
- let alice_chat = alice. create_chat ( bob) . await ;
924
946
let mut instance = Message :: new ( Viewtype :: File ) ;
925
947
instance
926
948
. set_file_from_bytes (
@@ -930,7 +952,58 @@ mod tests {
930
952
None ,
931
953
)
932
954
. unwrap ( ) ;
933
- send_msg ( alice, alice_chat. id , & mut instance) . await . unwrap ( ) ;
955
+
956
+ connect_alice_bob ( alice, bob, group, & mut instance) . await ;
957
+
958
+ // fiona joins late
959
+ let fiona = & mut tcm. fiona ( ) . await ;
960
+ add_contact_to_chat ( & alice, group, alice. add_or_lookup_contact_id ( & bob) . await )
961
+ . await
962
+ . unwrap ( ) ;
963
+
964
+ add_contact_to_chat ( & alice, group, alice. add_or_lookup_contact_id ( & fiona) . await )
965
+ . await
966
+ . unwrap ( ) ;
967
+
968
+ resend_msgs ( & alice, & [ instance. id ] ) . await . unwrap ( ) ;
969
+ let msg = alice. pop_sent_msg ( ) . await ;
970
+ let fiona_instance = fiona. recv_msg ( & msg) . await . id ;
971
+
972
+ let fiona_connect_future = send_webxdc_realtime_advertisement ( & fiona, fiona_instance)
973
+ . await
974
+ . unwrap ( )
975
+ . unwrap ( ) ;
976
+ let fiona_advert = fiona. pop_sent_msg ( ) . await ;
977
+ alice. recv_msg_trash ( & fiona_advert) . await ;
978
+
979
+ fiona_connect_future. await . unwrap ( ) ;
980
+ send_webxdc_realtime_data ( alice, instance. id , b"alice -> bob & fiona" . into ( ) )
981
+ . await
982
+ . unwrap ( ) ;
983
+
984
+ eprintln ! ( "Waiting for ephemeral message" ) ;
985
+ loop {
986
+ let event = fiona. evtracker . recv ( ) . await . unwrap ( ) ;
987
+ if let EventType :: WebxdcRealtimeData { data, .. } = event. typ {
988
+ if data == b"alice -> bob & fiona" {
989
+ break ;
990
+ } else {
991
+ panic ! (
992
+ "Unexpected status update: {}" ,
993
+ String :: from_utf8_lossy( & data)
994
+ ) ;
995
+ }
996
+ }
997
+ }
998
+ }
999
+
1000
+ async fn connect_alice_bob (
1001
+ alice : & mut TestContext ,
1002
+ bob : & mut TestContext ,
1003
+ chat : ChatId ,
1004
+ instance : & mut Message ,
1005
+ ) {
1006
+ send_msg ( alice, chat, instance) . await . unwrap ( ) ;
934
1007
let alice_webxdc = alice. get_last_msg ( ) . await ;
935
1008
936
1009
let webxdc = alice. pop_sent_msg ( ) . await ;
0 commit comments