@@ -27,15 +27,23 @@ use ruma::{
27
27
api:: client:: { membership:: Invite3pidInit , receipt:: create_receipt:: v3:: ReceiptType } ,
28
28
assign, event_id,
29
29
events:: {
30
+ call:: {
31
+ member:: {
32
+ ActiveFocus , ActiveLivekitFocus , Application , CallApplicationContent ,
33
+ CallMemberEventContent , CallScope ,
34
+ } ,
35
+ notify:: { ApplicationType , CallNotifyEventContent , NotifyType } ,
36
+ } ,
30
37
direct:: DirectUserIdentifier ,
31
38
receipt:: ReceiptThread ,
32
39
room:: {
33
40
member:: MembershipState ,
34
41
message:: { RoomMessageEventContent , RoomMessageEventContentWithoutRelation } ,
35
42
} ,
36
- RoomAccountDataEventType , TimelineEventType ,
43
+ Mentions , RoomAccountDataEventType , TimelineEventType ,
37
44
} ,
38
- int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, OwnedUserId , TransactionId ,
45
+ int, mxc_uri, owned_device_id, owned_event_id, room_id, thirdparty, user_id, OwnedUserId ,
46
+ TransactionId ,
39
47
} ;
40
48
use serde_json:: { from_value, json, Value } ;
41
49
use stream_assert:: assert_pending;
@@ -828,7 +836,8 @@ async fn test_call_notifications_ring_for_dms() {
828
836
. mount ( & server)
829
837
. await ;
830
838
831
- room. send_call_notification_if_needed ( ) . await . unwrap ( ) ;
839
+ let sent_event = room. send_call_notification_if_needed ( ) . await . unwrap ( ) ;
840
+ assert ! ( sent_event) ;
832
841
}
833
842
834
843
#[ async_test]
@@ -871,7 +880,8 @@ async fn test_call_notifications_notify_for_rooms() {
871
880
. mount ( & server)
872
881
. await ;
873
882
874
- room. send_call_notification_if_needed ( ) . await . unwrap ( ) ;
883
+ let sent_event = room. send_call_notification_if_needed ( ) . await . unwrap ( ) ;
884
+ assert ! ( sent_event) ;
875
885
}
876
886
877
887
#[ async_test]
@@ -906,7 +916,65 @@ async fn test_call_notifications_dont_notify_room_without_mention_powerlevel() {
906
916
. mount ( & server)
907
917
. await ;
908
918
909
- room. send_call_notification_if_needed ( ) . await . unwrap ( ) ;
919
+ let sent_event = room. send_call_notification_if_needed ( ) . await . unwrap ( ) ;
920
+ assert ! ( !sent_event) ;
921
+ }
922
+
923
+ #[ async_test]
924
+ async fn test_call_notifications_dont_notify_room_with_an_existing_call ( ) {
925
+ let ( client, server) = logged_in_client_with_server ( ) . await ;
926
+
927
+ let mut sync_builder = SyncResponseBuilder :: new ( ) ;
928
+ let event_factory = EventFactory :: new ( ) . room ( & DEFAULT_TEST_ROOM_ID ) ;
929
+ let call_notify_event = event_factory
930
+ . event ( CallNotifyEventContent :: new (
931
+ "call_id" . to_owned ( ) ,
932
+ ApplicationType :: Call ,
933
+ NotifyType :: Notify ,
934
+ Mentions :: new ( ) ,
935
+ ) )
936
+ . sender ( user_id ! ( "@alice:example.org" ) )
937
+ . into_raw_sync ( ) ;
938
+
939
+ let call_member_event = event_factory
940
+ . event ( CallMemberEventContent :: new (
941
+ Application :: Call ( CallApplicationContent :: new ( "call_id" . to_owned ( ) , CallScope :: Room ) ) ,
942
+ owned_device_id ! ( "a-device-id" ) ,
943
+ ActiveFocus :: Livekit ( ActiveLivekitFocus :: new ( ) ) ,
944
+ Vec :: new ( ) ,
945
+ None ,
946
+ ) )
947
+ . sender ( user_id ! ( "@alice:example.org" ) )
948
+ . state_key ( "_@alice:example.org_a-device-id" )
949
+ . into_raw_sync ( )
950
+ . cast ( ) ;
951
+
952
+ sync_builder. add_joined_room (
953
+ JoinedRoomBuilder :: default ( )
954
+ . add_timeline_bulk ( [ call_notify_event] )
955
+ . add_state_bulk ( [ call_member_event] ) ,
956
+ ) ;
957
+
958
+ mock_sync ( & server, sync_builder. build_json_sync_response ( ) , None ) . await ;
959
+ mock_encryption_state ( & server, false ) . await ;
960
+
961
+ let sync_settings = SyncSettings :: new ( ) . timeout ( Duration :: from_millis ( 3000 ) ) ;
962
+ let _response = client. sync_once ( sync_settings) . await . unwrap ( ) ;
963
+
964
+ let room = client. get_room ( & DEFAULT_TEST_ROOM_ID ) . unwrap ( ) ;
965
+ assert ! ( room. has_active_room_call( ) ) ;
966
+ assert ! ( !room. is_direct( ) . await . unwrap( ) ) ;
967
+
968
+ Mock :: given ( method ( "PUT" ) )
969
+ . and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/send/.*" ) )
970
+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( { "event_id" : "$event_id" } ) ) )
971
+ // Expect no calls of the send because we dont have permission to notify.
972
+ . expect ( 0 )
973
+ . mount ( & server)
974
+ . await ;
975
+
976
+ let sent_event = room. send_call_notification_if_needed ( ) . await . unwrap ( ) ;
977
+ assert ! ( !sent_event) ;
910
978
}
911
979
912
980
#[ async_test]
0 commit comments