diff --git a/rust/src/push/evaluator.rs b/rust/src/push/evaluator.rs index 57a4c2752ed9..c64d0f266323 100644 --- a/rust/src/push/evaluator.rs +++ b/rust/src/push/evaluator.rs @@ -498,7 +498,7 @@ fn test_requires_room_version_supports_condition() { }; let rules = PushRules::new(vec![custom_rule]); result = evaluator.run( - &FilteredPushRules::py_new(rules, BTreeMap::new(), true, true), + &FilteredPushRules::py_new(rules, BTreeMap::new(), true, true, false), None, None, ); diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index 19a7db6cb144..59c2f24cc00b 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -417,6 +417,7 @@ pub struct FilteredPushRules { enabled_map: BTreeMap, msc3664_enabled: bool, msc1767_enabled: bool, + msc3952_intentional_mentions: bool, } #[pymethods] @@ -427,12 +428,14 @@ impl FilteredPushRules { enabled_map: BTreeMap, msc3664_enabled: bool, msc1767_enabled: bool, + msc3952_intentional_mentions: bool, ) -> Self { Self { push_rules, enabled_map, msc3664_enabled, msc1767_enabled, + msc3952_intentional_mentions, } } @@ -461,6 +464,11 @@ impl FilteredPushRules { return false; } + if !self.msc3952_intentional_mentions && rule.rule_id.contains("org.matrix.msc3952") + { + return false; + } + true }) .map(|r| { diff --git a/stubs/synapse/synapse_rust/push.pyi b/stubs/synapse/synapse_rust/push.pyi index 739bf4409cef..85562c8f44d4 100644 --- a/stubs/synapse/synapse_rust/push.pyi +++ b/stubs/synapse/synapse_rust/push.pyi @@ -45,6 +45,7 @@ class FilteredPushRules: enabled_map: Dict[str, bool], msc3664_enabled: bool, msc1767_enabled: bool, + msc3952_intentional_mentions: bool, ): ... def rules(self) -> Collection[Tuple[PushRule, bool]]: ... diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index a8b2db372d56..cf60a3b07848 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -142,3 +142,8 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: # MSC3925: do not replace events with their edits self.msc3925_inhibit_edit = experimental.get("msc3925_inhibit_edit", False) + + # MSC3952: Intentional mentions + self.msc3952_intentional_mentions = experimental.get( + "msc3952_intentional_mentions", False + ) diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py index d4e4b777da95..8e4059ff9837 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py @@ -88,6 +88,7 @@ def _load_rules( enabled_map, msc3664_enabled=experimental_config.msc3664_enabled, msc1767_enabled=experimental_config.msc1767_enabled, + msc3952_intentional_mentions=experimental_config.msc3952_intentional_mentions, ) return filtered_rules diff --git a/tests/push/test_bulk_push_rule_evaluator.py b/tests/push/test_bulk_push_rule_evaluator.py index d4cdb8728413..8e7afa9778e6 100644 --- a/tests/push/test_bulk_push_rule_evaluator.py +++ b/tests/push/test_bulk_push_rule_evaluator.py @@ -128,6 +128,7 @@ def test_action_for_event_by_user_disabled_by_config(self) -> None: self.get_success(bulk_evaluator.action_for_events_by_user([(event, context)])) bulk_evaluator._action_for_event_by_user.assert_not_called() + @override_config({"experimental_features": {"msc3952_intentional_mentions": True}}) def test_mentions(self) -> None: """Test the behavior of an event which includes invalid mentions.""" bulk_evaluator = BulkPushRuleEvaluator(self.hs)