Skip to content

Commit 4478d63

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

File tree

14 files changed

+142
-47
lines changed

14 files changed

+142
-47
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ All notable changes to this project will be documented in this file.
2929
This is primarily for Element X to give a dedicated error message in case
3030
it connects a homeserver with only this method available.
3131
([#5222](https://github.com/matrix-org/matrix-rust-sdk/pull/5222))
32+
- Add `Action::NotifyInApp` and `RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp` behind
33+
a new feature `unstable-msc3768`.
34+
([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441))
3235

3336
### Breaking changes:
3437

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: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,13 @@ 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+
#[cfg(feature = "unstable-msc3768")]
331+
NotifyInApp,
327332
/// Sets an entry in the 'tweaks' dictionary sent to the push gateway.
328333
SetTweak { value: Tweak },
329334
}
@@ -334,6 +339,8 @@ impl TryFrom<SdkAction> for Action {
334339
fn try_from(value: SdkAction) -> Result<Self, Self::Error> {
335340
Ok(match value {
336341
SdkAction::Notify => Self::Notify,
342+
#[cfg(feature = "unstable-msc3768")]
343+
SdkAction::NotifyInApp => Self::NotifyInApp,
337344
SdkAction::SetTweak(tweak) => Self::SetTweak {
338345
value: tweak.try_into().map_err(|e| format!("Failed to convert tweak: {e}"))?,
339346
},
@@ -348,6 +355,8 @@ impl TryFrom<Action> for SdkAction {
348355
fn try_from(value: Action) -> Result<Self, Self::Error> {
349356
Ok(match value {
350357
Action::Notify => Self::Notify,
358+
#[cfg(feature = "unstable-msc3768")]
359+
Action::NotifyInApp => Self::NotifyInApp,
351360
Action::SetTweak { value } => Self::SetTweak(
352361
value.try_into().map_err(|e| format!("Failed to convert tweak: {e}"))?,
353362
),
@@ -358,10 +367,14 @@ impl TryFrom<Action> for SdkAction {
358367
/// Enum representing the push notification modes for a room.
359368
#[derive(Clone, uniffi::Enum)]
360369
pub enum RoomNotificationMode {
361-
/// Receive notifications for all messages.
370+
/// Receive remote and in-app notifications for all messages.
362371
AllMessages,
363-
/// Receive notifications for mentions and keywords only.
372+
/// Receive remote and in-app notifications for mentions and keywords only.
364373
MentionsAndKeywordsOnly,
374+
/// Receive remote and in-app notifications for mentions and keywords and
375+
/// in-app notifications only for other room messages.
376+
#[cfg(feature = "unstable-msc3768")]
377+
MentionsAndKeywordsOnlyTheRestInApp,
365378
/// Do not receive any notifications.
366379
Mute,
367380
}
@@ -371,6 +384,10 @@ impl From<SdkRoomNotificationMode> for RoomNotificationMode {
371384
match value {
372385
SdkRoomNotificationMode::AllMessages => Self::AllMessages,
373386
SdkRoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly,
387+
#[cfg(feature = "unstable-msc3768")]
388+
SdkRoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => {
389+
Self::MentionsAndKeywordsOnlyTheRestInApp
390+
}
374391
SdkRoomNotificationMode::Mute => Self::Mute,
375392
}
376393
}
@@ -381,6 +398,10 @@ impl From<RoomNotificationMode> for SdkRoomNotificationMode {
381398
match value {
382399
RoomNotificationMode::AllMessages => Self::AllMessages,
383400
RoomNotificationMode::MentionsAndKeywordsOnly => Self::MentionsAndKeywordsOnly,
401+
#[cfg(feature = "unstable-msc3768")]
402+
RoomNotificationMode::MentionsAndKeywordsOnlyTheRestInApp => {
403+
Self::MentionsAndKeywordsOnlyTheRestInApp
404+
}
384405
RoomNotificationMode::Mute => Self::Mute,
385406
}
386407
}

crates/matrix-sdk-base/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ qrcode = ["matrix-sdk-crypto?/qrcode"]
2828
automatic-room-key-forwarding = ["matrix-sdk-crypto?/automatic-room-key-forwarding"]
2929
experimental-send-custom-to-device = ["matrix-sdk-crypto?/experimental-send-custom-to-device"]
3030
uniffi = ["dep:uniffi", "matrix-sdk-crypto?/uniffi", "matrix-sdk-common/uniffi"]
31+
unstable-msc3768 = ["ruma/unstable-msc3768"]
3132

3233
# Private feature, see
3334
# https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823 for the gory

crates/matrix-sdk-base/src/notification_settings.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ use serde::{Deserialize, Serialize};
1919
/// Enum representing the push notification modes for a room.
2020
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
2121
pub enum RoomNotificationMode {
22-
/// Receive notifications for all messages.
22+
/// Receive remote and in-app notifications for all messages.
2323
AllMessages,
24-
/// Receive notifications for mentions and keywords only.
24+
/// Receive remote and in-app notifications for mentions and keywords only.
2525
MentionsAndKeywordsOnly,
26+
/// Receive remote and in-app notifications for mentions and keywords and
27+
/// in-app notifications only for other room messages.
28+
#[cfg(feature = "unstable-msc3768")]
29+
MentionsAndKeywordsOnlyTheRestInApp,
2630
/// Do not receive any notifications.
2731
Mute,
2832
}

crates/matrix-sdk-ui/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ All notable changes to this project will be documented in this file.
3131
- `Timeline::send()` will now automatically fill the thread relationship, if the timeline has a
3232
thread focus, and the sent event doesn't have a prefilled `relates_to` field (i.e. a relationship).
3333
([5427](https://github.com/matrix-org/matrix-rust-sdk/pull/5427))
34+
- Add experimental support for MSC3768 behind a new feature `unstable-msc3768`.
35+
([#5441](https://github.com/matrix-org/matrix-rust-sdk/pull/5441
3436

3537
### Refactor
3638

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 = ["matrix-sdk/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

crates/matrix-sdk/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ experimental-widgets = ["dep:uuid", "experimental-send-custom-to-device"]
5959

6060
docsrs = ["e2e-encryption", "sqlite", "indexeddb", "sso-login", "qrcode"]
6161

62+
# Add support for in-app only notifications
63+
unstable-msc3768 = ["matrix-sdk-base/unstable-msc3768"]
64+
6265
# Add support for inline media galleries via msgtypes
6366
unstable-msc4274 = ["ruma/unstable-msc4274", "matrix-sdk-base/unstable-msc4274"]
6467

0 commit comments

Comments
 (0)