Skip to content

Commit 3021ba4

Browse files
committed
feat(push): add experimental support for MSC3768 (in-app-only notifications)
Signed-off-by: Johannes Marbach <[email protected]>
1 parent ada68e1 commit 3021ba4

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ proptest = { version = "1.6.0", default-features = false, features = ["std"] }
5959
rand = "0.8.5"
6060
reqwest = { version = "0.12.12", default-features = false }
6161
rmp-serde = "1.3.0"
62-
ruma = { git = "https://github.com/ruma/ruma", rev = "de19ebaf71af620eb17abaefd92e43153f9d041d", features = [
62+
ruma = { git = "https://github.com/ruma/ruma", rev = "dd7b085424930c34323a60ef360194c27a61459c", features = [
6363
"client-api-c",
6464
"compat-upload-signatures",
6565
"compat-arbitrary-length-ids",
@@ -77,7 +77,7 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "de19ebaf71af620eb17abaefd9
7777
"unstable-msc4278",
7878
"unstable-msc4286",
7979
] }
80-
ruma-common = { git = "https://github.com/ruma/ruma", rev = "de19ebaf71af620eb17abaefd92e43153f9d041d" }
80+
ruma-common = { git = "https://github.com/ruma/ruma", rev = "dd7b085424930c34323a60ef360194c27a61459c" }
8181
sentry = "0.36.0"
8282
sentry-tracing = "0.36.0"
8383
serde = { version = "1.0.217", features = ["rc"] }

bindings/matrix-sdk-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ crate-type = [
2626
[features]
2727
default = ["bundled-sqlite", "unstable-msc4274"]
2828
bundled-sqlite = ["matrix-sdk/bundled-sqlite"]
29+
unstable-msc3768 = ["matrix-sdk-ui/unstable-msc3768"]
2930
unstable-msc4274 = ["matrix-sdk-ui/unstable-msc4274"]
3031
# Required when targeting a Javascript environment, like Wasm in a browser.
3132
js = ["matrix-sdk-ui/js"]

bindings/matrix-sdk-ffi/src/notification_settings.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,12 @@ impl TryFrom<Tweak> for SdkTweak {
322322
#[derive(Clone, uniffi::Enum)]
323323
/// Enum representing the push notification actions for a rule.
324324
pub enum Action {
325-
/// Causes matching events to generate a notification.
325+
/// Causes matching events to generate a notification (both in-app and
326+
/// remote / push).
326327
Notify,
328+
/// Causes matching events to generate an in-app notification but no remote
329+
/// / push notification.
330+
NotifyInApp,
327331
/// Sets an entry in the 'tweaks' dictionary sent to the push gateway.
328332
SetTweak { value: Tweak },
329333
}
@@ -334,6 +338,7 @@ impl TryFrom<SdkAction> for Action {
334338
fn try_from(value: SdkAction) -> Result<Self, Self::Error> {
335339
Ok(match value {
336340
SdkAction::Notify => Self::Notify,
341+
SdkAction::NotifyInApp => Self::NotifyInApp,
337342
SdkAction::SetTweak(tweak) => Self::SetTweak {
338343
value: tweak.try_into().map_err(|e| format!("Failed to convert tweak: {e}"))?,
339344
},
@@ -348,6 +353,7 @@ impl TryFrom<Action> for SdkAction {
348353
fn try_from(value: Action) -> Result<Self, Self::Error> {
349354
Ok(match value {
350355
Action::Notify => Self::Notify,
356+
Action::NotifyInApp => Self::NotifyInApp,
351357
Action::SetTweak { value } => Self::SetTweak(
352358
value.try_into().map_err(|e| format!("Failed to convert tweak: {e}"))?,
353359
),

crates/matrix-sdk-ui/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ rustls-tls = ["matrix-sdk/rustls-tls"]
1919
js = ["matrix-sdk/js"]
2020
uniffi = ["dep:uniffi", "matrix-sdk/uniffi", "matrix-sdk-base/uniffi"]
2121

22+
# Add support for in-app only notifications
23+
unstable-msc3768 = ["ruma/unstable-msc3768"]
24+
2225
# Add support for encrypted extensible events.
2326
unstable-msc3956 = ["ruma/unstable-msc3956"]
2427

@@ -58,6 +61,7 @@ tracing = { workspace = true, features = ["attributes"] }
5861
unicode-normalization.workspace = true
5962
uniffi = { workspace = true, optional = true }
6063

64+
cfg-if = "1.0.0"
6165
emojis = "0.6.4"
6266
unicode-segmentation = "1.12.0"
6367

crates/matrix-sdk-ui/src/notification_client.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::{
1818
time::Duration,
1919
};
2020

21+
use cfg_if::cfg_if;
2122
use futures_util::{StreamExt as _, pin_mut};
2223
use matrix_sdk::{
2324
Client, ClientBuildError, SlidingSyncList, SlidingSyncMode, room::Room, sleep::sleep,
@@ -677,7 +678,7 @@ impl NotificationClient {
677678

678679
let should_notify = push_actions
679680
.as_ref()
680-
.is_some_and(|actions| actions.iter().any(|a| a.should_notify()));
681+
.is_some_and(|actions| actions.iter().any(should_action_notify_remote));
681682

682683
if !should_notify {
683684
// The event has been filtered out by the user's push rules.
@@ -749,7 +750,7 @@ impl NotificationClient {
749750
}
750751

751752
if let Some(actions) = timeline_event.push_actions()
752-
&& !actions.iter().any(|a| a.should_notify())
753+
&& !actions.iter().any(should_action_notify_remote)
753754
{
754755
return Ok(NotificationStatus::EventFilteredOut);
755756
}
@@ -771,6 +772,17 @@ impl NotificationClient {
771772
}
772773
}
773774

775+
fn should_action_notify_remote(action: &Action) -> bool {
776+
cfg_if! {
777+
if #[cfg(feature = "unstable-msc3768")] {
778+
action.should_notify_remote()
779+
} else {
780+
// Before MSC3768 only combined remote/local notifications existed
781+
action.should_notify()
782+
}
783+
}
784+
}
785+
774786
fn is_event_encrypted(event_type: TimelineEventType) -> bool {
775787
let is_still_encrypted = matches!(event_type, TimelineEventType::RoomEncrypted);
776788

0 commit comments

Comments
 (0)