diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index 2c81f1caaca..440d1a9030d 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -14,8 +14,8 @@ use matrix_sdk_test::{ async_test, mocks::{mock_encryption_state, mock_redaction}, test_json::{self, sync::CUSTOM_ROOM_POWER_LEVELS}, - EphemeralTestEvent, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, - DEFAULT_TEST_ROOM_ID, + EphemeralTestEvent, GlobalAccountDataTestEvent, JoinedRoomBuilder, StateTestEvent, + SyncResponseBuilder, DEFAULT_TEST_ROOM_ID, }; use ruma::{ api::client::{membership::Invite3pidInit, receipt::create_receipt::v3::ReceiptType}, @@ -635,7 +635,8 @@ async fn test_call_notifications_ring_for_dms() { let (client, server) = logged_in_client_with_server().await; let mut sync_builder = SyncResponseBuilder::new(); - sync_builder.add_joined_room(JoinedRoomBuilder::default()); + let room_builder = JoinedRoomBuilder::default().add_state_event(StateTestEvent::PowerLevels); + sync_builder.add_joined_room(room_builder); sync_builder.add_global_account_data_event(GlobalAccountDataTestEvent::Direct); mock_sync(&server, sync_builder.build_json_sync_response(), None).await; @@ -678,9 +679,10 @@ async fn test_call_notifications_notify_for_rooms() { let (client, server) = logged_in_client_with_server().await; let mut sync_builder = SyncResponseBuilder::new(); - sync_builder.add_joined_room(JoinedRoomBuilder::default()); - + let room_builder = JoinedRoomBuilder::default().add_state_event(StateTestEvent::PowerLevels); + sync_builder.add_joined_room(room_builder); mock_sync(&server, sync_builder.build_json_sync_response(), None).await; + mock_encryption_state(&server, false).await; let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); @@ -715,6 +717,41 @@ async fn test_call_notifications_notify_for_rooms() { room.send_call_notification_if_needed().await.unwrap(); } +#[async_test] +async fn test_call_notifications_dont_notify_room_without_mention_powerlevel() { + let (client, server) = logged_in_client_with_server().await; + + let mut sync_builder = SyncResponseBuilder::new(); + let mut power_level_event = StateTestEvent::PowerLevels.into_json_value(); + // Allow noone to send room notify events. + *power_level_event.get_mut("content").unwrap().get_mut("notifications").unwrap() = + json!({"room": 101}); + + sync_builder.add_joined_room( + JoinedRoomBuilder::default().add_state_event(StateTestEvent::Custom(power_level_event)), + ); + + mock_sync(&server, sync_builder.build_json_sync_response(), None).await; + mock_encryption_state(&server, false).await; + + let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); + let _response = client.sync_once(sync_settings).await.unwrap(); + + let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap(); + assert!(!room.is_direct().await.unwrap()); + assert!(!room.has_active_room_call()); + + Mock::given(method("PUT")) + .and(path_regex(r"^/_matrix/client/r0/rooms/.*/send/.*")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({"event_id": "$event_id"}))) + // Expect no calls of the send because we dont have permission to notify. + .expect(0) + .mount(&server) + .await; + + room.send_call_notification_if_needed().await.unwrap(); +} + #[async_test] async fn test_make_reply_event_doesnt_require_event_cache() { // Even if we don't have enabled the event cache, we'll resort to using the diff --git a/testing/matrix-sdk-test/src/test_json/sync_events.rs b/testing/matrix-sdk-test/src/test_json/sync_events.rs index e5f5d824b29..df68df07bc9 100644 --- a/testing/matrix-sdk-test/src/test_json/sync_events.rs +++ b/testing/matrix-sdk-test/src/test_json/sync_events.rs @@ -350,6 +350,9 @@ pub static POWER_LEVELS: Lazy = Lazy::new(|| { "kick": 50, "redact": 50, "state_default": 50, + "notifications": { + "room": 0 + }, "users": { "@example:localhost": 100, "@bob:localhost": 0