Skip to content

Commit bcee5ba

Browse files
committed
refactor(threads): adapt to Ruma API changes related to async evaluation of push rules
1 parent ebb7059 commit bcee5ba

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

crates/matrix-sdk-base/src/response_processors/notification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'a> Notification<'a> {
5959
/// `push_condition_room_ctx`. (based on `Self::push_rules`).
6060
///
6161
/// This method returns the fetched [`Action`]s.
62-
pub fn push_notification_from_event_if<E, P>(
62+
pub async fn push_notification_from_event_if<E, P>(
6363
&mut self,
6464
room_id: &RoomId,
6565
push_condition_room_ctx: &PushConditionRoomCtx,
@@ -70,7 +70,7 @@ impl<'a> Notification<'a> {
7070
Raw<E>: Into<RawAnySyncOrStrippedTimelineEvent>,
7171
P: Fn(&Action) -> bool,
7272
{
73-
let actions = self.push_rules.get_actions(event, push_condition_room_ctx);
73+
let actions = self.push_rules.get_actions(event, push_condition_room_ctx).await;
7474

7575
if actions.iter().any(predicate) {
7676
self.push_notification(room_id, actions.to_owned(), event.clone().into());

crates/matrix-sdk-base/src/response_processors/state_events.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,14 @@ pub mod stripped {
281281

282282
// Check every event again for notification.
283283
for event in state_events.values().flat_map(|map| map.values()) {
284-
notification.push_notification_from_event_if(
285-
room_id,
286-
&push_condition_room_ctx,
287-
event,
288-
Action::should_notify,
289-
);
284+
notification
285+
.push_notification_from_event_if(
286+
room_id,
287+
&push_condition_room_ctx,
288+
event,
289+
Action::should_notify,
290+
)
291+
.await;
290292
}
291293
}
292294

crates/matrix-sdk-base/src/response_processors/timeline.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ pub async fn build<'notification, 'e2ee>(
129129
}
130130

131131
if let Some(push_condition_room_ctx) = &push_condition_room_ctx {
132-
let actions = notification.push_notification_from_event_if(
133-
room_id,
134-
push_condition_room_ctx,
135-
timeline_event.raw(),
136-
Action::should_notify,
137-
);
132+
let actions = notification
133+
.push_notification_from_event_if(
134+
room_id,
135+
push_condition_room_ctx,
136+
timeline_event.raw(),
137+
Action::should_notify,
138+
)
139+
.await;
138140

139141
timeline_event.set_push_actions(actions.to_owned());
140142
}

crates/matrix-sdk-ui/src/timeline/traits.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,11 @@ impl Decryptor for (matrix_sdk_base::crypto::OlmMachine, ruma::OwnedRoomId) {
343343
.await?
344344
{
345345
RoomEventDecryptionResult::Decrypted(decrypted) => {
346-
let push_actions = push_ctx.map(|push_ctx| push_ctx.for_event(&decrypted.event));
346+
let push_actions = if let Some(push_ctx) = push_ctx {
347+
Some(push_ctx.for_event(&decrypted.event).await)
348+
} else {
349+
None
350+
};
347351
Ok(TimelineEvent::from_decrypted(decrypted, push_actions))
348352
}
349353
RoomEventDecryptionResult::UnableToDecrypt(utd_info) => {

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ impl PushContext {
217217
}
218218

219219
/// Compute the push rules for a given event.
220-
pub fn for_event<T>(&self, event: &Raw<T>) -> Vec<Action> {
221-
self.push_rules.get_actions(event, &self.push_condition_room_ctx).to_owned()
220+
pub async fn for_event<T>(&self, event: &Raw<T>) -> Vec<Action> {
221+
self.push_rules.get_actions(event, &self.push_condition_room_ctx).await.to_owned()
222222
}
223223
}
224224

@@ -648,7 +648,7 @@ impl Room {
648648

649649
let mut event = TimelineEvent::from_plaintext(event.cast());
650650
if let Some(push_ctx) = push_ctx {
651-
event.set_push_actions(push_ctx.for_event(event.raw()));
651+
event.set_push_actions(push_ctx.for_event(event.raw()).await);
652652
}
653653

654654
event
@@ -1553,7 +1553,11 @@ impl Room {
15531553
.await?
15541554
{
15551555
RoomEventDecryptionResult::Decrypted(decrypted) => {
1556-
let push_actions = push_ctx.map(|push_ctx| push_ctx.for_event(&decrypted.event));
1556+
let push_actions = if let Some(push_ctx) = push_ctx {
1557+
Some(push_ctx.for_event(&decrypted.event).await)
1558+
} else {
1559+
None
1560+
};
15571561
Ok(TimelineEvent::from_decrypted(decrypted, push_actions))
15581562
}
15591563
RoomEventDecryptionResult::UnableToDecrypt(utd_info) => {
@@ -3045,7 +3049,11 @@ impl Room {
30453049
/// Note that it is possible that no push action is returned because the
30463050
/// current room state does not have all the required state events.
30473051
pub async fn event_push_actions<T>(&self, event: &Raw<T>) -> Result<Option<Vec<Action>>> {
3048-
Ok(self.push_context().await?.map(|ctx| ctx.for_event(event)))
3052+
if let Some(ctx) = self.push_context().await? {
3053+
Ok(Some(ctx.for_event(event).await))
3054+
} else {
3055+
Ok(None)
3056+
}
30493057
}
30503058

30513059
/// The membership details of the (latest) invite for the logged-in user in

0 commit comments

Comments
 (0)