Skip to content

Commit eee8a98

Browse files
committed
feat(push): add experimental support for MSC4359 ("Do not Disturb" notification settings)
Signed-off-by: Johannes Marbach <[email protected]>
1 parent 943b048 commit eee8a98

File tree

9 files changed

+177
-75
lines changed

9 files changed

+177
-75
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ rand = "0.8.5"
6565
regex = "1.11.2"
6666
reqwest = { version = "0.12.23", default-features = false }
6767
rmp-serde = "1.3.0"
68-
ruma = { git = "https://github.com/ruma/ruma", rev = "2f64faeabb85950de27e9829faeb389d2779ac57", features = [
68+
ruma = { git = "https://github.com/ruma/ruma", rev = "de227ef5c5b2d2ecff89ab021ebe53c5d565577d", features = [
6969
"client-api-c",
7070
"compat-upload-signatures",
7171
"compat-arbitrary-length-ids",
@@ -85,11 +85,12 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "2f64faeabb85950de27e9829fa
8585
"unstable-msc4286",
8686
"unstable-msc4306",
8787
"unstable-msc4308",
88-
"unstable-msc4310"
88+
"unstable-msc4310",
89+
"unstable-msc4359"
8990
] }
9091
sentry = { version = "0.42.0", default-features = false }
9192
sentry-tracing = "0.42.0"
92-
serde = { version = "1.0.219", features = ["rc"] }
93+
serde = { version = "1.0.221", features = ["rc"] }
9394
serde_html_form = "0.2.7"
9495
serde_json = "1.0.143"
9596
sha2 = "0.10.9"

bindings/matrix-sdk-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ crate-type = [
2727
default = ["bundled-sqlite", "unstable-msc4274", "experimental-element-recent-emojis"]
2828
bundled-sqlite = ["matrix-sdk/bundled-sqlite"]
2929
unstable-msc4274 = ["matrix-sdk-ui/unstable-msc4274"]
30+
unstable-msc4359 = ["matrix-sdk-ui/unstable-msc4359"]
3031
# Required when targeting a Javascript environment, like Wasm in a browser.
3132
js = ["matrix-sdk-ui/js"]
3233
# Use the TLS implementation provided by the host system, necessary on iOS and Wasm platforms.

crates/matrix-sdk-base/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ testing = [
6565
# Add support for inline media galleries via msgtypes
6666
unstable-msc4274 = []
6767

68+
# "Do not Disturb" notification settings
69+
unstable-msc4359 = ["ruma/unstable-msc4359"]
70+
6871
experimental-element-recent-emojis = []
6972

7073
[dependencies]

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use matrix_sdk_crypto::{
3232
};
3333
#[cfg(doc)]
3434
use ruma::DeviceId;
35+
#[cfg(feature = "unstable-msc4359")]
36+
use ruma::events::do_not_disturb::{DoNotDisturbEventContent, DoNotDisturbRoomKey};
3537
#[cfg(feature = "e2e-encryption")]
3638
use ruma::events::room::{history_visibility::HistoryVisibility, member::MembershipState};
3739
use ruma::{
@@ -1135,6 +1137,37 @@ impl BaseClient {
11351137
}
11361138
}
11371139
}
1140+
1141+
/// Checks whether the provided `room_id` belongs to a room in "Do not
1142+
/// Disturb" mode.
1143+
#[cfg(feature = "unstable-msc4359")]
1144+
pub async fn is_room_in_do_not_disturb_mode(&self, room_id: &RoomId) -> bool {
1145+
match self.state_store.get_account_data_event_static::<DoNotDisturbEventContent>().await {
1146+
Ok(Some(raw_do_not_disturb_room_list)) => {
1147+
match raw_do_not_disturb_room_list.deserialize() {
1148+
Ok(current_do_not_disturb_room_list) => {
1149+
current_do_not_disturb_room_list
1150+
.content
1151+
.rooms
1152+
.contains_key(&DoNotDisturbRoomKey::AllRooms)
1153+
|| current_do_not_disturb_room_list
1154+
.content
1155+
.rooms
1156+
.contains_key(&DoNotDisturbRoomKey::SingleRoom(room_id.to_owned()))
1157+
}
1158+
Err(error) => {
1159+
warn!(?error, "Failed to deserialize the do not disturb room list event");
1160+
false
1161+
}
1162+
}
1163+
}
1164+
Ok(None) => false,
1165+
Err(error) => {
1166+
warn!(?error, "Could not get the do not disturb room list from the state store");
1167+
false
1168+
}
1169+
}
1170+
}
11381171
}
11391172

11401173
/// Represent the `required_state` values sent by a sync request.

crates/matrix-sdk-ui/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ unstable-msc3956 = ["ruma/unstable-msc3956"]
2525
# Add support for inline media galleries via msgtypes
2626
unstable-msc4274 = ["matrix-sdk/unstable-msc4274"]
2727

28+
# "Do not Disturb" notification settings
29+
unstable-msc4359 = ["matrix-sdk/unstable-msc4359"]
30+
2831
# Enable experimental support for encrypting state events; see
2932
# https://github.com/matrix-org/matrix-rust-sdk/issues/5397.
3033
experimental-encrypted-state-events = [
@@ -38,6 +41,7 @@ async-rx.workspace = true
3841
async-stream.workspace = true
3942
async_cell = "0.2.3"
4043
bitflags.workspace = true
44+
cfg-if.workspace = true
4145
chrono.workspace = true
4246
eyeball.workspace = true
4347
eyeball-im.workspace = true

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

Lines changed: 14 additions & 1 deletion
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,
@@ -637,7 +638,19 @@ impl NotificationClient {
637638
let notification_item =
638639
NotificationItem::new(room, raw_event, push_actions, state_events).await?;
639640

640-
if self.client.is_user_ignored(notification_item.event.sender()).await {
641+
let is_room_in_do_not_disturb = {
642+
cfg_if! {
643+
if #[cfg(feature = "unstable-msc4359")] {
644+
self.client.is_room_in_do_not_disturb_mode(room.room_id()).await
645+
} else {
646+
false
647+
}
648+
}
649+
};
650+
651+
if self.client.is_user_ignored(notification_item.event.sender()).await
652+
|| is_room_in_do_not_disturb
653+
{
641654
Ok(NotificationStatus::EventFilteredOut)
642655
} else {
643656
Ok(NotificationStatus::Event(Box::new(notification_item)))

crates/matrix-sdk/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ docsrs = ["e2e-encryption", "sqlite", "indexeddb", "sso-login", "qrcode"]
7171
# Add support for inline media galleries via msgtypes
7272
unstable-msc4274 = ["ruma/unstable-msc4274", "matrix-sdk-base/unstable-msc4274"]
7373

74+
# "Do not Disturb" notification settings
75+
unstable-msc4359 = ["matrix-sdk-base/unstable-msc4359"]
76+
7477
experimental-search = ["matrix-sdk-search"]
7578

7679
experimental-element-recent-emojis = ["matrix-sdk-base/experimental-element-recent-emojis"]

crates/matrix-sdk/src/client/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,6 +2860,13 @@ impl Client {
28602860
self.base_client().is_user_ignored(user_id).await
28612861
}
28622862

2863+
/// Checks whether the provided `room_id` belongs to a room in "Do not
2864+
/// Disturb" mode.
2865+
#[cfg(feature = "unstable-msc4359")]
2866+
pub async fn is_room_in_do_not_disturb_mode(&self, room_id: &RoomId) -> bool {
2867+
self.base_client().is_room_in_do_not_disturb_mode(room_id).await
2868+
}
2869+
28632870
/// Gets the `max_upload_size` value from the homeserver, getting either a
28642871
/// cached value or with a `/_matrix/client/v1/media/config` request if it's
28652872
/// missing.

0 commit comments

Comments
 (0)