common: Make push rules only apply if enabled
This only changes the behavior of `ConditionalPushRule::applies` and `PatternedPushRule::applies_to`, `Ruleset::get_actions` was already filtering out disabled rules.
This commit is contained in:
parent
5d0fb3924e
commit
fc423b3620
@ -107,27 +107,31 @@ impl Ruleset {
|
||||
{
|
||||
let event_map = &FlattenedJson::from_raw(event);
|
||||
|
||||
for rule in self.override_.iter().filter(|r| r.enabled) {
|
||||
for rule in &self.override_ {
|
||||
if rule.applies(event_map, context) {
|
||||
return rule.actions.iter();
|
||||
}
|
||||
}
|
||||
for rule in self.content.iter().filter(|r| r.enabled) {
|
||||
for rule in &self.content {
|
||||
if rule.applies_to("content.body", event_map, context) {
|
||||
return rule.actions.iter();
|
||||
}
|
||||
}
|
||||
for rule in self.room.iter().filter(|r| r.enabled) {
|
||||
if condition::check_event_match(event_map, "room_id", &rule.rule_id, context) {
|
||||
for rule in &self.room {
|
||||
if rule.enabled
|
||||
&& condition::check_event_match(event_map, "room_id", &rule.rule_id, context)
|
||||
{
|
||||
return rule.actions.iter();
|
||||
}
|
||||
}
|
||||
for rule in self.sender.iter().filter(|r| r.enabled) {
|
||||
if condition::check_event_match(event_map, "sender", &rule.rule_id, context) {
|
||||
for rule in &self.sender {
|
||||
if rule.enabled
|
||||
&& condition::check_event_match(event_map, "sender", &rule.rule_id, context)
|
||||
{
|
||||
return rule.actions.iter();
|
||||
}
|
||||
}
|
||||
for rule in self.underride.iter().filter(|r| r.enabled) {
|
||||
for rule in &self.underride {
|
||||
if rule.applies(event_map, context) {
|
||||
return rule.actions.iter();
|
||||
}
|
||||
@ -238,6 +242,18 @@ pub struct ConditionalPushRule {
|
||||
pub conditions: Vec<PushCondition>,
|
||||
}
|
||||
|
||||
impl ConditionalPushRule {
|
||||
/// Check if the push rule applies to the event.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `event` - The flattened JSON representation of a room message event.
|
||||
/// * `context` - The context of the room at the time of the event.
|
||||
pub fn applies(&self, event: &FlattenedJson, context: &PushConditionRoomCtx) -> bool {
|
||||
self.enabled && self.conditions.iter().all(|cond| cond.applies(event, context))
|
||||
}
|
||||
}
|
||||
|
||||
/// Initial set of fields of `ConditionalPushRule`.
|
||||
///
|
||||
/// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in
|
||||
@ -270,18 +286,6 @@ impl From<ConditionalPushRuleInit> for ConditionalPushRule {
|
||||
}
|
||||
}
|
||||
|
||||
impl ConditionalPushRule {
|
||||
/// Check if the push rule applies to the event.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `event` - The flattened JSON representation of a room message event.
|
||||
/// * `context` - The context of the room at the time of the event.
|
||||
pub fn applies(&self, event: &FlattenedJson, context: &PushConditionRoomCtx) -> bool {
|
||||
self.conditions.iter().all(|cond| cond.applies(event, context))
|
||||
}
|
||||
}
|
||||
|
||||
// The following trait are needed to be able to make
|
||||
// an IndexSet of the type
|
||||
|
||||
@ -343,7 +347,7 @@ impl PatternedPushRule {
|
||||
event: &FlattenedJson,
|
||||
context: &PushConditionRoomCtx,
|
||||
) -> bool {
|
||||
condition::check_event_match(event, key, &self.pattern, context)
|
||||
self.enabled && condition::check_event_match(event, key, &self.pattern, context)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user