diff --git a/crates/matrix-sdk-base/src/response_processors/room/sync_v2.rs b/crates/matrix-sdk-base/src/response_processors/room/sync_v2.rs index 9fa642b81..668f8d79a 100644 --- a/crates/matrix-sdk-base/src/response_processors/room/sync_v2.rs +++ b/crates/matrix-sdk-base/src/response_processors/room/sync_v2.rs @@ -238,9 +238,7 @@ pub async fn update_invited_room( (&raw_events, &events), &room, &mut room_info, - notification.push_rules, - notification.notifications, - notification.state_store, + notification, ) .await?; diff --git a/crates/matrix-sdk-base/src/response_processors/state_events.rs b/crates/matrix-sdk-base/src/response_processors/state_events.rs index 4735f6be1..1da00f03a 100644 --- a/crates/matrix-sdk-base/src/response_processors/state_events.rs +++ b/crates/matrix-sdk-base/src/response_processors/state_events.rs @@ -117,18 +117,14 @@ pub mod sync { pub mod stripped { use std::{collections::BTreeMap, iter}; - use ruma::{ - events::AnyStrippedStateEvent, - push::{Action, Ruleset}, - OwnedRoomId, - }; + use ruma::{events::AnyStrippedStateEvent, push::Action}; use tracing::instrument; - use super::{super::timeline, Context, Raw}; - use crate::{ - deserialized_responses::RawAnySyncOrStrippedTimelineEvent, store::BaseStateStore, - sync::Notification, Result, Room, RoomInfo, + use super::{ + super::{notification, timeline}, + Context, Raw, }; + use crate::{Result, Room, RoomInfo}; /// Collect [`AnyStrippedStateEvent`] to [`AnyStrippedStateEvent`]. pub fn collect( @@ -164,9 +160,7 @@ pub mod stripped { (raw_events, events): (&[Raw], &[AnyStrippedStateEvent]), room: &Room, room_info: &mut RoomInfo, - push_rules: &Ruleset, - notifications: &mut BTreeMap>, - state_store: &BaseStateStore, + mut notification: notification::Notification<'_>, ) -> Result<()> { let mut state_events = BTreeMap::new(); @@ -186,20 +180,19 @@ pub mod stripped { // We need to check for notifications after we have handled all state // events, to make sure we have the full push context. if let Some(push_context) = - timeline::get_push_room_context(context, room, room_info, state_store).await? + timeline::get_push_room_context(context, room, room_info, notification.state_store) + .await? { + let room_id = room.room_id(); + // Check every event again for notification. for event in state_events.values().flat_map(|map| map.values()) { - let actions = push_rules.get_actions(event, &push_context); - - if actions.iter().any(Action::should_notify) { - notifications.entry(room.room_id().to_owned()).or_default().push( - Notification { - actions: actions.to_owned(), - event: RawAnySyncOrStrippedTimelineEvent::Stripped(event.clone()), - }, - ); - } + notification.push_notification_from_event_if( + room_id, + &push_context, + event, + Action::should_notify, + ); } } diff --git a/crates/matrix-sdk-base/src/response_processors/timeline.rs b/crates/matrix-sdk-base/src/response_processors/timeline.rs index 6c985b98c..7a5860a7f 100644 --- a/crates/matrix-sdk-base/src/response_processors/timeline.rs +++ b/crates/matrix-sdk-base/src/response_processors/timeline.rs @@ -32,9 +32,8 @@ use super::Context; #[cfg(feature = "e2e-encryption")] use super::{e2ee, verification}; use crate::{ - deserialized_responses::RawAnySyncOrStrippedTimelineEvent, store::{BaseStateStore, StateStoreExt as _}, - sync::{Notification, Timeline}, + sync::Timeline, Result, Room, RoomInfo, }; @@ -51,7 +50,7 @@ pub async fn build<'notification, 'e2ee>( room: &Room, room_info: &mut RoomInfo, timeline_inputs: builder::Timeline, - notification_inputs: builder::Notification<'notification>, + mut notification_inputs: builder::Notification<'notification>, #[cfg(feature = "e2e-encryption")] e2ee: builder::E2EE<'e2ee>, ) -> Result { let mut timeline = Timeline::new(timeline_inputs.limited, timeline_inputs.prev_batch); @@ -140,22 +139,13 @@ pub async fn build<'notification, 'e2ee>( .await?; } - if let Some(context) = &push_context { - let actions = - notification_inputs.push_rules.get_actions(timeline_event.raw(), context); - - if actions.iter().any(Action::should_notify) { - notification_inputs - .notifications - .entry(room_id.to_owned()) - .or_default() - .push(Notification { - actions: actions.to_owned(), - event: RawAnySyncOrStrippedTimelineEvent::Sync( - timeline_event.raw().clone(), - ), - }); - } + if let Some(push_context) = &push_context { + let actions = notification_inputs.push_notification_from_event_if( + room_id, + push_context, + timeline_event.raw(), + Action::should_notify, + ); timeline_event.push_actions = Some(actions.to_owned()); } diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index fe218356b..fc7ab2b29 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -405,9 +405,11 @@ impl BaseClient { (&raw_events, &events), &room, &mut room_info, - &push_rules, - notifications, - &self.state_store, + processors::notification::Notification::new( + &push_rules, + notifications, + &self.state_store, + ), ) .await?; }