Skip to content

Commit

Permalink
feat: time and day push rule condition python
Browse files Browse the repository at this point in the history
  • Loading branch information
hanadi92 committed Jan 27, 2024
1 parent 443368f commit 933e886
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
1 change: 1 addition & 0 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions synapse/synapse_rust/push.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions tests/push/test_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 933e886

Please sign in to comment.