@@ -4,6 +4,7 @@ use std::{
4
4
} ;
5
5
6
6
use futures_util:: future:: join_all;
7
+ use js_int:: uint;
7
8
use matrix_sdk:: {
8
9
config:: SyncSettings ,
9
10
room:: { edit:: EditedContent , Receipts , ReportedContentScore , RoomMemberRole } ,
@@ -18,11 +19,13 @@ use ruma::{
18
19
api:: client:: { membership:: Invite3pidInit , receipt:: create_receipt:: v3:: ReceiptType } ,
19
20
assign, event_id,
20
21
events:: {
22
+ location:: AssetType ,
21
23
receipt:: ReceiptThread ,
22
24
room:: message:: { RoomMessageEventContent , RoomMessageEventContentWithoutRelation } ,
23
25
AnySyncStateEvent , StateEventType , TimelineEventType ,
24
26
} ,
25
- int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, OwnedUserId , TransactionId ,
27
+ int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, MilliSecondsSinceUnixEpoch ,
28
+ OwnedUserId , TransactionId ,
26
29
} ;
27
30
use serde_json:: { json, Value } ;
28
31
use wiremock:: {
@@ -780,19 +783,17 @@ async fn test_start_live_location_share_for_room() {
780
783
. mount ( & server)
781
784
. await ;
782
785
783
- // Initial Sync with no beacon information
784
- mock_sync ( & server, & * test_json:: SYNC , None ) . await ;
785
-
786
786
let sync_settings = SyncSettings :: new ( ) . timeout ( Duration :: from_millis ( 3000 ) ) ;
787
787
788
+ mock_sync ( & server, & * test_json:: SYNC , None ) . await ;
789
+
788
790
let _response = client. sync_once ( sync_settings. clone ( ) ) . await . unwrap ( ) ;
789
791
790
792
let room = client. get_room ( & DEFAULT_TEST_ROOM_ID ) . unwrap ( ) ;
791
793
792
794
let response =
793
795
room. start_live_location_share ( 3000 , Some ( "Live Share" . to_owned ( ) ) ) . await . unwrap ( ) ;
794
796
795
- // Verify the event is correctly sent.
796
797
assert_eq ! ( event_id!( "$h29iv0s8:example.com" ) , response. event_id) ;
797
798
server. reset ( ) . await ;
798
799
@@ -809,12 +810,12 @@ async fn test_start_live_location_share_for_room() {
809
810
"content" : {
810
811
"description" : "Live Share" ,
811
812
"live" : true ,
812
- "org.matrix.msc3488.ts" : 1436829458432_u64 ,
813
+ "org.matrix.msc3488.ts" : 1_636_829_458 ,
813
814
"timeout" : 3000 ,
814
815
"org.matrix.msc3488.asset" : { "type" : "m.self" }
815
816
} ,
816
817
"event_id" : "$15139375514XsgmR:localhost" ,
817
- "origin_server_ts" : 151393755000000_u64 ,
818
+ "origin_server_ts" : 1_636_829_458 ,
818
819
"sender" : "@example:localhost" ,
819
820
"state_key" : "@example:localhost" ,
820
821
"type" : "org.matrix.msc3672.beacon_info" ,
@@ -836,29 +837,30 @@ async fn test_start_live_location_share_for_room() {
836
837
let _response = client. sync_once ( sync_settings. clone ( ) ) . await . unwrap ( ) ;
837
838
server. reset ( ) . await ;
838
839
839
- // Verify the event is correctly processed in the state store.
840
840
let state_events = room. get_state_events ( StateEventType :: BeaconInfo ) . await . unwrap ( ) ;
841
841
assert_eq ! ( state_events. len( ) , 1 ) ;
842
842
843
- if let Some ( raw_event) = state_events. first ( ) {
844
- match raw_event. deserialize ( ) {
845
- Ok ( AnySyncOrStrippedState :: Sync ( AnySyncStateEvent :: BeaconInfo ( e) ) ) => {
846
- let content = e. as_original ( ) . unwrap ( ) . content . clone ( ) ;
847
- assert_eq ! ( e. sender( ) , room. own_user_id( ) ) ;
848
- assert_eq ! ( e. state_key( ) , "@example:localhost" ) ;
849
- assert_eq ! ( e. event_id( ) , event_id!( "$15139375514XsgmR:localhost" ) ) ;
850
-
851
- assert_eq ! ( content. description, Some ( "Live Share" . to_owned( ) ) ) ;
852
- assert_eq ! ( content. timeout, Duration :: from_millis( 3000 ) ) ;
853
- assert ! ( content. live) ;
854
- }
855
- _ => {
856
- panic ! ( "Expected a BeaconInfo event" ) ;
857
- }
858
- }
859
- } else {
860
- panic ! ( "There should be a beacon_info state event" ) ;
861
- }
843
+ let raw_event = state_events. first ( ) . expect ( "There should be a beacon_info state event" ) ;
844
+
845
+ let ev = match raw_event. deserialize ( ) . expect ( "Failed to deserialize event" ) {
846
+ AnySyncOrStrippedState :: Sync ( AnySyncStateEvent :: BeaconInfo ( ev) ) => ev,
847
+ _ => panic ! ( "Expected a BeaconInfo event" ) ,
848
+ } ;
849
+
850
+ let content = ev. as_original ( ) . unwrap ( ) . content . clone ( ) ;
851
+
852
+ assert_eq ! ( ev. sender( ) , room. own_user_id( ) ) ;
853
+ assert_eq ! ( ev. state_key( ) , "@example:localhost" ) ;
854
+ assert_eq ! ( ev. event_id( ) , event_id!( "$15139375514XsgmR:localhost" ) ) ;
855
+ assert_eq ! ( ev. event_type( ) , StateEventType :: BeaconInfo ) ;
856
+ assert_eq ! ( ev. origin_server_ts( ) , MilliSecondsSinceUnixEpoch ( uint!( 1_636_829_458 ) ) ) ;
857
+
858
+ assert_eq ! ( content. description, Some ( "Live Share" . to_owned( ) ) ) ;
859
+ assert_eq ! ( content. timeout, Duration :: from_millis( 3000 ) ) ;
860
+ assert_eq ! ( content. ts, MilliSecondsSinceUnixEpoch ( uint!( 1_636_829_458 ) ) ) ;
861
+ assert_eq ! ( content. asset. type_, AssetType :: Self_ ) ;
862
+
863
+ assert ! ( content. live) ;
862
864
}
863
865
864
866
#[ async_test]
@@ -872,6 +874,8 @@ async fn test_stop_sharing_live_location() {
872
874
. mount ( & server)
873
875
. await ;
874
876
877
+ let sync_settings = SyncSettings :: new ( ) . timeout ( Duration :: from_millis ( 3000 ) ) ;
878
+
875
879
mock_sync (
876
880
& server,
877
881
json ! ( {
@@ -885,12 +889,12 @@ async fn test_stop_sharing_live_location() {
885
889
"content" : {
886
890
"description" : "Live Share" ,
887
891
"live" : true ,
888
- "org.matrix.msc3488.ts" : 1436829458432_u64 ,
889
- "timeout" : 86400000 ,
892
+ "org.matrix.msc3488.ts" : 1_636_829_458 ,
893
+ "timeout" : 3000 ,
890
894
"org.matrix.msc3488.asset" : { "type" : "m.self" }
891
895
} ,
892
896
"event_id" : "$15139375514XsgmR:localhost" ,
893
- "origin_server_ts" : 151393755000000_u64 ,
897
+ "origin_server_ts" : 1_636_829_458 ,
894
898
"sender" : "@example:localhost" ,
895
899
"state_key" : "@example:localhost" ,
896
900
"type" : "org.matrix.msc3672.beacon_info" ,
@@ -909,16 +913,77 @@ async fn test_stop_sharing_live_location() {
909
913
)
910
914
. await ;
911
915
912
- let sync_settings = SyncSettings :: new ( ) . timeout ( Duration :: from_millis ( 3000 ) ) ;
913
-
914
- let _response = client. sync_once ( sync_settings) . await . unwrap ( ) ;
916
+ let _response = client. sync_once ( sync_settings. clone ( ) ) . await . unwrap ( ) ;
915
917
916
918
let room = client. get_room ( & DEFAULT_TEST_ROOM_ID ) . unwrap ( ) ;
917
919
918
920
let response = room. stop_live_location_share ( ) . await . unwrap ( ) ;
919
921
920
922
assert_eq ! ( event_id!( "$h29iv0s8:example.com" ) , response. event_id) ;
923
+ server. reset ( ) . await ;
924
+
925
+ mock_sync (
926
+ & server,
927
+ json ! ( {
928
+ "next_batch" : "s526_47314_1_7_1_1_1_1_1" ,
929
+ "rooms" : {
930
+ "join" : {
931
+ * DEFAULT_TEST_ROOM_ID : {
932
+ "state" : {
933
+ "events" : [
934
+ {
935
+ "content" : {
936
+ "description" : "Live Share" ,
937
+ "live" : false ,
938
+ "org.matrix.msc3488.ts" : 1_636_829_458 ,
939
+ "timeout" : 3000 ,
940
+ "org.matrix.msc3488.asset" : { "type" : "m.self" }
941
+ } ,
942
+ "event_id" : "$15139375514XsgmR:localhost" ,
943
+ "origin_server_ts" : 1_636_829_458 ,
944
+ "sender" : "@example:localhost" ,
945
+ "state_key" : "@example:localhost" ,
946
+ "type" : "org.matrix.msc3672.beacon_info" ,
947
+ "unsigned" : {
948
+ "age" : 7034220
949
+ }
950
+ } ,
951
+ ]
952
+ }
953
+ }
954
+ }
955
+ }
956
+
957
+ } ) ,
958
+ None ,
959
+ )
960
+ . await ;
961
+
962
+ let _response = client. sync_once ( sync_settings. clone ( ) ) . await . unwrap ( ) ;
963
+ server. reset ( ) . await ;
921
964
922
965
let state_events = room. get_state_events ( StateEventType :: BeaconInfo ) . await . unwrap ( ) ;
923
966
assert_eq ! ( state_events. len( ) , 1 ) ;
967
+
968
+ let raw_event = state_events. first ( ) . expect ( "There should be a beacon_info state event" ) ;
969
+
970
+ let ev = match raw_event. deserialize ( ) . expect ( "Failed to deserialize event" ) {
971
+ AnySyncOrStrippedState :: Sync ( AnySyncStateEvent :: BeaconInfo ( ev) ) => ev,
972
+ _ => panic ! ( "Expected a BeaconInfo event" ) ,
973
+ } ;
974
+
975
+ let content = ev. as_original ( ) . unwrap ( ) . content . clone ( ) ;
976
+
977
+ assert_eq ! ( ev. sender( ) , room. own_user_id( ) ) ;
978
+ assert_eq ! ( ev. state_key( ) , "@example:localhost" ) ;
979
+ assert_eq ! ( ev. event_id( ) , event_id!( "$15139375514XsgmR:localhost" ) ) ;
980
+ assert_eq ! ( ev. event_type( ) , StateEventType :: BeaconInfo ) ;
981
+ assert_eq ! ( ev. origin_server_ts( ) , MilliSecondsSinceUnixEpoch ( uint!( 1_636_829_458 ) ) ) ;
982
+
983
+ assert_eq ! ( content. description, Some ( "Live Share" . to_owned( ) ) ) ;
984
+ assert_eq ! ( content. timeout, Duration :: from_millis( 3000 ) ) ;
985
+ assert_eq ! ( content. ts, MilliSecondsSinceUnixEpoch ( uint!( 1_636_829_458 ) ) ) ;
986
+ assert_eq ! ( content. asset. type_, AssetType :: Self_ ) ;
987
+
988
+ assert ! ( !content. live) ;
924
989
}
0 commit comments