From cac010334a30645cbc6675b49d00bcaced4cdbab Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Thu, 24 Jul 2025 10:55:54 +0200 Subject: [PATCH 01/11] feat(push): add experimental support for MSC3768 (in-app-only notifications) Signed-off-by: Johannes Marbach --- Cargo.lock | 1 + bindings/matrix-sdk-ffi/CHANGELOG.md | 3 ++ bindings/matrix-sdk-ffi/Cargo.toml | 1 + .../src/notification_settings.rs | 27 ++++++++++-- crates/matrix-sdk-base/CHANGELOG.md | 3 ++ crates/matrix-sdk-base/Cargo.toml | 1 + .../src/notification_settings.rs | 8 +++- crates/matrix-sdk-ui/Cargo.toml | 4 ++ .../matrix-sdk-ui/src/notification_client.rs | 16 ++++++- crates/matrix-sdk/Cargo.toml | 3 ++ .../src/notification_settings/command.rs | 43 +++++++++++++------ .../src/notification_settings/mod.rs | 15 +++++-- .../notification_settings/rule_commands.rs | 23 +++++----- .../src/notification_settings/rules.rs | 42 ++++++++++++------ 14 files changed, 143 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d33fd1c2af..10d30c179e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3353,6 +3353,7 @@ dependencies = [ "async-stream", "async_cell", "bitflags", + "cfg-if", "chrono", "emojis", "eyeball", diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index c231d22428b..850f396148b 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -29,6 +29,9 @@ All notable changes to this project will be documented in this file. This is primarily for Element X to give a dedicated error message in case it connects a homeserver with only this method available. ([#5222](https://github.com/matrix-org/matrix-rust-sdk/pull/5222)) +- Add `Action::NotifyInApp` and `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind + a new feature `unstable-msc3768`. + ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441)) ### Breaking changes: diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index 36e9a75ec41..7b99979ce1f 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -26,6 +26,7 @@ crate-type = [ [features] default = ["bundled-sqlite", "unstable-msc4274"] bundled-sqlite = ["matrix-sdk/bundled-sqlite"] +unstable-msc3768 = ["matrix-sdk-ui/unstable-msc3768"] unstable-msc4274 = ["matrix-sdk-ui/unstable-msc4274"] # Required when targeting a Javascript environment, like Wasm in a browser. js = ["matrix-sdk-ui/js"] diff --git a/bindings/matrix-sdk-ffi/src/notification_settings.rs b/bindings/matrix-sdk-ffi/src/notification_settings.rs index 9cce328bfae..6ea827a406c 100644 --- a/bindings/matrix-sdk-ffi/src/notification_settings.rs +++ b/bindings/matrix-sdk-ffi/src/notification_settings.rs @@ -322,8 +322,13 @@ impl TryFrom for SdkTweak { #[derive(Clone, uniffi::Enum)] /// Enum representing the push notification actions for a rule. pub enum Action { - /// Causes matching events to generate a notification. + /// Causes matching events to generate a notification (both in-app and + /// remote / push). Notify, + /// Causes matching events to generate an in-app notification but no remote + /// / push notification. + #[cfg(feature = "unstable-msc3768")] + NotifyInApp, /// Sets an entry in the 'tweaks' dictionary sent to the push gateway. SetTweak { value: Tweak }, } @@ -334,6 +339,8 @@ impl TryFrom for Action { fn try_from(value: SdkAction) -> Result { Ok(match value { SdkAction::Notify => Self::Notify, + #[cfg(feature = "unstable-msc3768")] + SdkAction::NotifyInApp => Self::NotifyInApp, SdkAction::SetTweak(tweak) => Self::SetTweak { value: tweak.try_into().map_err(|e| format!("Failed to convert tweak: {e}"))?, }, @@ -348,6 +355,8 @@ impl TryFrom for SdkAction { fn try_from(value: Action) -> Result { Ok(match value { Action::Notify => Self::Notify, + #[cfg(feature = "unstable-msc3768")] + Action::NotifyInApp => Self::NotifyInApp, Action::SetTweak { value } => Self::SetTweak( value.try_into().map_err(|e| format!("Failed to convert tweak: {e}"))?, ), @@ -358,10 +367,14 @@ impl TryFrom for SdkAction { /// Enum representing the push notification modes for a room. #[derive(Clone, uniffi::Enum)] pub enum RoomNotificationMode { - /// Receive notifications for all messages. + /// Receive remote and in-app notifications for all messages. AllMessages, - /// Receive notifications for mentions and keywords only. + /// Receive remote and in-app notifications for mentions and keywords only. MentionsAndKeywordsOnly, + /// Receive remote and in-app notifications for mentions and keywords and + /// in-app notifications only for other room messages. + #[cfg(feature = "unstable-msc3768")] + MentionsAndKeywordsOnlyTheRestInApp, /// Do not receive any notifications. Mute, } @@ -371,6 +384,10 @@ impl From for RoomNotificationMode { match value { SdkRoomNotificationMode::AllMessages => Self::AllMessages, SdkRoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, + #[cfg(feature = "unstable-msc3768")] + SdkRoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { + Self::MentionsAndKeywordsOnlyTheRestInApp + } SdkRoomNotificationMode::Mute => Self::Mute, } } @@ -381,6 +398,10 @@ impl From for SdkRoomNotificationMode { match value { RoomNotificationMode::AllMessages => Self::AllMessages, RoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, + #[cfg(feature = "unstable-msc3768")] + RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { + Self::MentionsAndKeywordsOnlyTheRestInApp + } RoomNotificationMode::Mute => Self::Mute, } } diff --git a/crates/matrix-sdk-base/CHANGELOG.md b/crates/matrix-sdk-base/CHANGELOG.md index 0441ecef6ab..9a3292b2c31 100644 --- a/crates/matrix-sdk-base/CHANGELOG.md +++ b/crates/matrix-sdk-base/CHANGELOG.md @@ -18,6 +18,9 @@ All notable changes to this project will be documented in this file. `RoomInfo::invite_details` method returns both the timestamp and the inviter. ([#5390](https://github.com/matrix-org/matrix-rust-sdk/pull/5390)) +- Add `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind a new + feature `unstable-msc3768`. + ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441 ### Refactor - [**breaking**] `RelationalLinkedChunk::items` now takes a `RoomId` instead of an diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index a74665b096e..31fa5a739f1 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -28,6 +28,7 @@ qrcode = ["matrix-sdk-crypto?/qrcode"] automatic-room-key-forwarding = ["matrix-sdk-crypto?/automatic-room-key-forwarding"] experimental-send-custom-to-device = ["matrix-sdk-crypto?/experimental-send-custom-to-device"] uniffi = ["dep:uniffi", "matrix-sdk-crypto?/uniffi", "matrix-sdk-common/uniffi"] +unstable-msc3768 = ["ruma/unstable-msc3768"] # Private feature, see # https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823 for the gory diff --git a/crates/matrix-sdk-base/src/notification_settings.rs b/crates/matrix-sdk-base/src/notification_settings.rs index 8a733d1e607..b72bacabbbf 100644 --- a/crates/matrix-sdk-base/src/notification_settings.rs +++ b/crates/matrix-sdk-base/src/notification_settings.rs @@ -19,10 +19,14 @@ use serde::{Deserialize, Serialize}; /// Enum representing the push notification modes for a room. #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub enum RoomNotificationMode { - /// Receive notifications for all messages. + /// Receive remote and in-app notifications for all messages. AllMessages, - /// Receive notifications for mentions and keywords only. + /// Receive remote and in-app notifications for mentions and keywords only. MentionsAndKeywordsOnly, + /// Receive remote and in-app notifications for mentions and keywords and + /// in-app notifications only for other room messages. + #[cfg(feature = "unstable-msc3768")] + MentionsAndKeywordsOnlyTheRestInApp, /// Do not receive any notifications. Mute, } diff --git a/crates/matrix-sdk-ui/Cargo.toml b/crates/matrix-sdk-ui/Cargo.toml index ddacc9e1927..6310f6759f7 100644 --- a/crates/matrix-sdk-ui/Cargo.toml +++ b/crates/matrix-sdk-ui/Cargo.toml @@ -19,6 +19,9 @@ rustls-tls = ["matrix-sdk/rustls-tls"] js = ["matrix-sdk/js"] uniffi = ["dep:uniffi", "matrix-sdk/uniffi", "matrix-sdk-base/uniffi"] +# Add support for in-app only notifications +unstable-msc3768 = ["matrix-sdk/unstable-msc3768"] + # Add support for encrypted extensible events. unstable-msc3956 = ["ruma/unstable-msc3956"] @@ -58,6 +61,7 @@ tracing = { workspace = true, features = ["attributes"] } unicode-normalization.workspace = true uniffi = { workspace = true, optional = true } +cfg-if = "1.0.0" emojis = "0.6.4" unicode-segmentation = "1.12.0" diff --git a/crates/matrix-sdk-ui/src/notification_client.rs b/crates/matrix-sdk-ui/src/notification_client.rs index de960b87167..4472fcbd98b 100644 --- a/crates/matrix-sdk-ui/src/notification_client.rs +++ b/crates/matrix-sdk-ui/src/notification_client.rs @@ -18,6 +18,7 @@ use std::{ time::Duration, }; +use cfg_if::cfg_if; use futures_util::{StreamExt as _, pin_mut}; use matrix_sdk::{ Client, ClientBuildError, SlidingSyncList, SlidingSyncMode, room::Room, sleep::sleep, @@ -677,7 +678,7 @@ impl NotificationClient { let should_notify = push_actions .as_ref() - .is_some_and(|actions| actions.iter().any(|a| a.should_notify())); + .is_some_and(|actions| actions.iter().any(should_action_notify_remote)); if !should_notify { // The event has been filtered out by the user's push rules. @@ -749,7 +750,7 @@ impl NotificationClient { } if let Some(actions) = timeline_event.push_actions() - && !actions.iter().any(|a| a.should_notify()) + && !actions.iter().any(should_action_notify_remote) { return Ok(NotificationStatus::EventFilteredOut); } @@ -771,6 +772,17 @@ impl NotificationClient { } } +fn should_action_notify_remote(action: &Action) -> bool { + cfg_if! { + if #[cfg(feature = "unstable-msc3768")] { + action.should_notify_remote() + } else { + // Before MSC3768 only combined remote/local notifications existed + action.should_notify() + } + } +} + fn is_event_encrypted(event_type: TimelineEventType) -> bool { let is_still_encrypted = matches!(event_type, TimelineEventType::RoomEncrypted); diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index b1077fac54a..2dc63cd4e60 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -59,6 +59,9 @@ experimental-widgets = ["dep:uuid", "experimental-send-custom-to-device"] docsrs = ["e2e-encryption", "sqlite", "indexeddb", "sso-login", "qrcode"] +# Add support for in-app only notifications +unstable-msc3768 = ["matrix-sdk-base/unstable-msc3768"] + # Add support for inline media galleries via msgtypes unstable-msc4274 = ["ruma/unstable-msc4274", "matrix-sdk-base/unstable-msc4274"] diff --git a/crates/matrix-sdk/src/notification_settings/command.rs b/crates/matrix-sdk/src/notification_settings/command.rs index 65ce37b71c7..cb4afbd452a 100644 --- a/crates/matrix-sdk/src/notification_settings/command.rs +++ b/crates/matrix-sdk/src/notification_settings/command.rs @@ -14,9 +14,9 @@ use crate::NotificationSettingsError; #[derive(Clone, Debug)] pub(crate) enum Command { /// Set a new `Room` push rule - SetRoomPushRule { room_id: OwnedRoomId, notify: bool }, + SetRoomPushRule { room_id: OwnedRoomId, notify: Notify }, /// Set a new `Override` push rule matching a `RoomId` - SetOverridePushRule { rule_id: String, room_id: OwnedRoomId, notify: bool }, + SetOverridePushRule { rule_id: String, room_id: OwnedRoomId, notify: Notify }, /// Set a new push rule for a keyword. SetKeywordPushRule { keyword: String }, /// Set whether a push rule is enabled @@ -29,21 +29,13 @@ pub(crate) enum Command { SetCustomPushRule { rule: NewPushRule }, } -fn get_notify_actions(notify: bool) -> Vec { - if notify { - vec![Action::Notify, Action::SetTweak(Tweak::Sound("default".into()))] - } else { - vec![] - } -} - impl Command { /// Tries to create a push rule corresponding to this command pub(crate) fn to_push_rule(&self) -> Result { match self { Self::SetRoomPushRule { room_id, notify } => { // `Room` push rule for this `room_id` - let new_rule = NewSimplePushRule::new(room_id.clone(), get_notify_actions(*notify)); + let new_rule = NewSimplePushRule::new(room_id.clone(), notify.get_actions()); Ok(NewPushRule::Room(new_rule)) } @@ -55,7 +47,7 @@ impl Command { key: "room_id".to_owned(), pattern: room_id.to_string(), }], - get_notify_actions(*notify), + notify.get_actions(), ); Ok(NewPushRule::Override(new_rule)) } @@ -65,7 +57,7 @@ impl Command { let new_rule = NewPatternedPushRule::new( keyword.clone(), keyword.clone(), - get_notify_actions(true), + Notify::All.get_actions(), ); Ok(NewPushRule::Content(new_rule)) } @@ -80,3 +72,28 @@ impl Command { } } } + +/// Enum describing if and how to deliver a notification. +#[derive(Clone, Debug, Eq, PartialEq)] +pub(crate) enum Notify { + /// Generate a notification both in-app and remote / push. + All, + + /// Only generate an in-app notification but no remote / push notification. + #[cfg(feature = "unstable-msc3768")] + InAppOnly, + + /// Don't notify at all. + None, +} + +impl Notify { + fn get_actions(&self) -> Vec { + match self { + Self::All => vec![Action::Notify, Action::SetTweak(Tweak::Sound("default".into()))], + #[cfg(feature = "unstable-msc3768")] + Self::InAppOnly => vec![Action::NotifyInApp], + Self::None => vec![], + } + } +} diff --git a/crates/matrix-sdk/src/notification_settings/mod.rs b/crates/matrix-sdk/src/notification_settings/mod.rs index eebe73e951e..780260ed22b 100644 --- a/crates/matrix-sdk/src/notification_settings/mod.rs +++ b/crates/matrix-sdk/src/notification_settings/mod.rs @@ -41,7 +41,7 @@ pub use matrix_sdk_base::notification_settings::RoomNotificationMode; use crate::{ config::RequestConfig, error::NotificationSettingsError, event_handler::EventHandlerDropGuard, - Client, Result, + notification_settings::command::Notify, Client, Result, }; /// Whether or not a room is encrypted @@ -320,15 +320,20 @@ impl NotificationSettings { let (new_rule_kind, notify) = match mode { RoomNotificationMode::AllMessages => { // insert a `Room` rule which notifies - (RuleKind::Room, true) + (RuleKind::Room, Notify::All) } RoomNotificationMode::MentionsAndKeywordsOnly => { // insert a `Room` rule which doesn't notify - (RuleKind::Room, false) + (RuleKind::Room, Notify::None) + } + #[cfg(feature = "unstable-msc3768")] + RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { + // insert a `Room` rule which notifies in-app only + (RuleKind::Room, Notify::InAppOnly) } RoomNotificationMode::Mute => { // insert an `Override` rule which doesn't notify - (RuleKind::Override, false) + (RuleKind::Override, Notify::None) } }; @@ -923,6 +928,8 @@ mod tests { let new_modes = [ RoomNotificationMode::AllMessages, RoomNotificationMode::MentionsAndKeywordsOnly, + #[cfg(feature = "unstable-msc3768")] + RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp, RoomNotificationMode::Mute, ]; for new_mode in new_modes { diff --git a/crates/matrix-sdk/src/notification_settings/rule_commands.rs b/crates/matrix-sdk/src/notification_settings/rule_commands.rs index a545e23b94b..14e26d31836 100644 --- a/crates/matrix-sdk/src/notification_settings/rule_commands.rs +++ b/crates/matrix-sdk/src/notification_settings/rule_commands.rs @@ -7,7 +7,7 @@ use ruma::{ }; use super::command::Command; -use crate::NotificationSettingsError; +use crate::{notification_settings::command::Notify, NotificationSettingsError}; /// A `RuleCommand` allows to generate a list of `Command` needed to modify a /// `Ruleset` @@ -27,7 +27,7 @@ impl RuleCommands { &mut self, kind: RuleKind, room_id: &RoomId, - notify: bool, + notify: Notify, ) -> Result<(), NotificationSettingsError> { let command = match kind { RuleKind::Room => Command::SetRoomPushRule { room_id: room_id.to_owned(), notify }, @@ -210,7 +210,10 @@ mod tests { }; use super::RuleCommands; - use crate::{error::NotificationSettingsError, notification_settings::command::Command}; + use crate::{ + error::NotificationSettingsError, + notification_settings::command::{Command, Notify}, + }; fn get_server_default_ruleset() -> Ruleset { let user_id = UserId::parse("@user:matrix.org").unwrap(); @@ -225,7 +228,7 @@ mod tests { async fn test_insert_rule_room() { let room_id = get_test_room_id(); let mut rule_commands = RuleCommands::new(get_server_default_ruleset()); - rule_commands.insert_rule(RuleKind::Room, &room_id, true).unwrap(); + rule_commands.insert_rule(RuleKind::Room, &room_id, Notify::All).unwrap(); // A rule must have been inserted in the ruleset. assert!(rule_commands.rules.get(RuleKind::Room, &room_id).is_some()); @@ -235,7 +238,7 @@ mod tests { assert_matches!(&rule_commands.commands[0], Command::SetRoomPushRule { room_id: command_room_id, notify } => { assert_eq!(command_room_id, &room_id); - assert!(notify); + assert_eq!(&Notify::All, notify); } ); } @@ -244,7 +247,7 @@ mod tests { async fn test_insert_rule_override() { let room_id = get_test_room_id(); let mut rule_commands = RuleCommands::new(get_server_default_ruleset()); - rule_commands.insert_rule(RuleKind::Override, &room_id, true).unwrap(); + rule_commands.insert_rule(RuleKind::Override, &room_id, Notify::All).unwrap(); // A rule must have been inserted in the ruleset. assert!(rule_commands.rules.get(RuleKind::Override, &room_id).is_some()); @@ -255,7 +258,7 @@ mod tests { Command::SetOverridePushRule {room_id: command_room_id, rule_id, notify } => { assert_eq!(command_room_id, &room_id); assert_eq!(rule_id, room_id.as_str()); - assert!(notify); + assert_eq!(&Notify::All, notify); } ); } @@ -266,17 +269,17 @@ mod tests { let mut rule_commands = RuleCommands::new(get_server_default_ruleset()); assert_matches!( - rule_commands.insert_rule(RuleKind::Underride, &room_id, true), + rule_commands.insert_rule(RuleKind::Underride, &room_id, Notify::All), Err(NotificationSettingsError::InvalidParameter(_)) => {} ); assert_matches!( - rule_commands.insert_rule(RuleKind::Content, &room_id, true), + rule_commands.insert_rule(RuleKind::Content, &room_id, Notify::All), Err(NotificationSettingsError::InvalidParameter(_)) => {} ); assert_matches!( - rule_commands.insert_rule(RuleKind::Sender, &room_id, true), + rule_commands.insert_rule(RuleKind::Sender, &room_id, Notify::All), Err(NotificationSettingsError::InvalidParameter(_)) => {} ); } diff --git a/crates/matrix-sdk/src/notification_settings/rules.rs b/crates/matrix-sdk/src/notification_settings/rules.rs index 7a022c429e3..40ed48d76af 100644 --- a/crates/matrix-sdk/src/notification_settings/rules.rs +++ b/crates/matrix-sdk/src/notification_settings/rules.rs @@ -1,5 +1,6 @@ //! Ruleset utility struct +use cfg_if::cfg_if; use imbl::HashSet; use indexmap::IndexSet; use ruma::{ @@ -85,8 +86,16 @@ impl Rules { // Search for an enabled `Room` rule where `rule_id` is the `room_id` if let Some(rule) = self.ruleset.get(RuleKind::Room, room_id) { - // if this rule contains a `Notify` action if rule.triggers_notification() { + cfg_if! { + if #[cfg(feature = "unstable-msc3768")] { + if !rule.triggers_remote_notification() { + // This rule contains a `NotifyInApp` action. + return Some(RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp); + } + } + } + // This rule contains a `Notify` action. return Some(RoomNotificationMode::AllMessages); } return Some(RoomNotificationMode::MentionsAndKeywordsOnly); @@ -112,18 +121,24 @@ impl Rules { let predefined_rule_id = get_predefined_underride_room_rule_id(is_encrypted, is_one_to_one); let rule_id = predefined_rule_id.as_str(); - // If there is an `Underride` rule that should trigger a notification, the mode - // is `AllMessages` - if self - .ruleset - .get(RuleKind::Underride, rule_id) - .is_some_and(|r| r.enabled() && r.triggers_notification()) - { - RoomNotificationMode::AllMessages - } else { - // Otherwise, the mode is `MentionsAndKeywordsOnly` - RoomNotificationMode::MentionsAndKeywordsOnly + if let Some(rule) = self.ruleset.get(RuleKind::Underride, rule_id).filter(|r| r.enabled()) { + if rule.triggers_notification() { + cfg_if! { + if #[cfg(feature = "unstable-msc3768")] { + if !rule.triggers_remote_notification() { + // This rule contains a `NotifyInApp` action. + return RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp; + } + } + } + // If there is an `Underride` rule that should trigger a notification, the mode + // is `AllMessages` + return RoomNotificationMode::AllMessages; + } } + + // Otherwise, the mode is `MentionsAndKeywordsOnly` + RoomNotificationMode::MentionsAndKeywordsOnly } /// Get all room IDs for which a user-defined rule exists. @@ -330,6 +345,7 @@ pub(crate) mod tests { use crate::{ error::NotificationSettingsError, notification_settings::{ + command::Notify, rules::{self, Rules}, IsEncrypted, IsOneToOne, RoomNotificationMode, }, @@ -614,7 +630,7 @@ pub(crate) mod tests { // Build a `RuleCommands` inserting a rule let mut rules_commands = RuleCommands::new(rules.ruleset.clone()); - rules_commands.insert_rule(RuleKind::Override, &room_id, false).unwrap(); + rules_commands.insert_rule(RuleKind::Override, &room_id, Notify::None).unwrap(); rules.apply(rules_commands); From 8be28a11fc2318444ca5e6791e96b7be16982592 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 6 Aug 2025 14:46:00 +0200 Subject: [PATCH 02/11] Avoid macro expansion of `vec![]` Co-authored-by: Benjamin Bouvier Signed-off-by: Johannes Marbach --- crates/matrix-sdk/src/notification_settings/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/notification_settings/command.rs b/crates/matrix-sdk/src/notification_settings/command.rs index cb4afbd452a..743e9a49930 100644 --- a/crates/matrix-sdk/src/notification_settings/command.rs +++ b/crates/matrix-sdk/src/notification_settings/command.rs @@ -93,7 +93,7 @@ impl Notify { Self::All => vec![Action::Notify, Action::SetTweak(Tweak::Sound("default".into()))], #[cfg(feature = "unstable-msc3768")] Self::InAppOnly => vec![Action::NotifyInApp], - Self::None => vec![], + Self::None => Vec::new() } } } From ef96531cfc8f3cc4d70f94bee49c9acba114d703 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 6 Aug 2025 14:51:02 +0200 Subject: [PATCH 03/11] fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications) Flip assertions Signed-off-by: Johannes Marbach --- crates/matrix-sdk/src/notification_settings/rule_commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk/src/notification_settings/rule_commands.rs b/crates/matrix-sdk/src/notification_settings/rule_commands.rs index 14e26d31836..dd43ce3b43e 100644 --- a/crates/matrix-sdk/src/notification_settings/rule_commands.rs +++ b/crates/matrix-sdk/src/notification_settings/rule_commands.rs @@ -238,7 +238,7 @@ mod tests { assert_matches!(&rule_commands.commands[0], Command::SetRoomPushRule { room_id: command_room_id, notify } => { assert_eq!(command_room_id, &room_id); - assert_eq!(&Notify::All, notify); + assert_eq!(*notify, Notify::All); } ); } @@ -258,7 +258,7 @@ mod tests { Command::SetOverridePushRule {room_id: command_room_id, rule_id, notify } => { assert_eq!(command_room_id, &room_id); assert_eq!(rule_id, room_id.as_str()); - assert_eq!(&Notify::All, notify); + assert_eq!(*notify, Notify::All); } ); } From cd21783c92e646f2dd7c9e37880fbec580b8f7c7 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 6 Aug 2025 15:04:46 +0200 Subject: [PATCH 04/11] fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications) Eliminate cfg_if Signed-off-by: Johannes Marbach --- .../src/notification_settings/rules.rs | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/matrix-sdk/src/notification_settings/rules.rs b/crates/matrix-sdk/src/notification_settings/rules.rs index 40ed48d76af..7aac76de67f 100644 --- a/crates/matrix-sdk/src/notification_settings/rules.rs +++ b/crates/matrix-sdk/src/notification_settings/rules.rs @@ -1,6 +1,5 @@ //! Ruleset utility struct -use cfg_if::cfg_if; use imbl::HashSet; use indexmap::IndexSet; use ruma::{ @@ -87,14 +86,12 @@ impl Rules { // Search for an enabled `Room` rule where `rule_id` is the `room_id` if let Some(rule) = self.ruleset.get(RuleKind::Room, room_id) { if rule.triggers_notification() { - cfg_if! { - if #[cfg(feature = "unstable-msc3768")] { - if !rule.triggers_remote_notification() { - // This rule contains a `NotifyInApp` action. - return Some(RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp); - } - } + #[cfg(feature = "unstable-msc3768")] + if !rule.triggers_remote_notification() { + // This rule contains a `NotifyInApp` action. + return Some(RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp); } + // This rule contains a `Notify` action. return Some(RoomNotificationMode::AllMessages); } @@ -123,13 +120,10 @@ impl Rules { if let Some(rule) = self.ruleset.get(RuleKind::Underride, rule_id).filter(|r| r.enabled()) { if rule.triggers_notification() { - cfg_if! { - if #[cfg(feature = "unstable-msc3768")] { - if !rule.triggers_remote_notification() { - // This rule contains a `NotifyInApp` action. - return RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp; - } - } + #[cfg(feature = "unstable-msc3768")] + if !rule.triggers_remote_notification() { + // This rule contains a `NotifyInApp` action. + return RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp; } // If there is an `Underride` rule that should trigger a notification, the mode // is `AllMessages` From 3b158ab3f39258d4bcd3f465a3fd861304401852 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 6 Aug 2025 15:07:17 +0200 Subject: [PATCH 05/11] fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications) Reformat Signed-off-by: Johannes Marbach --- crates/matrix-sdk/src/notification_settings/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/notification_settings/command.rs b/crates/matrix-sdk/src/notification_settings/command.rs index 743e9a49930..5be61a1cc65 100644 --- a/crates/matrix-sdk/src/notification_settings/command.rs +++ b/crates/matrix-sdk/src/notification_settings/command.rs @@ -93,7 +93,7 @@ impl Notify { Self::All => vec![Action::Notify, Action::SetTweak(Tweak::Sound("default".into()))], #[cfg(feature = "unstable-msc3768")] Self::InAppOnly => vec![Action::NotifyInApp], - Self::None => Vec::new() + Self::None => Vec::new(), } } } From 6e3b7f6da03ad811f10e35212b2abcb10feafa14 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 6 Aug 2025 15:11:32 +0200 Subject: [PATCH 06/11] fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications) Make Notify Copy Signed-off-by: Johannes Marbach --- crates/matrix-sdk/src/notification_settings/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/notification_settings/command.rs b/crates/matrix-sdk/src/notification_settings/command.rs index 5be61a1cc65..12f9bfffc81 100644 --- a/crates/matrix-sdk/src/notification_settings/command.rs +++ b/crates/matrix-sdk/src/notification_settings/command.rs @@ -74,7 +74,7 @@ impl Command { } /// Enum describing if and how to deliver a notification. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub(crate) enum Notify { /// Generate a notification both in-app and remote / push. All, From deef9610d75d0d1b88423a800a1cabb1f74f29e2 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 6 Aug 2025 16:01:34 +0200 Subject: [PATCH 07/11] fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications) Combine the two enum variants Signed-off-by: Johannes Marbach --- bindings/matrix-sdk-ffi/CHANGELOG.md | 4 +- .../src/notification_settings.rs | 35 ++++++---- crates/matrix-sdk-base/CHANGELOG.md | 4 +- .../src/notification_settings.rs | 11 +-- .../src/notification_settings/mod.rs | 69 +++++++++++++++---- .../src/notification_settings/rules.rs | 29 ++++++-- crates/matrix-sdk/src/sliding_sync/client.rs | 5 +- .../integration/room/notification_mode.rs | 8 ++- .../src/tests/sliding_sync/room.rs | 2 +- 9 files changed, 119 insertions(+), 48 deletions(-) diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index 850f396148b..411ff48ef83 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -29,8 +29,8 @@ All notable changes to this project will be documented in this file. This is primarily for Element X to give a dedicated error message in case it connects a homeserver with only this method available. ([#5222](https://github.com/matrix-org/matrix-rust-sdk/pull/5222)) -- Add `Action::NotifyInApp` and `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind - a new feature `unstable-msc3768`. +- Add `Action::NotifyInApp` and a new field `notify_in_app` in `RoomNotificationMode::MentionsAndKeywordsOnly` + behind a new feature `unstable-msc3768`. ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441)) ### Breaking changes: diff --git a/bindings/matrix-sdk-ffi/src/notification_settings.rs b/bindings/matrix-sdk-ffi/src/notification_settings.rs index 6ea827a406c..6a8d1fedfc9 100644 --- a/bindings/matrix-sdk-ffi/src/notification_settings.rs +++ b/bindings/matrix-sdk-ffi/src/notification_settings.rs @@ -370,11 +370,12 @@ pub enum RoomNotificationMode { /// Receive remote and in-app notifications for all messages. AllMessages, /// Receive remote and in-app notifications for mentions and keywords only. - MentionsAndKeywordsOnly, - /// Receive remote and in-app notifications for mentions and keywords and - /// in-app notifications only for other room messages. - #[cfg(feature = "unstable-msc3768")] - MentionsAndKeywordsOnlyTheRestInApp, + MentionsAndKeywordsOnly { + /// If true, receive in-app-only notifications (no pushes) for other + /// room messages. Otherwise, mute all other room messages. + #[cfg(feature = "unstable-msc3768")] + notify_in_app: bool, + }, /// Do not receive any notifications. Mute, } @@ -383,11 +384,13 @@ impl From for RoomNotificationMode { fn from(value: SdkRoomNotificationMode) -> Self { match value { SdkRoomNotificationMode::AllMessages => Self::AllMessages, - SdkRoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, - #[cfg(feature = "unstable-msc3768")] - SdkRoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { - Self::MentionsAndKeywordsOnlyTheRestInApp - } + SdkRoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app, + } => Self::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app, + }, SdkRoomNotificationMode::Mute => Self::Mute, } } @@ -397,11 +400,13 @@ impl From for SdkRoomNotificationMode { fn from(value: RoomNotificationMode) -> Self { match value { RoomNotificationMode::AllMessages => Self::AllMessages, - RoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, - #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { - Self::MentionsAndKeywordsOnlyTheRestInApp - } + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app, + } => Self::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app, + }, RoomNotificationMode::Mute => Self::Mute, } } diff --git a/crates/matrix-sdk-base/CHANGELOG.md b/crates/matrix-sdk-base/CHANGELOG.md index 9a3292b2c31..eaa03ecd828 100644 --- a/crates/matrix-sdk-base/CHANGELOG.md +++ b/crates/matrix-sdk-base/CHANGELOG.md @@ -18,8 +18,8 @@ All notable changes to this project will be documented in this file. `RoomInfo::invite_details` method returns both the timestamp and the inviter. ([#5390](https://github.com/matrix-org/matrix-rust-sdk/pull/5390)) -- Add `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind a new - feature `unstable-msc3768`. +- Add a new field `notify_in_app` in `RoomNotificationMode::MentionsAndKeywordsOnly` + behind a new feature `unstable-msc3768`. ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441 ### Refactor diff --git a/crates/matrix-sdk-base/src/notification_settings.rs b/crates/matrix-sdk-base/src/notification_settings.rs index b72bacabbbf..b816210d495 100644 --- a/crates/matrix-sdk-base/src/notification_settings.rs +++ b/crates/matrix-sdk-base/src/notification_settings.rs @@ -22,11 +22,12 @@ pub enum RoomNotificationMode { /// Receive remote and in-app notifications for all messages. AllMessages, /// Receive remote and in-app notifications for mentions and keywords only. - MentionsAndKeywordsOnly, - /// Receive remote and in-app notifications for mentions and keywords and - /// in-app notifications only for other room messages. - #[cfg(feature = "unstable-msc3768")] - MentionsAndKeywordsOnlyTheRestInApp, + MentionsAndKeywordsOnly { + /// If true, receive in-app-only notifications (no pushes) for other + /// room messages. Otherwise, mute all other room messages. + #[cfg(feature = "unstable-msc3768")] + notify_in_app: bool, + }, /// Do not receive any notifications. Mute, } diff --git a/crates/matrix-sdk/src/notification_settings/mod.rs b/crates/matrix-sdk/src/notification_settings/mod.rs index 780260ed22b..bc3fabbfdaa 100644 --- a/crates/matrix-sdk/src/notification_settings/mod.rs +++ b/crates/matrix-sdk/src/notification_settings/mod.rs @@ -322,12 +322,15 @@ impl NotificationSettings { // insert a `Room` rule which notifies (RuleKind::Room, Notify::All) } - RoomNotificationMode::MentionsAndKeywordsOnly => { + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false, + } => { // insert a `Room` rule which doesn't notify (RuleKind::Room, Notify::None) } #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { + RoomNotificationMode::MentionsAndKeywordsOnly { notify_in_app: true } => { // insert a `Room` rule which notifies in-app only (RuleKind::Room, Notify::InAppOnly) } @@ -719,7 +722,10 @@ mod tests { let settings = from_insert_rules(&client, vec![(RuleKind::Room, &room_id, false)]); assert_eq!( settings.get_user_defined_room_notification_mode(&room_id).await.unwrap(), - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); } @@ -773,7 +779,10 @@ mod tests { let settings = NotificationSettings::new(client.to_owned(), ruleset.to_owned()); assert_eq!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes).await, - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); // The default mode must be `MentionsAndKeywords` if the corresponding Underride @@ -785,7 +794,10 @@ mod tests { let settings = NotificationSettings::new(client, ruleset); assert_eq!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes).await, - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); } @@ -927,9 +939,12 @@ mod tests { let new_modes = [ RoomNotificationMode::AllMessages, - RoomNotificationMode::MentionsAndKeywordsOnly, + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false, + }, #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp, + RoomNotificationMode::MentionsAndKeywordsOnly { notify_in_app: true }, RoomNotificationMode::Mute, ]; for new_mode in new_modes { @@ -1106,7 +1121,10 @@ mod tests { let settings = from_insert_rules(&client, vec![(RuleKind::Room, &room_id, false)]); assert_eq!( settings.get_user_defined_room_notification_mode(&room_id).await.unwrap(), - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); // Unmute the room @@ -1115,7 +1133,10 @@ mod tests { // The ruleset must not be modified assert_eq!( settings.get_user_defined_room_notification_mode(&room_id).await.unwrap(), - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); let room_rules = get_custom_rules_for_room(&settings, &room_id).await; @@ -1212,7 +1233,10 @@ mod tests { .set_default_room_notification_mode( IsEncrypted::No, IsOneToOne::No, - RoomNotificationMode::MentionsAndKeywordsOnly, + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false, + }, ) .await .unwrap(); @@ -1234,7 +1258,10 @@ mod tests { // reflect the change. assert_matches!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::No).await, - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); } @@ -1273,7 +1300,10 @@ mod tests { .set_default_room_notification_mode( IsEncrypted::No, IsOneToOne::Yes, - RoomNotificationMode::MentionsAndKeywordsOnly, + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false, + }, ) .await .unwrap(); @@ -1295,7 +1325,10 @@ mod tests { // reflect the change. assert_matches!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes).await, - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); } @@ -1617,7 +1650,10 @@ mod tests { .set_default_room_notification_mode( IsEncrypted::No, IsOneToOne::No, - RoomNotificationMode::MentionsAndKeywordsOnly, + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false, + }, ) .await .unwrap(); @@ -1626,7 +1662,10 @@ mod tests { // reflect the change. assert_matches!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::No).await, - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } ); } diff --git a/crates/matrix-sdk/src/notification_settings/rules.rs b/crates/matrix-sdk/src/notification_settings/rules.rs index 7aac76de67f..8a7f8d5cc1e 100644 --- a/crates/matrix-sdk/src/notification_settings/rules.rs +++ b/crates/matrix-sdk/src/notification_settings/rules.rs @@ -89,13 +89,18 @@ impl Rules { #[cfg(feature = "unstable-msc3768")] if !rule.triggers_remote_notification() { // This rule contains a `NotifyInApp` action. - return Some(RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp); + return Some(RoomNotificationMode::MentionsAndKeywordsOnly { + notify_in_app: true, + }); } // This rule contains a `Notify` action. return Some(RoomNotificationMode::AllMessages); } - return Some(RoomNotificationMode::MentionsAndKeywordsOnly); + return Some(RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false, + }); } // There is no custom rule matching this `room_id` @@ -123,7 +128,7 @@ impl Rules { #[cfg(feature = "unstable-msc3768")] if !rule.triggers_remote_notification() { // This rule contains a `NotifyInApp` action. - return RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp; + return RoomNotificationMode::MentionsAndKeywordsOnly { notify_in_app: true }; } // If there is an `Underride` rule that should trigger a notification, the mode // is `AllMessages` @@ -132,7 +137,10 @@ impl Rules { } // Otherwise, the mode is `MentionsAndKeywordsOnly` - RoomNotificationMode::MentionsAndKeywordsOnly + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false, + } } /// Get all room IDs for which a user-defined rule exists. @@ -407,7 +415,10 @@ pub(crate) mod tests { let rules = Rules::new(ruleset); assert_eq!( rules.get_user_defined_room_notification_mode(&room_id), - Some(RoomNotificationMode::MentionsAndKeywordsOnly) + Some(RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + }) ); // Initialize with a `Room` rule that doesn't notify @@ -477,7 +488,13 @@ pub(crate) mod tests { let rules = Rules::new(ruleset); let mode = rules.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes); // Then the mode should be `MentionsAndKeywordsOnly` - assert_eq!(mode, RoomNotificationMode::MentionsAndKeywordsOnly); + assert_eq!( + mode, + RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + } + ); } #[async_test] diff --git a/crates/matrix-sdk/src/sliding_sync/client.rs b/crates/matrix-sdk/src/sliding_sync/client.rs index 96da1724adc..262c83cd525 100644 --- a/crates/matrix-sdk/src/sliding_sync/client.rs +++ b/crates/matrix-sdk/src/sliding_sync/client.rs @@ -480,7 +480,10 @@ mod tests { // The room has an updated cached user-defined notification mode. assert_eq!( room.cached_user_defined_notification_mode(), - Some(RoomNotificationMode::MentionsAndKeywordsOnly), + Some(RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + }), ); Ok(()) diff --git a/crates/matrix-sdk/tests/integration/room/notification_mode.rs b/crates/matrix-sdk/tests/integration/room/notification_mode.rs index 1e2a347a7e6..50fea072576 100644 --- a/crates/matrix-sdk/tests/integration/room/notification_mode.rs +++ b/crates/matrix-sdk/tests/integration/room/notification_mode.rs @@ -65,7 +65,13 @@ async fn test_get_notification_mode() { 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)); + assert_matches!( + mode, + Some(RoomNotificationMode::MentionsAndKeywordsOnly { + #[cfg(feature = "unstable-msc3768")] + notify_in_app: false + }) + ); // getting the user-defined mode must return None let mode = room.user_defined_notification_mode().await; diff --git a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs index 6fde9316dc0..dc15f2da5e1 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs @@ -603,7 +603,7 @@ async fn test_room_notification_count() -> Result<()> { settings .set_room_notification_mode( alice_room.room_id(), - matrix_sdk::notification_settings::RoomNotificationMode::MentionsAndKeywordsOnly, + matrix_sdk::notification_settings::RoomNotificationMode::MentionsAndKeywordsOnly {}, ) .await?; warn!("Done!"); From c3a694cf8d41bfe8042d9046730615090cef7be6 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 6 Aug 2025 17:00:46 +0200 Subject: [PATCH 08/11] fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications) Add read receipt test Signed-off-by: Johannes Marbach --- crates/matrix-sdk-base/src/read_receipts.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/matrix-sdk-base/src/read_receipts.rs b/crates/matrix-sdk-base/src/read_receipts.rs index 253bfdafdcf..3264078f1f2 100644 --- a/crates/matrix-sdk-base/src/read_receipts.rs +++ b/crates/matrix-sdk-base/src/read_receipts.rs @@ -787,6 +787,17 @@ mod tests { assert_eq!(receipts.num_mentions, 1); assert_eq!(receipts.num_notifications, 1); + // NotifyInApp is treated like Notify + #[cfg(feature = "unstable-msc3768")] + { + let event = make_event(user_id!("@bob:example.org"), vec![Action::NotifyInApp]); + let mut receipts = RoomReadReceipts::default(); + receipts.process_event(&event, user_id, ThreadingSupport::Disabled); + assert_eq!(receipts.num_unread, 1); + assert_eq!(receipts.num_mentions, 0); + assert_eq!(receipts.num_notifications, 1); + } + // Technically this `push_actions` set would be a bug somewhere else, but let's // make sure to resist against it. let event = make_event(user_id!("@bob:example.org"), vec![Action::Notify, Action::Notify]); From 7ad2a00da34aa45df54aafdab6af3730f2219bd5 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Mon, 11 Aug 2025 15:01:14 +0200 Subject: [PATCH 09/11] Update bindings/matrix-sdk-ffi/src/notification_settings.rs Co-authored-by: Benjamin Bouvier Signed-off-by: Johannes Marbach --- bindings/matrix-sdk-ffi/src/notification_settings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/notification_settings.rs b/bindings/matrix-sdk-ffi/src/notification_settings.rs index 6a8d1fedfc9..5ee5ab5d073 100644 --- a/bindings/matrix-sdk-ffi/src/notification_settings.rs +++ b/bindings/matrix-sdk-ffi/src/notification_settings.rs @@ -326,7 +326,7 @@ pub enum Action { /// remote / push). Notify, /// Causes matching events to generate an in-app notification but no remote - /// / push notification. + /// (push) notification. #[cfg(feature = "unstable-msc3768")] NotifyInApp, /// Sets an entry in the 'tweaks' dictionary sent to the push gateway. From b23bc278a701c752e9a71ea3dbee7885f9705cc0 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Mon, 11 Aug 2025 14:52:03 +0200 Subject: [PATCH 10/11] Revert "fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications)" This reverts commit deef9610d75d0d1b88423a800a1cabb1f74f29e2. --- bindings/matrix-sdk-ffi/CHANGELOG.md | 4 +- .../src/notification_settings.rs | 35 ++++------ crates/matrix-sdk-base/CHANGELOG.md | 4 +- .../src/notification_settings.rs | 11 ++- .../src/notification_settings/mod.rs | 69 ++++--------------- .../src/notification_settings/rules.rs | 29 ++------ crates/matrix-sdk/src/sliding_sync/client.rs | 5 +- .../integration/room/notification_mode.rs | 8 +-- .../src/tests/sliding_sync/room.rs | 2 +- 9 files changed, 48 insertions(+), 119 deletions(-) diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index 411ff48ef83..850f396148b 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -29,8 +29,8 @@ All notable changes to this project will be documented in this file. This is primarily for Element X to give a dedicated error message in case it connects a homeserver with only this method available. ([#5222](https://github.com/matrix-org/matrix-rust-sdk/pull/5222)) -- Add `Action::NotifyInApp` and a new field `notify_in_app` in `RoomNotificationMode::MentionsAndKeywordsOnly` - behind a new feature `unstable-msc3768`. +- Add `Action::NotifyInApp` and `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind + a new feature `unstable-msc3768`. ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441)) ### Breaking changes: diff --git a/bindings/matrix-sdk-ffi/src/notification_settings.rs b/bindings/matrix-sdk-ffi/src/notification_settings.rs index 5ee5ab5d073..1cf2f0e24a3 100644 --- a/bindings/matrix-sdk-ffi/src/notification_settings.rs +++ b/bindings/matrix-sdk-ffi/src/notification_settings.rs @@ -370,12 +370,11 @@ pub enum RoomNotificationMode { /// Receive remote and in-app notifications for all messages. AllMessages, /// Receive remote and in-app notifications for mentions and keywords only. - MentionsAndKeywordsOnly { - /// If true, receive in-app-only notifications (no pushes) for other - /// room messages. Otherwise, mute all other room messages. - #[cfg(feature = "unstable-msc3768")] - notify_in_app: bool, - }, + MentionsAndKeywordsOnly, + /// Receive remote and in-app notifications for mentions and keywords and + /// in-app notifications only for other room messages. + #[cfg(feature = "unstable-msc3768")] + MentionsAndKeywordsOnlyTheRestInApp, /// Do not receive any notifications. Mute, } @@ -384,13 +383,11 @@ impl From for RoomNotificationMode { fn from(value: SdkRoomNotificationMode) -> Self { match value { SdkRoomNotificationMode::AllMessages => Self::AllMessages, - SdkRoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app, - } => Self::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app, - }, + SdkRoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, + #[cfg(feature = "unstable-msc3768")] + SdkRoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { + Self::MentionsAndKeywordsOnlyTheRestInApp + } SdkRoomNotificationMode::Mute => Self::Mute, } } @@ -400,13 +397,11 @@ impl From for SdkRoomNotificationMode { fn from(value: RoomNotificationMode) -> Self { match value { RoomNotificationMode::AllMessages => Self::AllMessages, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app, - } => Self::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app, - }, + RoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, + #[cfg(feature = "unstable-msc3768")] + RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { + Self::MentionsAndKeywordsOnlyTheRestInApp + } RoomNotificationMode::Mute => Self::Mute, } } diff --git a/crates/matrix-sdk-base/CHANGELOG.md b/crates/matrix-sdk-base/CHANGELOG.md index eaa03ecd828..9a3292b2c31 100644 --- a/crates/matrix-sdk-base/CHANGELOG.md +++ b/crates/matrix-sdk-base/CHANGELOG.md @@ -18,8 +18,8 @@ All notable changes to this project will be documented in this file. `RoomInfo::invite_details` method returns both the timestamp and the inviter. ([#5390](https://github.com/matrix-org/matrix-rust-sdk/pull/5390)) -- Add a new field `notify_in_app` in `RoomNotificationMode::MentionsAndKeywordsOnly` - behind a new feature `unstable-msc3768`. +- Add `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind a new + feature `unstable-msc3768`. ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441 ### Refactor diff --git a/crates/matrix-sdk-base/src/notification_settings.rs b/crates/matrix-sdk-base/src/notification_settings.rs index b816210d495..b72bacabbbf 100644 --- a/crates/matrix-sdk-base/src/notification_settings.rs +++ b/crates/matrix-sdk-base/src/notification_settings.rs @@ -22,12 +22,11 @@ pub enum RoomNotificationMode { /// Receive remote and in-app notifications for all messages. AllMessages, /// Receive remote and in-app notifications for mentions and keywords only. - MentionsAndKeywordsOnly { - /// If true, receive in-app-only notifications (no pushes) for other - /// room messages. Otherwise, mute all other room messages. - #[cfg(feature = "unstable-msc3768")] - notify_in_app: bool, - }, + MentionsAndKeywordsOnly, + /// Receive remote and in-app notifications for mentions and keywords and + /// in-app notifications only for other room messages. + #[cfg(feature = "unstable-msc3768")] + MentionsAndKeywordsOnlyTheRestInApp, /// Do not receive any notifications. Mute, } diff --git a/crates/matrix-sdk/src/notification_settings/mod.rs b/crates/matrix-sdk/src/notification_settings/mod.rs index bc3fabbfdaa..780260ed22b 100644 --- a/crates/matrix-sdk/src/notification_settings/mod.rs +++ b/crates/matrix-sdk/src/notification_settings/mod.rs @@ -322,15 +322,12 @@ impl NotificationSettings { // insert a `Room` rule which notifies (RuleKind::Room, Notify::All) } - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false, - } => { + RoomNotificationMode::MentionsAndKeywordsOnly => { // insert a `Room` rule which doesn't notify (RuleKind::Room, Notify::None) } #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnly { notify_in_app: true } => { + RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { // insert a `Room` rule which notifies in-app only (RuleKind::Room, Notify::InAppOnly) } @@ -722,10 +719,7 @@ mod tests { let settings = from_insert_rules(&client, vec![(RuleKind::Room, &room_id, false)]); assert_eq!( settings.get_user_defined_room_notification_mode(&room_id).await.unwrap(), - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); } @@ -779,10 +773,7 @@ mod tests { let settings = NotificationSettings::new(client.to_owned(), ruleset.to_owned()); assert_eq!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes).await, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); // The default mode must be `MentionsAndKeywords` if the corresponding Underride @@ -794,10 +785,7 @@ mod tests { let settings = NotificationSettings::new(client, ruleset); assert_eq!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes).await, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); } @@ -939,12 +927,9 @@ mod tests { let new_modes = [ RoomNotificationMode::AllMessages, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false, - }, + RoomNotificationMode::MentionsAndKeywordsOnly, #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnly { notify_in_app: true }, + RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp, RoomNotificationMode::Mute, ]; for new_mode in new_modes { @@ -1121,10 +1106,7 @@ mod tests { let settings = from_insert_rules(&client, vec![(RuleKind::Room, &room_id, false)]); assert_eq!( settings.get_user_defined_room_notification_mode(&room_id).await.unwrap(), - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); // Unmute the room @@ -1133,10 +1115,7 @@ mod tests { // The ruleset must not be modified assert_eq!( settings.get_user_defined_room_notification_mode(&room_id).await.unwrap(), - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); let room_rules = get_custom_rules_for_room(&settings, &room_id).await; @@ -1233,10 +1212,7 @@ mod tests { .set_default_room_notification_mode( IsEncrypted::No, IsOneToOne::No, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false, - }, + RoomNotificationMode::MentionsAndKeywordsOnly, ) .await .unwrap(); @@ -1258,10 +1234,7 @@ mod tests { // reflect the change. assert_matches!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::No).await, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); } @@ -1300,10 +1273,7 @@ mod tests { .set_default_room_notification_mode( IsEncrypted::No, IsOneToOne::Yes, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false, - }, + RoomNotificationMode::MentionsAndKeywordsOnly, ) .await .unwrap(); @@ -1325,10 +1295,7 @@ mod tests { // reflect the change. assert_matches!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes).await, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); } @@ -1650,10 +1617,7 @@ mod tests { .set_default_room_notification_mode( IsEncrypted::No, IsOneToOne::No, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false, - }, + RoomNotificationMode::MentionsAndKeywordsOnly, ) .await .unwrap(); @@ -1662,10 +1626,7 @@ mod tests { // reflect the change. assert_matches!( settings.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::No).await, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } + RoomNotificationMode::MentionsAndKeywordsOnly ); } diff --git a/crates/matrix-sdk/src/notification_settings/rules.rs b/crates/matrix-sdk/src/notification_settings/rules.rs index 8a7f8d5cc1e..7aac76de67f 100644 --- a/crates/matrix-sdk/src/notification_settings/rules.rs +++ b/crates/matrix-sdk/src/notification_settings/rules.rs @@ -89,18 +89,13 @@ impl Rules { #[cfg(feature = "unstable-msc3768")] if !rule.triggers_remote_notification() { // This rule contains a `NotifyInApp` action. - return Some(RoomNotificationMode::MentionsAndKeywordsOnly { - notify_in_app: true, - }); + return Some(RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp); } // This rule contains a `Notify` action. return Some(RoomNotificationMode::AllMessages); } - return Some(RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false, - }); + return Some(RoomNotificationMode::MentionsAndKeywordsOnly); } // There is no custom rule matching this `room_id` @@ -128,7 +123,7 @@ impl Rules { #[cfg(feature = "unstable-msc3768")] if !rule.triggers_remote_notification() { // This rule contains a `NotifyInApp` action. - return RoomNotificationMode::MentionsAndKeywordsOnly { notify_in_app: true }; + return RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp; } // If there is an `Underride` rule that should trigger a notification, the mode // is `AllMessages` @@ -137,10 +132,7 @@ impl Rules { } // Otherwise, the mode is `MentionsAndKeywordsOnly` - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false, - } + RoomNotificationMode::MentionsAndKeywordsOnly } /// Get all room IDs for which a user-defined rule exists. @@ -415,10 +407,7 @@ pub(crate) mod tests { let rules = Rules::new(ruleset); assert_eq!( rules.get_user_defined_room_notification_mode(&room_id), - Some(RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - }) + Some(RoomNotificationMode::MentionsAndKeywordsOnly) ); // Initialize with a `Room` rule that doesn't notify @@ -488,13 +477,7 @@ pub(crate) mod tests { let rules = Rules::new(ruleset); let mode = rules.get_default_room_notification_mode(IsEncrypted::No, IsOneToOne::Yes); // Then the mode should be `MentionsAndKeywordsOnly` - assert_eq!( - mode, - RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - } - ); + assert_eq!(mode, RoomNotificationMode::MentionsAndKeywordsOnly); } #[async_test] diff --git a/crates/matrix-sdk/src/sliding_sync/client.rs b/crates/matrix-sdk/src/sliding_sync/client.rs index 262c83cd525..96da1724adc 100644 --- a/crates/matrix-sdk/src/sliding_sync/client.rs +++ b/crates/matrix-sdk/src/sliding_sync/client.rs @@ -480,10 +480,7 @@ mod tests { // The room has an updated cached user-defined notification mode. assert_eq!( room.cached_user_defined_notification_mode(), - Some(RoomNotificationMode::MentionsAndKeywordsOnly { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - }), + Some(RoomNotificationMode::MentionsAndKeywordsOnly), ); Ok(()) diff --git a/crates/matrix-sdk/tests/integration/room/notification_mode.rs b/crates/matrix-sdk/tests/integration/room/notification_mode.rs index 50fea072576..1e2a347a7e6 100644 --- a/crates/matrix-sdk/tests/integration/room/notification_mode.rs +++ b/crates/matrix-sdk/tests/integration/room/notification_mode.rs @@ -65,13 +65,7 @@ async fn test_get_notification_mode() { 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 { - #[cfg(feature = "unstable-msc3768")] - notify_in_app: false - }) - ); + assert_matches!(mode, Some(RoomNotificationMode::MentionsAndKeywordsOnly)); // getting the user-defined mode must return None let mode = room.user_defined_notification_mode().await; diff --git a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs index dc15f2da5e1..6fde9316dc0 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs @@ -603,7 +603,7 @@ async fn test_room_notification_count() -> Result<()> { settings .set_room_notification_mode( alice_room.room_id(), - matrix_sdk::notification_settings::RoomNotificationMode::MentionsAndKeywordsOnly {}, + matrix_sdk::notification_settings::RoomNotificationMode::MentionsAndKeywordsOnly, ) .await?; warn!("Done!"); From e6bd99f296e7ad03b0b1b307223c2c2bed0f917f Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Mon, 11 Aug 2025 15:00:31 +0200 Subject: [PATCH 11/11] fixup! feat(push): add experimental support for MSC3768 (in-app-only notifications) Rename MentionsAndKeywordsOnlyTheRestInApp to PushMentionsAndKeywordsOnly Signed-off-by: Johannes Marbach --- bindings/matrix-sdk-ffi/CHANGELOG.md | 2 +- bindings/matrix-sdk-ffi/src/notification_settings.rs | 10 ++++------ crates/matrix-sdk-base/CHANGELOG.md | 2 +- crates/matrix-sdk-base/src/notification_settings.rs | 2 +- crates/matrix-sdk/src/notification_settings/mod.rs | 4 ++-- crates/matrix-sdk/src/notification_settings/rules.rs | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index 850f396148b..fb7a21a72a0 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -29,7 +29,7 @@ All notable changes to this project will be documented in this file. This is primarily for Element X to give a dedicated error message in case it connects a homeserver with only this method available. ([#5222](https://github.com/matrix-org/matrix-rust-sdk/pull/5222)) -- Add `Action::NotifyInApp` and `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind +- Add `Action::NotifyInApp` and `RoomNotificationMode::PushMentionsAndKeywordsOnly` behind a new feature `unstable-msc3768`. ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441)) diff --git a/bindings/matrix-sdk-ffi/src/notification_settings.rs b/bindings/matrix-sdk-ffi/src/notification_settings.rs index 1cf2f0e24a3..cb1e053948a 100644 --- a/bindings/matrix-sdk-ffi/src/notification_settings.rs +++ b/bindings/matrix-sdk-ffi/src/notification_settings.rs @@ -374,7 +374,7 @@ pub enum RoomNotificationMode { /// Receive remote and in-app notifications for mentions and keywords and /// in-app notifications only for other room messages. #[cfg(feature = "unstable-msc3768")] - MentionsAndKeywordsOnlyTheRestInApp, + PushMentionsAndKeywordsOnly, /// Do not receive any notifications. Mute, } @@ -385,8 +385,8 @@ impl From for RoomNotificationMode { SdkRoomNotificationMode::AllMessages => Self::AllMessages, SdkRoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, #[cfg(feature = "unstable-msc3768")] - SdkRoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { - Self::MentionsAndKeywordsOnlyTheRestInApp + SdkRoomNotificationMode::PushMentionsAndKeywordsOnly => { + Self::PushMentionsAndKeywordsOnly } SdkRoomNotificationMode::Mute => Self::Mute, } @@ -399,9 +399,7 @@ impl From for SdkRoomNotificationMode { RoomNotificationMode::AllMessages => Self::AllMessages, RoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly, #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { - Self::MentionsAndKeywordsOnlyTheRestInApp - } + RoomNotificationMode::PushMentionsAndKeywordsOnly => Self::PushMentionsAndKeywordsOnly, RoomNotificationMode::Mute => Self::Mute, } } diff --git a/crates/matrix-sdk-base/CHANGELOG.md b/crates/matrix-sdk-base/CHANGELOG.md index 9a3292b2c31..97b3474368d 100644 --- a/crates/matrix-sdk-base/CHANGELOG.md +++ b/crates/matrix-sdk-base/CHANGELOG.md @@ -18,7 +18,7 @@ All notable changes to this project will be documented in this file. `RoomInfo::invite_details` method returns both the timestamp and the inviter. ([#5390](https://github.com/matrix-org/matrix-rust-sdk/pull/5390)) -- Add `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind a new +- Add `RoomNotificationMode::PushMentionsAndKeywordsOnly` behind a new feature `unstable-msc3768`. ([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441 diff --git a/crates/matrix-sdk-base/src/notification_settings.rs b/crates/matrix-sdk-base/src/notification_settings.rs index b72bacabbbf..f8144eb1233 100644 --- a/crates/matrix-sdk-base/src/notification_settings.rs +++ b/crates/matrix-sdk-base/src/notification_settings.rs @@ -26,7 +26,7 @@ pub enum RoomNotificationMode { /// Receive remote and in-app notifications for mentions and keywords and /// in-app notifications only for other room messages. #[cfg(feature = "unstable-msc3768")] - MentionsAndKeywordsOnlyTheRestInApp, + PushMentionsAndKeywordsOnly, /// Do not receive any notifications. Mute, } diff --git a/crates/matrix-sdk/src/notification_settings/mod.rs b/crates/matrix-sdk/src/notification_settings/mod.rs index 780260ed22b..a29c7d6117d 100644 --- a/crates/matrix-sdk/src/notification_settings/mod.rs +++ b/crates/matrix-sdk/src/notification_settings/mod.rs @@ -327,7 +327,7 @@ impl NotificationSettings { (RuleKind::Room, Notify::None) } #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => { + RoomNotificationMode::PushMentionsAndKeywordsOnly => { // insert a `Room` rule which notifies in-app only (RuleKind::Room, Notify::InAppOnly) } @@ -929,7 +929,7 @@ mod tests { RoomNotificationMode::AllMessages, RoomNotificationMode::MentionsAndKeywordsOnly, #[cfg(feature = "unstable-msc3768")] - RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp, + RoomNotificationMode::PushMentionsAndKeywordsOnly, RoomNotificationMode::Mute, ]; for new_mode in new_modes { diff --git a/crates/matrix-sdk/src/notification_settings/rules.rs b/crates/matrix-sdk/src/notification_settings/rules.rs index 7aac76de67f..df3efc1dea2 100644 --- a/crates/matrix-sdk/src/notification_settings/rules.rs +++ b/crates/matrix-sdk/src/notification_settings/rules.rs @@ -89,7 +89,7 @@ impl Rules { #[cfg(feature = "unstable-msc3768")] if !rule.triggers_remote_notification() { // This rule contains a `NotifyInApp` action. - return Some(RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp); + return Some(RoomNotificationMode::PushMentionsAndKeywordsOnly); } // This rule contains a `Notify` action. @@ -123,7 +123,7 @@ impl Rules { #[cfg(feature = "unstable-msc3768")] if !rule.triggers_remote_notification() { // This rule contains a `NotifyInApp` action. - return RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp; + return RoomNotificationMode::PushMentionsAndKeywordsOnly; } // If there is an `Underride` rule that should trigger a notification, the mode // is `AllMessages`