2016-01-07 05:26:29 +01:00
|
|
|
# Copyright 2015, 2016 OpenMarket Ltd
|
2017-10-05 13:39:18 +02:00
|
|
|
# Copyright 2017 New Vector Ltd
|
2019-07-05 18:37:52 +02:00
|
|
|
# Copyright 2019 The Matrix.org Foundation C.I.C.
|
2015-04-24 11:35:29 +02:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
"""
|
|
|
|
Push rules is the system used to determine which events trigger a push (and a
|
|
|
|
bump in notification counts).
|
|
|
|
|
|
|
|
This consists of a list of "push rules" for each user, where a push rule is a
|
|
|
|
pair of "conditions" and "actions". When a user receives an event Synapse
|
|
|
|
iterates over the list of push rules until it finds one where all the conditions
|
|
|
|
match the event, at which point "actions" describe the outcome (e.g. notify,
|
|
|
|
highlight, etc).
|
|
|
|
|
|
|
|
Push rules are split up into 5 different "kinds" (aka "priority classes"), which
|
|
|
|
are run in order:
|
|
|
|
1. Override — highest priority rules, e.g. always ignore notices
|
|
|
|
2. Content — content specific rules, e.g. @ notifications
|
|
|
|
3. Room — per room rules, e.g. enable/disable notifications for all messages
|
|
|
|
in a room
|
|
|
|
4. Sender — per sender rules, e.g. never notify for messages from a given
|
|
|
|
user
|
|
|
|
5. Underride — the lowest priority "default" rules, e.g. notify for every
|
|
|
|
message.
|
|
|
|
|
|
|
|
The set of "base rules" are the list of rules that every user has by default. A
|
|
|
|
user can modify their copy of the push rules in one of three ways:
|
|
|
|
|
|
|
|
1. Adding a new push rule of a certain kind
|
|
|
|
2. Changing the actions of a base rule
|
|
|
|
3. Enabling/disabling a base rule.
|
|
|
|
|
|
|
|
The base rules are split into whether they come before or after a particular
|
|
|
|
kind, so the order of push rule evaluation would be: base rules for before
|
|
|
|
"override" kind, user defined "override" rules, base rules after "override"
|
|
|
|
kind, etc, etc.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import itertools
|
2022-08-17 13:02:38 +02:00
|
|
|
import logging
|
2022-08-16 13:22:17 +02:00
|
|
|
from typing import Dict, Iterator, List, Mapping, Sequence, Tuple, Union
|
|
|
|
|
|
|
|
import attr
|
|
|
|
|
|
|
|
from synapse.config.experimental import ExperimentalConfig
|
|
|
|
from synapse.push.rulekinds import PRIORITY_CLASS_MAP
|
|
|
|
|
2022-08-17 13:02:38 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
|
|
|
|
@attr.s(auto_attribs=True, slots=True, frozen=True)
|
|
|
|
class PushRule:
|
|
|
|
"""A push rule
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
rule_id: a unique ID for this rule
|
|
|
|
priority_class: what "kind" of push rule this is (see
|
|
|
|
`PRIORITY_CLASS_MAP` for mapping between int and kind)
|
|
|
|
conditions: the sequence of conditions that all need to match
|
|
|
|
actions: the actions to apply if all conditions are met
|
|
|
|
default: is this a base rule?
|
|
|
|
default_enabled: is this enabled by default?
|
|
|
|
"""
|
2018-07-09 08:09:20 +02:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
rule_id: str
|
|
|
|
priority_class: int
|
|
|
|
conditions: Sequence[Mapping[str, str]]
|
|
|
|
actions: Sequence[Union[str, Mapping]]
|
|
|
|
default: bool = False
|
|
|
|
default_enabled: bool = True
|
2015-02-10 17:30:48 +01:00
|
|
|
|
2016-02-26 15:28:19 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
@attr.s(auto_attribs=True, slots=True, frozen=True, weakref_slot=False)
|
|
|
|
class PushRules:
|
|
|
|
"""A collection of push rules for an account.
|
2016-04-01 17:08:59 +02:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
Can be iterated over, producing push rules in priority order.
|
2016-02-26 15:28:19 +01:00
|
|
|
"""
|
2015-02-05 15:46:06 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
# A mapping from rule ID to push rule that overrides a base rule. These will
|
|
|
|
# be returned instead of the base rule.
|
|
|
|
overriden_base_rules: Dict[str, PushRule] = attr.Factory(dict)
|
|
|
|
|
|
|
|
# The following stores the custom push rules at each priority class.
|
|
|
|
#
|
|
|
|
# We keep these separate (rather than combining into one big list) to avoid
|
|
|
|
# copying the base rules around all the time.
|
|
|
|
override: List[PushRule] = attr.Factory(list)
|
|
|
|
content: List[PushRule] = attr.Factory(list)
|
|
|
|
room: List[PushRule] = attr.Factory(list)
|
|
|
|
sender: List[PushRule] = attr.Factory(list)
|
|
|
|
underride: List[PushRule] = attr.Factory(list)
|
|
|
|
|
|
|
|
def __iter__(self) -> Iterator[PushRule]:
|
|
|
|
# When iterating over the push rules we need to return the base rules
|
|
|
|
# interspersed at the correct spots.
|
|
|
|
for rule in itertools.chain(
|
|
|
|
BASE_PREPEND_OVERRIDE_RULES,
|
|
|
|
self.override,
|
|
|
|
BASE_APPEND_OVERRIDE_RULES,
|
|
|
|
self.content,
|
|
|
|
BASE_APPEND_CONTENT_RULES,
|
|
|
|
self.room,
|
|
|
|
self.sender,
|
|
|
|
self.underride,
|
|
|
|
BASE_APPEND_UNDERRIDE_RULES,
|
|
|
|
):
|
|
|
|
# Check if a base rule has been overriden by a custom rule. If so
|
|
|
|
# return that instead.
|
|
|
|
override_rule = self.overriden_base_rules.get(rule.rule_id)
|
|
|
|
if override_rule:
|
|
|
|
yield override_rule
|
|
|
|
else:
|
|
|
|
yield rule
|
|
|
|
|
|
|
|
def __len__(self) -> int:
|
|
|
|
# The length is mostly used by caches to get a sense of "size" / amount
|
|
|
|
# of memory this object is using, so we only count the number of custom
|
|
|
|
# rules.
|
|
|
|
return (
|
|
|
|
len(self.overriden_base_rules)
|
|
|
|
+ len(self.override)
|
|
|
|
+ len(self.content)
|
|
|
|
+ len(self.room)
|
|
|
|
+ len(self.sender)
|
|
|
|
+ len(self.underride)
|
|
|
|
)
|
2016-02-26 15:28:19 +01:00
|
|
|
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
@attr.s(auto_attribs=True, slots=True, frozen=True, weakref_slot=False)
|
|
|
|
class FilteredPushRules:
|
|
|
|
"""A wrapper around `PushRules` that filters out disabled experimental push
|
|
|
|
rules, and includes the "enabled" state for each rule when iterated over.
|
|
|
|
"""
|
2015-03-10 18:26:25 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
push_rules: PushRules
|
|
|
|
enabled_map: Dict[str, bool]
|
|
|
|
experimental_config: ExperimentalConfig
|
2015-03-10 18:26:25 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
def __iter__(self) -> Iterator[Tuple[PushRule, bool]]:
|
|
|
|
for rule in self.push_rules:
|
|
|
|
if not _is_experimental_rule_enabled(
|
|
|
|
rule.rule_id, self.experimental_config
|
|
|
|
):
|
|
|
|
continue
|
2015-02-05 15:46:06 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
enabled = self.enabled_map.get(rule.rule_id, rule.default_enabled)
|
2015-02-05 15:46:06 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
yield rule, enabled
|
2015-02-05 15:46:06 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
def __len__(self) -> int:
|
|
|
|
return len(self.push_rules)
|
2015-02-05 15:46:06 +01:00
|
|
|
|
2015-03-10 18:26:25 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
DEFAULT_EMPTY_PUSH_RULES = PushRules()
|
2016-02-26 15:28:19 +01:00
|
|
|
|
2015-03-10 18:26:25 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
def compile_push_rules(rawrules: List[PushRule]) -> PushRules:
|
|
|
|
"""Given a set of custom push rules return a `PushRules` instance (which
|
|
|
|
includes the base rules).
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not rawrules:
|
|
|
|
# Fast path to avoid allocating empty lists when there are no custom
|
|
|
|
# rules for the user.
|
|
|
|
return DEFAULT_EMPTY_PUSH_RULES
|
2015-03-11 11:01:17 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
rules = PushRules()
|
2015-03-10 18:26:25 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
for rule in rawrules:
|
|
|
|
# We need to decide which bucket each custom push rule goes into.
|
2015-02-05 15:46:06 +01:00
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
# If it has the same ID as a base rule then it overrides that...
|
|
|
|
overriden_base_rule = BASE_RULES_BY_ID.get(rule.rule_id)
|
|
|
|
if overriden_base_rule:
|
|
|
|
rules.overriden_base_rules[rule.rule_id] = attr.evolve(
|
|
|
|
overriden_base_rule, actions=rule.actions
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# ... otherwise it gets added to the appropriate priority class bucket
|
|
|
|
collection: List[PushRule]
|
|
|
|
if rule.priority_class == 5:
|
|
|
|
collection = rules.override
|
|
|
|
elif rule.priority_class == 4:
|
|
|
|
collection = rules.content
|
|
|
|
elif rule.priority_class == 3:
|
|
|
|
collection = rules.room
|
|
|
|
elif rule.priority_class == 2:
|
|
|
|
collection = rules.sender
|
|
|
|
elif rule.priority_class == 1:
|
|
|
|
collection = rules.underride
|
2022-08-17 13:02:38 +02:00
|
|
|
elif rule.priority_class <= 0:
|
|
|
|
logger.info(
|
|
|
|
"Got rule with priority class less than zero, but doesn't override a base rule: %s",
|
|
|
|
rule,
|
|
|
|
)
|
|
|
|
continue
|
2022-08-16 13:22:17 +02:00
|
|
|
else:
|
2022-08-17 13:02:38 +02:00
|
|
|
# We log and continue here so as not to break event sending
|
|
|
|
logger.error("Unknown priority class: %", rule.priority_class)
|
|
|
|
continue
|
2022-08-16 13:22:17 +02:00
|
|
|
|
|
|
|
collection.append(rule)
|
2016-02-26 15:28:19 +01:00
|
|
|
|
2015-02-05 15:46:06 +01:00
|
|
|
return rules
|
|
|
|
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
def _is_experimental_rule_enabled(
|
|
|
|
rule_id: str, experimental_config: ExperimentalConfig
|
|
|
|
) -> bool:
|
|
|
|
"""Used by `FilteredPushRules` to filter out experimental rules when they
|
|
|
|
have not been enabled.
|
|
|
|
"""
|
|
|
|
if (
|
|
|
|
rule_id == "global/override/.org.matrix.msc3786.rule.room.server_acl"
|
|
|
|
and not experimental_config.msc3786_enabled
|
|
|
|
):
|
|
|
|
return False
|
|
|
|
if (
|
|
|
|
rule_id == "global/underride/.org.matrix.msc3772.thread_reply"
|
|
|
|
and not experimental_config.msc3772_enabled
|
|
|
|
):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
BASE_APPEND_CONTENT_RULES = [
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["content"],
|
|
|
|
rule_id="global/content/.m.rule.contains_user_name",
|
|
|
|
conditions=[
|
2016-01-18 11:09:14 +01:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "content.body",
|
2022-05-24 15:23:23 +02:00
|
|
|
# Match the localpart of the requester's MXID.
|
2019-06-20 11:32:02 +02:00
|
|
|
"pattern_type": "user_localpart",
|
2016-01-18 11:09:14 +01:00
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=[
|
2019-06-20 11:32:02 +02:00
|
|
|
"notify",
|
|
|
|
{"set_tweak": "sound", "value": "default"},
|
|
|
|
{"set_tweak": "highlight"},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
)
|
2016-01-18 11:09:14 +01:00
|
|
|
]
|
2015-02-05 15:46:06 +01:00
|
|
|
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_PREPEND_OVERRIDE_RULES = [
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.master",
|
|
|
|
default_enabled=False,
|
|
|
|
conditions=[],
|
|
|
|
actions=["dont_notify"],
|
|
|
|
)
|
2016-01-18 11:09:14 +01:00
|
|
|
]
|
2015-03-10 18:26:25 +01:00
|
|
|
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_APPEND_OVERRIDE_RULES = [
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.suppress_notices",
|
|
|
|
conditions=[
|
2016-01-18 11:09:14 +01:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "content.msgtype",
|
|
|
|
"pattern": "m.notice",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_suppress_notices",
|
2016-01-18 11:09:14 +01:00
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["dont_notify"],
|
|
|
|
),
|
2016-04-08 16:29:59 +02:00
|
|
|
# NB. .m.rule.invite_for_me must be higher prio than .m.rule.member_event
|
|
|
|
# otherwise invites will be matched by .m.rule.member_event
|
2022-08-16 13:22:17 +02:00
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.invite_for_me",
|
|
|
|
conditions=[
|
2016-04-08 16:29:59 +02:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.member",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_member",
|
2016-04-08 16:29:59 +02:00
|
|
|
},
|
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "content.membership",
|
|
|
|
"pattern": "invite",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_invite_member",
|
2016-04-08 16:29:59 +02:00
|
|
|
},
|
2022-05-24 15:23:23 +02:00
|
|
|
# Match the requester's MXID.
|
2019-06-20 11:32:02 +02:00
|
|
|
{"kind": "event_match", "key": "state_key", "pattern_type": "user_id"},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=[
|
2019-06-20 11:32:02 +02:00
|
|
|
"notify",
|
|
|
|
{"set_tweak": "sound", "value": "default"},
|
|
|
|
{"set_tweak": "highlight", "value": False},
|
2016-04-08 16:29:59 +02:00
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
),
|
2016-03-24 14:19:39 +01:00
|
|
|
# Will we sometimes want to know about people joining and leaving?
|
|
|
|
# Perhaps: if so, this could be expanded upon. Seems the most usual case
|
|
|
|
# is that we don't though. We add this override rule so that even if
|
|
|
|
# the room rule is set to notify, we don't get notifications about
|
|
|
|
# join/leave/avatar/displayname events.
|
|
|
|
# See also: https://matrix.org/jira/browse/SYN-607
|
2022-08-16 13:22:17 +02:00
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.member_event",
|
|
|
|
conditions=[
|
2016-03-24 14:19:39 +01:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.member",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_member",
|
2016-03-24 14:19:39 +01:00
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["dont_notify"],
|
|
|
|
),
|
2016-08-15 19:34:53 +02:00
|
|
|
# This was changed from underride to override so it's closer in priority
|
|
|
|
# to the content rules where the user name highlight rule lives. This
|
|
|
|
# way a room rule is lower priority than both but a custom override rule
|
|
|
|
# is higher priority than both.
|
2022-08-16 13:22:17 +02:00
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.contains_display_name",
|
|
|
|
conditions=[{"kind": "contains_display_name"}],
|
|
|
|
actions=[
|
2019-06-20 11:32:02 +02:00
|
|
|
"notify",
|
|
|
|
{"set_tweak": "sound", "value": "default"},
|
|
|
|
{"set_tweak": "highlight"},
|
2016-01-18 11:09:14 +01:00
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
),
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.roomnotif",
|
|
|
|
conditions=[
|
2017-10-05 13:39:18 +02:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "content.body",
|
|
|
|
"pattern": "@room",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_roomnotif_content",
|
2017-10-05 13:39:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "sender_notification_permission",
|
|
|
|
"key": "room",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_roomnotif_pl",
|
2017-10-05 13:39:18 +02:00
|
|
|
},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["notify", {"set_tweak": "highlight", "value": True}],
|
|
|
|
),
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.tombstone",
|
|
|
|
conditions=[
|
2019-04-29 23:40:31 +02:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.tombstone",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_tombstone",
|
2019-07-31 17:22:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"kind": "event_match",
|
|
|
|
"key": "state_key",
|
|
|
|
"pattern": "",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_tombstone_statekey",
|
2019-07-31 17:22:38 +02:00
|
|
|
},
|
2019-04-29 23:40:31 +02:00
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["notify", {"set_tweak": "highlight", "value": True}],
|
|
|
|
),
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.m.rule.reaction",
|
|
|
|
conditions=[
|
2019-07-05 18:37:52 +02:00
|
|
|
{
|
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.reaction",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_reaction",
|
2019-07-05 18:37:52 +02:00
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["dont_notify"],
|
|
|
|
),
|
2022-05-10 09:57:36 +02:00
|
|
|
# XXX: This is an experimental rule that is only enabled if msc3786_enabled
|
|
|
|
# is enabled, if it is not the rule gets filtered out in _load_rules() in
|
|
|
|
# PushRulesWorkerStore
|
2022-08-16 13:22:17 +02:00
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["override"],
|
|
|
|
rule_id="global/override/.org.matrix.msc3786.rule.room.server_acl",
|
|
|
|
conditions=[
|
2022-05-10 09:57:36 +02:00
|
|
|
{
|
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.server_acl",
|
|
|
|
"_cache_key": "_room_server_acl",
|
2022-06-27 21:28:34 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"kind": "event_match",
|
|
|
|
"key": "state_key",
|
|
|
|
"pattern": "",
|
|
|
|
"_cache_key": "_room_server_acl_state_key",
|
|
|
|
},
|
2022-05-10 09:57:36 +02:00
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=[],
|
|
|
|
),
|
2016-08-15 19:34:53 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_APPEND_UNDERRIDE_RULES = [
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["underride"],
|
|
|
|
rule_id="global/underride/.m.rule.call",
|
|
|
|
conditions=[
|
2016-01-18 11:09:14 +01:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.call.invite",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_call",
|
2016-01-18 11:09:14 +01:00
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=[
|
2019-06-20 11:32:02 +02:00
|
|
|
"notify",
|
|
|
|
{"set_tweak": "sound", "value": "ring"},
|
|
|
|
{"set_tweak": "highlight", "value": False},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
),
|
2016-09-17 23:05:06 +02:00
|
|
|
# XXX: once m.direct is standardised everywhere, we should use it to detect
|
|
|
|
# a DM from the user's perspective rather than this heuristic.
|
2022-08-16 13:22:17 +02:00
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["underride"],
|
|
|
|
rule_id="global/underride/.m.rule.room_one_to_one",
|
|
|
|
conditions=[
|
2022-03-11 14:45:26 +01:00
|
|
|
{"kind": "room_member_count", "is": "2", "_cache_key": "member_count"},
|
2016-01-18 11:09:14 +01:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.message",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_message",
|
2016-01-26 11:21:41 +01:00
|
|
|
},
|
2016-01-18 11:09:14 +01:00
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=[
|
2019-06-20 11:32:02 +02:00
|
|
|
"notify",
|
|
|
|
{"set_tweak": "sound", "value": "default"},
|
|
|
|
{"set_tweak": "highlight", "value": False},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
),
|
2016-09-17 23:05:06 +02:00
|
|
|
# XXX: this is going to fire for events which aren't m.room.messages
|
|
|
|
# but are encrypted (e.g. m.call.*)...
|
2022-08-16 13:22:17 +02:00
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["underride"],
|
|
|
|
rule_id="global/underride/.m.rule.encrypted_room_one_to_one",
|
|
|
|
conditions=[
|
2022-03-11 14:45:26 +01:00
|
|
|
{"kind": "room_member_count", "is": "2", "_cache_key": "member_count"},
|
2016-09-17 23:05:06 +02:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.encrypted",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_encrypted",
|
2016-09-17 23:05:06 +02:00
|
|
|
},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=[
|
2019-06-20 11:32:02 +02:00
|
|
|
"notify",
|
|
|
|
{"set_tweak": "sound", "value": "default"},
|
|
|
|
{"set_tweak": "highlight", "value": False},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
),
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["underride"],
|
|
|
|
rule_id="global/underride/.org.matrix.msc3772.thread_reply",
|
|
|
|
conditions=[
|
2022-05-24 15:23:23 +02:00
|
|
|
{
|
|
|
|
"kind": "org.matrix.msc3772.relation_match",
|
|
|
|
"rel_type": "m.thread",
|
|
|
|
# Match the requester's MXID.
|
|
|
|
"sender_type": "user_id",
|
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["notify", {"set_tweak": "highlight", "value": False}],
|
|
|
|
),
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["underride"],
|
|
|
|
rule_id="global/underride/.m.rule.message",
|
|
|
|
conditions=[
|
2016-01-18 11:09:14 +01:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.message",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_message",
|
2016-01-18 11:09:14 +01:00
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["notify", {"set_tweak": "highlight", "value": False}],
|
|
|
|
),
|
2016-09-17 23:05:06 +02:00
|
|
|
# XXX: this is going to fire for events which aren't m.room.messages
|
|
|
|
# but are encrypted (e.g. m.call.*)...
|
2022-08-16 13:22:17 +02:00
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["underride"],
|
|
|
|
rule_id="global/underride/.m.rule.encrypted",
|
|
|
|
conditions=[
|
2016-09-17 23:05:06 +02:00
|
|
|
{
|
2019-06-20 11:32:02 +02:00
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "m.room.encrypted",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_encrypted",
|
2016-09-17 23:05:06 +02:00
|
|
|
}
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["notify", {"set_tweak": "highlight", "value": False}],
|
|
|
|
),
|
|
|
|
PushRule(
|
|
|
|
default=True,
|
|
|
|
priority_class=PRIORITY_CLASS_MAP["underride"],
|
|
|
|
rule_id="global/underride/.im.vector.jitsi",
|
|
|
|
conditions=[
|
2020-11-02 17:36:14 +01:00
|
|
|
{
|
|
|
|
"kind": "event_match",
|
|
|
|
"key": "type",
|
|
|
|
"pattern": "im.vector.modular.widgets",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_type_modular_widgets",
|
2020-11-02 17:36:14 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"kind": "event_match",
|
|
|
|
"key": "content.type",
|
|
|
|
"pattern": "jitsi",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_content_type_jitsi",
|
2020-11-02 17:36:14 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"kind": "event_match",
|
|
|
|
"key": "state_key",
|
|
|
|
"pattern": "*",
|
2022-03-11 14:45:26 +01:00
|
|
|
"_cache_key": "_is_state_event",
|
2020-11-02 17:36:14 +01:00
|
|
|
},
|
|
|
|
],
|
2022-08-16 13:22:17 +02:00
|
|
|
actions=["notify", {"set_tweak": "highlight", "value": False}],
|
|
|
|
),
|
2016-01-18 11:09:14 +01:00
|
|
|
]
|
2015-02-05 15:46:06 +01:00
|
|
|
|
2015-03-10 18:26:25 +01:00
|
|
|
|
2016-02-26 15:28:19 +01:00
|
|
|
BASE_RULE_IDS = set()
|
|
|
|
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_RULES_BY_ID: Dict[str, PushRule] = {}
|
|
|
|
|
2016-01-18 16:29:41 +01:00
|
|
|
for r in BASE_APPEND_CONTENT_RULES:
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_RULE_IDS.add(r.rule_id)
|
|
|
|
BASE_RULES_BY_ID[r.rule_id] = r
|
2015-03-10 18:26:25 +01:00
|
|
|
|
2016-01-18 16:29:41 +01:00
|
|
|
for r in BASE_PREPEND_OVERRIDE_RULES:
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_RULE_IDS.add(r.rule_id)
|
|
|
|
BASE_RULES_BY_ID[r.rule_id] = r
|
2015-04-24 15:26:33 +02:00
|
|
|
|
2016-04-08 16:29:59 +02:00
|
|
|
for r in BASE_APPEND_OVERRIDE_RULES:
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_RULE_IDS.add(r.rule_id)
|
|
|
|
BASE_RULES_BY_ID[r.rule_id] = r
|
2015-04-24 15:26:33 +02:00
|
|
|
|
2016-01-18 16:29:41 +01:00
|
|
|
for r in BASE_APPEND_UNDERRIDE_RULES:
|
2022-08-16 13:22:17 +02:00
|
|
|
BASE_RULE_IDS.add(r.rule_id)
|
|
|
|
BASE_RULES_BY_ID[r.rule_id] = r
|