matrix-sdk: Add StateChanges::add_notification

master
Kévin Commaille 2021-04-27 11:16:02 +02:00
parent f6c4fdde7d
commit c569436ba4
No known key found for this signature in database
GPG Key ID: 296D60AE1E61661C
2 changed files with 17 additions and 17 deletions

View File

@ -517,24 +517,16 @@ impl BaseClient {
let actions = push_rules.get_actions(&raw_event, &context).to_vec(); let actions = push_rules.get_actions(&raw_event, &context).to_vec();
if actions.iter().any(|a| matches!(a, Action::Notify)) { if actions.iter().any(|a| matches!(a, Action::Notify)) {
let notification = Notification::new( changes.add_notification(
actions, room_id,
raw_event, Notification::new(
false, actions,
room_id.clone(), raw_event,
SystemTime::now(), 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. // TODO send and store the highlight tweak value with the event.
// Needs to associate custom data with events and to store them. // Needs to associate custom data with events and to store them.

View File

@ -442,4 +442,12 @@ impl StateChanges {
.or_insert_with(BTreeMap::new) .or_insert_with(BTreeMap::new)
.insert(event.state_key().to_string(), event); .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);
}
} }