@@ -9,20 +9,18 @@ use matrix_sdk::{
9
9
room:: { edit:: EditedContent , Receipts , ReportedContentScore , RoomMemberRole } ,
10
10
test_utils:: events:: EventFactory ,
11
11
} ;
12
- use matrix_sdk_base:: RoomState ;
12
+ use matrix_sdk_base:: { deserialized_responses :: AnySyncOrStrippedState , RoomState } ;
13
13
use matrix_sdk_test:: {
14
- async_test, test_json,
15
- test_json:: sync:: { CUSTOM_ROOM_POWER_LEVELS , LIVE_LOCATION_SHARING_SYNC } ,
16
- EphemeralTestEvent , GlobalAccountDataTestEvent , JoinedRoomBuilder , SyncResponseBuilder ,
17
- DEFAULT_TEST_ROOM_ID ,
14
+ async_test, test_json, test_json:: sync:: CUSTOM_ROOM_POWER_LEVELS , EphemeralTestEvent ,
15
+ GlobalAccountDataTestEvent , JoinedRoomBuilder , SyncResponseBuilder , DEFAULT_TEST_ROOM_ID ,
18
16
} ;
19
17
use ruma:: {
20
18
api:: client:: { membership:: Invite3pidInit , receipt:: create_receipt:: v3:: ReceiptType } ,
21
19
assign, event_id,
22
20
events:: {
23
21
receipt:: ReceiptThread ,
24
22
room:: message:: { RoomMessageEventContent , RoomMessageEventContentWithoutRelation } ,
25
- StateEventType , TimelineEventType ,
23
+ AnySyncStateEvent , StateEventType , TimelineEventType ,
26
24
} ,
27
25
int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, OwnedUserId , TransactionId ,
28
26
} ;
@@ -782,16 +780,85 @@ async fn test_start_live_location_share_for_room() {
782
780
. mount ( & server)
783
781
. await ;
784
782
783
+ // Initial Sync with no beacon information
785
784
mock_sync ( & server, & * test_json:: SYNC , None ) . await ;
786
785
787
786
let sync_settings = SyncSettings :: new ( ) . timeout ( Duration :: from_millis ( 3000 ) ) ;
788
787
789
- let _response = client. sync_once ( sync_settings) . await . unwrap ( ) ;
788
+ let _response = client. sync_once ( sync_settings. clone ( ) ) . await . unwrap ( ) ;
790
789
791
790
let room = client. get_room ( & DEFAULT_TEST_ROOM_ID ) . unwrap ( ) ;
792
791
793
- let response = room. start_live_location_share ( 3000 , None ) . await . unwrap ( ) ;
792
+ let response =
793
+ room. start_live_location_share ( 3000 , Some ( "Live Share" . to_owned ( ) ) ) . await . unwrap ( ) ;
794
+
795
+ // Verify the event is correctly sent.
794
796
assert_eq ! ( event_id!( "$h29iv0s8:example.com" ) , response. event_id) ;
797
+ server. reset ( ) . await ;
798
+
799
+ mock_sync (
800
+ & server,
801
+ json ! ( {
802
+ "next_batch" : "s526_47314_0_7_1_1_1_1_1" ,
803
+ "rooms" : {
804
+ "join" : {
805
+ * DEFAULT_TEST_ROOM_ID : {
806
+ "state" : {
807
+ "events" : [
808
+ {
809
+ "content" : {
810
+ "description" : "Live Share" ,
811
+ "live" : true ,
812
+ "org.matrix.msc3488.ts" : 1436829458432_u64 ,
813
+ "timeout" : 3000 ,
814
+ "org.matrix.msc3488.asset" : { "type" : "m.self" }
815
+ } ,
816
+ "event_id" : "$15139375514XsgmR:localhost" ,
817
+ "origin_server_ts" : 151393755000000_u64 ,
818
+ "sender" : "@example:localhost" ,
819
+ "state_key" : "@example:localhost" ,
820
+ "type" : "org.matrix.msc3672.beacon_info" ,
821
+ "unsigned" : {
822
+ "age" : 7034220
823
+ }
824
+ } ,
825
+ ]
826
+ }
827
+ }
828
+ }
829
+ }
830
+
831
+ } ) ,
832
+ None ,
833
+ )
834
+ . await ;
835
+
836
+ let _response = client. sync_once ( sync_settings. clone ( ) ) . await . unwrap ( ) ;
837
+ server. reset ( ) . await ;
838
+
839
+ // Verify the event is correctly processed in the state store.
840
+ let state_events = room. get_state_events ( StateEventType :: BeaconInfo ) . await . unwrap ( ) ;
841
+ assert_eq ! ( state_events. len( ) , 1 ) ;
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
+ }
795
862
}
796
863
797
864
#[ async_test]
@@ -805,7 +872,42 @@ async fn test_stop_sharing_live_location() {
805
872
. mount ( & server)
806
873
. await ;
807
874
808
- mock_sync ( & server, & * LIVE_LOCATION_SHARING_SYNC , None ) . await ;
875
+ mock_sync (
876
+ & server,
877
+ json ! ( {
878
+ "next_batch" : "s526_47314_0_7_1_1_1_1_1" ,
879
+ "rooms" : {
880
+ "join" : {
881
+ * DEFAULT_TEST_ROOM_ID : {
882
+ "state" : {
883
+ "events" : [
884
+ {
885
+ "content" : {
886
+ "description" : "Live Share" ,
887
+ "live" : true ,
888
+ "org.matrix.msc3488.ts" : 1436829458432_u64 ,
889
+ "timeout" : 86400000 ,
890
+ "org.matrix.msc3488.asset" : { "type" : "m.self" }
891
+ } ,
892
+ "event_id" : "$15139375514XsgmR:localhost" ,
893
+ "origin_server_ts" : 151393755000000_u64 ,
894
+ "sender" : "@example:localhost" ,
895
+ "state_key" : "@example:localhost" ,
896
+ "type" : "org.matrix.msc3672.beacon_info" ,
897
+ "unsigned" : {
898
+ "age" : 7034220
899
+ }
900
+ } ,
901
+ ]
902
+ }
903
+ }
904
+ }
905
+ }
906
+
907
+ } ) ,
908
+ None ,
909
+ )
910
+ . await ;
809
911
810
912
let sync_settings = SyncSettings :: new ( ) . timeout ( Duration :: from_millis ( 3000 ) ) ;
811
913
0 commit comments