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 1 commit
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
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/src/room_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ 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),
notification_mode: room.notification_mode(true).await.map(Into::into),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really clear what (true) means as an argument list for .notification_mode(). Maybe we should have separate notification_mode and user_defined_notification_mode or notification_mode and effective_notification_mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added a separate user_defined_notification_mode() function.

})
}
}
8 changes: 6 additions & 2 deletions crates/matrix-sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,11 @@ impl Room {
}

/// Get the notification mode
pub async fn notification_mode(&self) -> Option<RoomNotificationMode> {
///
/// # Arguments
///
/// * `user_defined_only` - Whether to get only the user-defined mode.
pub async fn notification_mode(&self, user_defined_only: bool) -> Option<RoomNotificationMode> {
if !matches!(self.state(), RoomState::Joined) {
return None;
}
Expand All @@ -2371,7 +2375,7 @@ impl Room {
// Get the user-defined mode if available
let notification_mode =
notification_settings.get_user_defined_room_notification_mode(self.room_id()).await;
if notification_mode.is_some() {
if user_defined_only || notification_mode.is_some() {
notification_mode
} else if let Ok(is_encrypted) = self.is_encrypted().await {
// Otherwise, if encrypted status is available, get the default mode for this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn get_notification_mode() {
// Joined room with a user-defined rule
let room = client.get_room(room_id).unwrap();
assert_eq!(room.state(), RoomState::Joined);
let mode = room.notification_mode().await;
let mode = room.notification_mode(false).await;
assert_matches!(mode, Some(RoomNotificationMode::AllMessages));

// Joined room without user-defined rules
Expand All @@ -63,12 +63,15 @@ async fn get_notification_mode() {

let room = client.get_room(room_no_rules_id).unwrap();
assert_eq!(room.state(), RoomState::Joined);
let mode = room.notification_mode().await;
let mode = room.notification_mode(false).await;
assert_matches!(mode, Some(RoomNotificationMode::MentionsAndKeywordsOnly));

let mode = room.notification_mode(true).await;
assert_matches!(mode, None);

// Room not joined
let room = client.get_room(room_not_joined_id).unwrap();
assert_eq!(room.state(), RoomState::Invited);
let mode = room.notification_mode().await;
let mode = room.notification_mode(false).await;
assert_eq!(mode, None);
}