Skip to content
Open
Changes from all commits
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
35 changes: 25 additions & 10 deletions crates/matrix-sdk/src/sliding_sync/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use matrix_sdk_base::{
sync::SyncResponse, timer, RequestedRequiredStates, ThreadSubscriptionCatchupToken,
};
use matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent;
use ruma::api::{
client::sync::sync_events::v5::{self as http, response},
FeatureFlag, SupportedVersions,
use ruma::{
api::{
client::sync::sync_events::v5::{self as http, response},
FeatureFlag, SupportedVersions,
},
events::GlobalAccountDataEventType,
};
use tracing::error;

Expand Down Expand Up @@ -242,13 +245,25 @@ impl SlidingSyncResponseProcessor {
async fn update_in_memory_caches(client: &Client, response: &SyncResponse) -> Result<()> {
let _timer = timer!(tracing::Level::TRACE, "update_in_memory_caches");

for room_id in response.rooms.joined.keys() {
let Some(room) = client.get_room(room_id) else {
error!(?room_id, "Cannot post process a room in sliding sync because it is missing");
continue;
};

room.user_defined_notification_mode().await;
// Only update the notification modes if the push rules have changed.
if response.account_data.iter().any(|event| {
event
.get_field::<GlobalAccountDataEventType>("type")
.ok()
.flatten()
.is_some_and(|event_type| event_type == GlobalAccountDataEventType::PushRules)
}) {
for room_id in response.rooms.joined.keys() {
let Some(room) = client.get_room(room_id) else {
error!(
?room_id,
"Cannot post process a room in sliding sync because it is missing"
);
continue;
};

room.user_defined_notification_mode().await;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: an extra perf improvement would be to create the NotificationSettings instance once (instead of once per call to user_defined_notification_mode()), and use it to update all the room notification modes at once, instead of creating the NotificationSettings (which loads the push rules from DB) once per room.

Also, I think it's still necessary to figure what are the newly joined rooms, and compute the user defined notification mode for those.

Not as simple as I imagined first, unfortunately.

}
}

Ok(())
Expand Down
Loading