mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-09 08:27:32 -04:00
refactor(threads): adapt to Ruma API changes related to async evaluation of push rules
This commit is contained in:
@@ -59,7 +59,7 @@ impl<'a> Notification<'a> {
|
||||
/// `push_condition_room_ctx`. (based on `Self::push_rules`).
|
||||
///
|
||||
/// This method returns the fetched [`Action`]s.
|
||||
pub fn push_notification_from_event_if<E, P>(
|
||||
pub async fn push_notification_from_event_if<E, P>(
|
||||
&mut self,
|
||||
room_id: &RoomId,
|
||||
push_condition_room_ctx: &PushConditionRoomCtx,
|
||||
@@ -70,7 +70,7 @@ impl<'a> Notification<'a> {
|
||||
Raw<E>: Into<RawAnySyncOrStrippedTimelineEvent>,
|
||||
P: Fn(&Action) -> bool,
|
||||
{
|
||||
let actions = self.push_rules.get_actions(event, push_condition_room_ctx);
|
||||
let actions = self.push_rules.get_actions(event, push_condition_room_ctx).await;
|
||||
|
||||
if actions.iter().any(predicate) {
|
||||
self.push_notification(room_id, actions.to_owned(), event.clone().into());
|
||||
|
||||
@@ -281,12 +281,14 @@ pub mod stripped {
|
||||
|
||||
// Check every event again for notification.
|
||||
for event in state_events.values().flat_map(|map| map.values()) {
|
||||
notification.push_notification_from_event_if(
|
||||
room_id,
|
||||
&push_condition_room_ctx,
|
||||
event,
|
||||
Action::should_notify,
|
||||
);
|
||||
notification
|
||||
.push_notification_from_event_if(
|
||||
room_id,
|
||||
&push_condition_room_ctx,
|
||||
event,
|
||||
Action::should_notify,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,12 +129,14 @@ pub async fn build<'notification, 'e2ee>(
|
||||
}
|
||||
|
||||
if let Some(push_condition_room_ctx) = &push_condition_room_ctx {
|
||||
let actions = notification.push_notification_from_event_if(
|
||||
room_id,
|
||||
push_condition_room_ctx,
|
||||
timeline_event.raw(),
|
||||
Action::should_notify,
|
||||
);
|
||||
let actions = notification
|
||||
.push_notification_from_event_if(
|
||||
room_id,
|
||||
push_condition_room_ctx,
|
||||
timeline_event.raw(),
|
||||
Action::should_notify,
|
||||
)
|
||||
.await;
|
||||
|
||||
timeline_event.set_push_actions(actions.to_owned());
|
||||
}
|
||||
|
||||
@@ -343,7 +343,11 @@ impl Decryptor for (matrix_sdk_base::crypto::OlmMachine, ruma::OwnedRoomId) {
|
||||
.await?
|
||||
{
|
||||
RoomEventDecryptionResult::Decrypted(decrypted) => {
|
||||
let push_actions = push_ctx.map(|push_ctx| push_ctx.for_event(&decrypted.event));
|
||||
let push_actions = if let Some(push_ctx) = push_ctx {
|
||||
Some(push_ctx.for_event(&decrypted.event).await)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(TimelineEvent::from_decrypted(decrypted, push_actions))
|
||||
}
|
||||
RoomEventDecryptionResult::UnableToDecrypt(utd_info) => {
|
||||
|
||||
@@ -217,8 +217,8 @@ impl PushContext {
|
||||
}
|
||||
|
||||
/// Compute the push rules for a given event.
|
||||
pub fn for_event<T>(&self, event: &Raw<T>) -> Vec<Action> {
|
||||
self.push_rules.get_actions(event, &self.push_condition_room_ctx).to_owned()
|
||||
pub async fn for_event<T>(&self, event: &Raw<T>) -> Vec<Action> {
|
||||
self.push_rules.get_actions(event, &self.push_condition_room_ctx).await.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,7 +648,7 @@ impl Room {
|
||||
|
||||
let mut event = TimelineEvent::from_plaintext(event.cast());
|
||||
if let Some(push_ctx) = push_ctx {
|
||||
event.set_push_actions(push_ctx.for_event(event.raw()));
|
||||
event.set_push_actions(push_ctx.for_event(event.raw()).await);
|
||||
}
|
||||
|
||||
event
|
||||
@@ -1553,7 +1553,11 @@ impl Room {
|
||||
.await?
|
||||
{
|
||||
RoomEventDecryptionResult::Decrypted(decrypted) => {
|
||||
let push_actions = push_ctx.map(|push_ctx| push_ctx.for_event(&decrypted.event));
|
||||
let push_actions = if let Some(push_ctx) = push_ctx {
|
||||
Some(push_ctx.for_event(&decrypted.event).await)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(TimelineEvent::from_decrypted(decrypted, push_actions))
|
||||
}
|
||||
RoomEventDecryptionResult::UnableToDecrypt(utd_info) => {
|
||||
@@ -3045,7 +3049,11 @@ impl Room {
|
||||
/// Note that it is possible that no push action is returned because the
|
||||
/// current room state does not have all the required state events.
|
||||
pub async fn event_push_actions<T>(&self, event: &Raw<T>) -> Result<Option<Vec<Action>>> {
|
||||
Ok(self.push_context().await?.map(|ctx| ctx.for_event(event)))
|
||||
if let Some(ctx) = self.push_context().await? {
|
||||
Ok(Some(ctx.for_event(event).await))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// The membership details of the (latest) invite for the logged-in user in
|
||||
|
||||
Reference in New Issue
Block a user