Update the base rules to remove the dont_notify action. (MSC3987) (#15534)

A dont_notify action is a no-op (and coalesce is undefined). These are
both considered no-ops by the spec, per MSC3987 and the predefined
push rules were updated to remove dont_notify from the list of actions.
This commit is contained in:
Patrick Cloke 2023-05-04 07:54:13 -04:00 committed by GitHub
parent cc872eaf16
commit ded8f3d349
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 8 deletions

1
changelog.d/15534.misc Normal file
View file

@ -0,0 +1 @@
Implement [MSC3987](https://github.com/matrix-org/matrix-spec-proposals/pull/3987) by removing `"dont_notify"` from the list of actions in default push rules.

View file

@ -57,7 +57,7 @@ pub const BASE_PREPEND_OVERRIDE_RULES: &[PushRule] = &[PushRule {
rule_id: Cow::Borrowed("global/override/.m.rule.master"), rule_id: Cow::Borrowed("global/override/.m.rule.master"),
priority_class: 5, priority_class: 5,
conditions: Cow::Borrowed(&[]), conditions: Cow::Borrowed(&[]),
actions: Cow::Borrowed(&[Action::DontNotify]), actions: Cow::Borrowed(&[]),
default: true, default: true,
default_enabled: false, default_enabled: false,
}]; }];
@ -88,7 +88,7 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
pattern: Cow::Borrowed("m.notice"), pattern: Cow::Borrowed("m.notice"),
}, },
))]), ))]),
actions: Cow::Borrowed(&[Action::DontNotify]), actions: Cow::Borrowed(&[]),
default: true, default: true,
default_enabled: true, default_enabled: true,
}, },
@ -122,7 +122,7 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
pattern: Cow::Borrowed("m.room.member"), pattern: Cow::Borrowed("m.room.member"),
}, },
))]), ))]),
actions: Cow::Borrowed(&[Action::DontNotify]), actions: Cow::Borrowed(&[]),
default: true, default: true,
default_enabled: true, default_enabled: true,
}, },

View file

@ -140,7 +140,7 @@ impl PushRuleEvaluator {
/// name. /// name.
/// ///
/// Returns the set of actions, if any, that match (filtering out any /// Returns the set of actions, if any, that match (filtering out any
/// `dont_notify` actions). /// `dont_notify` and `coalesce` actions).
pub fn run( pub fn run(
&self, &self,
push_rules: &FilteredPushRules, push_rules: &FilteredPushRules,
@ -198,8 +198,9 @@ impl PushRuleEvaluator {
let actions = push_rule let actions = push_rule
.actions .actions
.iter() .iter()
// Filter out "dont_notify" actions, as we don't store them. // Filter out "dont_notify" and "coalesce" actions, as we don't store them
.filter(|a| **a != Action::DontNotify) // (since they result in no action by the pushers).
.filter(|a| **a != Action::DontNotify && **a != Action::Coalesce)
.cloned() .cloned()
.collect(); .collect();

View file

@ -164,11 +164,13 @@ impl PushRule {
/// The "action" Synapse should perform for a matching push rule. /// The "action" Synapse should perform for a matching push rule.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum Action { pub enum Action {
DontNotify,
Notify, Notify,
Coalesce,
SetTweak(SetTweak), SetTweak(SetTweak),
// Legacy actions that should be understood, but are equivalent to no-ops.
DontNotify,
Coalesce,
// An unrecognized custom action. // An unrecognized custom action.
Unknown(Value), Unknown(Value),
} }

View file

@ -129,6 +129,8 @@ def check_actions(actions: List[Union[str, JsonDict]]) -> None:
raise InvalidRuleException("No actions found") raise InvalidRuleException("No actions found")
for a in actions: for a in actions:
# "dont_notify" and "coalesce" are legacy actions. They are allowed, but
# ignored (resulting in no action from the pusher).
if a in ["notify", "dont_notify", "coalesce"]: if a in ["notify", "dont_notify", "coalesce"]:
pass pass
elif isinstance(a, dict) and "set_tweak" in a: elif isinstance(a, dict) and "set_tweak" in a: