From 933e8867c6e161f5936e4c264772a8107f3628d6 Mon Sep 17 00:00:00 2001 From: hanadi92 Date: Sat, 27 Jan 2024 19:50:15 +0100 Subject: [PATCH] feat: time and day push rule condition python --- synapse/config/experimental.py | 5 +++++ synapse/push/bulk_push_rule_evaluator.py | 1 + synapse/synapse_rust/push.pyi | 1 + tests/push/test_push_rule_evaluator.py | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index d43d9da956c..1ea5b264142 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -430,3 +430,8 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: self.msc4069_profile_inhibit_propagation = experimental.get( "msc4069_profile_inhibit_propagation", False ) + + # MSC3767: time based notification filtering + self.msc3767_time_and_day = experimental.get( + "org.matrix.msc3767.time_and_day", False + ) diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py index 34ab637c3d0..3fc1a4f59be 100644 --- a/synapse/push/bulk_push_rule_evaluator.py +++ b/synapse/push/bulk_push_rule_evaluator.py @@ -435,6 +435,7 @@ async def _action_for_event_by_user( self._related_event_match_enabled, event.room_version.msc3931_push_features, self.hs.config.experimental.msc1767_enabled, # MSC3931 flag + self.hs.config.experimental.msc3767_time_and_day, ) for uid, rules in rules_by_user.items(): diff --git a/synapse/synapse_rust/push.pyi b/synapse/synapse_rust/push.pyi index 27a974e1bbe..ba38ab0b35c 100644 --- a/synapse/synapse_rust/push.pyi +++ b/synapse/synapse_rust/push.pyi @@ -65,6 +65,7 @@ class PushRuleEvaluator: related_event_match_enabled: bool, room_version_feature_flags: Tuple[str, ...], msc3931_enabled: bool, + msc3767_time_and_day: bool, ): ... def run( self, diff --git a/tests/push/test_push_rule_evaluator.py b/tests/push/test_push_rule_evaluator.py index 420fbea9982..200e681ced7 100644 --- a/tests/push/test_push_rule_evaluator.py +++ b/tests/push/test_push_rule_evaluator.py @@ -174,6 +174,7 @@ def _get_evaluator( related_event_match_enabled=True, room_version_feature_flags=event.room_version.msc3931_push_features, msc3931_enabled=True, + msc3767_time_and_day=True, ) def test_display_name(self) -> None: @@ -802,6 +803,24 @@ def test_related_event_match_no_related_event(self) -> None: ) ) + def test_time_and_day_match(self) -> None: + # for testing, make whole day in do not disturb + condition = { + "kind": "org.matrix.msc3767.time_and_day", + "timezone": "", + "intervals": [ + { + "time_of_day": ["00:01", "23:59"], + "day_of_week": [0, 1, 2, 3, 4, 5, 6], + }, + ], + } + + evaluator = self._get_evaluator({"body": "foo bar baz"}) + action = evaluator.matches(condition, "@user:test", "user") + + self.assertTrue(action) + class TestBulkPushRuleEvaluator(unittest.HomeserverTestCase): """Tests for the bulk push rule evaluator"""