Skip to content

ffi: RoomInfo notification mode must reflect the user-defined mode #2545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bindings/matrix-sdk-ffi/src/room_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct RoomInfo {
joined_members_count: u64,
highlight_count: u64,
notification_count: u64,
notification_mode: Option<RoomNotificationMode>,
user_defined_notification_mode: Option<RoomNotificationMode>,
}

impl RoomInfo {
Expand Down Expand Up @@ -63,7 +63,10 @@ impl RoomInfo {
joined_members_count: room.joined_members_count(),
highlight_count: unread_notification_counts.highlight_count,
notification_count: unread_notification_counts.notification_count,
notification_mode: room.notification_mode().await.map(Into::into),
user_defined_notification_mode: room
.user_defined_notification_mode()
.await
.map(Into::into),
})
}
}
11 changes: 11 additions & 0 deletions crates/matrix-sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,17 @@ impl Room {
None
}
}

/// Get the user-defined notification mode
pub async fn user_defined_notification_mode(&self) -> Option<RoomNotificationMode> {
if !matches!(self.state(), RoomState::Joined) {
return None;
}
let notification_settings = self.client().notification_settings().await;

// Get the user-defined mode if available
notification_settings.get_user_defined_room_notification_mode(self.room_id()).await
}
}

/// Details of the (latest) invite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@ async fn get_notification_mode() {
.mount(&server)
.await;

// With a room without specific notification rules
let room = client.get_room(room_no_rules_id).unwrap();
assert_eq!(room.state(), RoomState::Joined);
// getting the mode should return the default one
let mode = room.notification_mode().await;
assert_matches!(mode, Some(RoomNotificationMode::MentionsAndKeywordsOnly));

// getting the user-defined mode must return None
let mode = room.user_defined_notification_mode().await;
assert_matches!(mode, None);

// Room not joined
let room = client.get_room(room_not_joined_id).unwrap();
assert_eq!(room.state(), RoomState::Invited);
Expand Down