diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index c7c93570..e12197b4 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -517,24 +517,16 @@ impl BaseClient { let actions = push_rules.get_actions(&raw_event, &context).to_vec(); if actions.iter().any(|a| matches!(a, Action::Notify)) { - let notification = Notification::new( - actions, - raw_event, - false, - room_id.clone(), - SystemTime::now(), + changes.add_notification( + room_id, + Notification::new( + actions, + raw_event, + false, + room_id.clone(), + SystemTime::now(), + ), ); - - match changes.notifications.get_mut(room_id) { - Some(room) => { - room.push(notification); - } - None => { - changes - .notifications - .insert(room_id.clone(), vec![notification]); - } - } } // TODO send and store the highlight tweak value with the event. // Needs to associate custom data with events and to store them. diff --git a/matrix_sdk_base/src/store/mod.rs b/matrix_sdk_base/src/store/mod.rs index 95365a1a..d9e33336 100644 --- a/matrix_sdk_base/src/store/mod.rs +++ b/matrix_sdk_base/src/store/mod.rs @@ -442,4 +442,12 @@ impl StateChanges { .or_insert_with(BTreeMap::new) .insert(event.state_key().to_string(), event); } + + /// Update the `StateChanges` struct with the given room with a new `Notification`. + pub fn add_notification(&mut self, room_id: &RoomId, notification: Notification) { + self.notifications + .entry(room_id.to_owned()) + .or_insert_with(Vec::new) + .push(notification); + } }