diff --git a/synapse/push/baserules.py b/synapse/push/baserules.py index 81532bf469f6..a681fea5a1f5 100644 --- a/synapse/push/baserules.py +++ b/synapse/push/baserules.py @@ -181,22 +181,20 @@ def _is_experimental_rule_enabled( PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["content"], - **{ - "rule_id": "global/content/.m.rule.contains_user_name", - "conditions": [ - { - "kind": "event_match", - "key": "content.body", - # Match the localpart of the requester's MXID. - "pattern_type": "user_localpart", - } - ], - "actions": [ - "notify", - {"set_tweak": "sound", "value": "default"}, - {"set_tweak": "highlight"}, - ], - }, + rule_id="global/content/.m.rule.contains_user_name", + conditions=[ + { + "kind": "event_match", + "key": "content.body", + # Match the localpart of the requester's MXID. + "pattern_type": "user_localpart", + } + ], + actions=[ + "notify", + {"set_tweak": "sound", "value": "default"}, + {"set_tweak": "highlight"}, + ], ) ] @@ -205,12 +203,10 @@ def _is_experimental_rule_enabled( PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.master", - "enabled": False, - "conditions": [], - "actions": ["dont_notify"], - }, + rule_id="global/override/.m.rule.master", + enabled=False, + conditions=[], + actions=["dont_notify"], ) ] @@ -219,48 +215,44 @@ def _is_experimental_rule_enabled( PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.suppress_notices", - "conditions": [ - { - "kind": "event_match", - "key": "content.msgtype", - "pattern": "m.notice", - "_cache_key": "_suppress_notices", - } - ], - "actions": ["dont_notify"], - }, + rule_id="global/override/.m.rule.suppress_notices", + conditions=[ + { + "kind": "event_match", + "key": "content.msgtype", + "pattern": "m.notice", + "_cache_key": "_suppress_notices", + } + ], + actions=["dont_notify"], ), # 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 PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.invite_for_me", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.member", - "_cache_key": "_member", - }, - { - "kind": "event_match", - "key": "content.membership", - "pattern": "invite", - "_cache_key": "_invite_member", - }, - # Match the requester's MXID. - {"kind": "event_match", "key": "state_key", "pattern_type": "user_id"}, - ], - "actions": [ - "notify", - {"set_tweak": "sound", "value": "default"}, - {"set_tweak": "highlight", "value": False}, - ], - }, + rule_id="global/override/.m.rule.invite_for_me", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.member", + "_cache_key": "_member", + }, + { + "kind": "event_match", + "key": "content.membership", + "pattern": "invite", + "_cache_key": "_invite_member", + }, + # Match the requester's MXID. + {"kind": "event_match", "key": "state_key", "pattern_type": "user_id"}, + ], + actions=[ + "notify", + {"set_tweak": "sound", "value": "default"}, + {"set_tweak": "highlight", "value": False}, + ], ), # Will we sometimes want to know about people joining and leaving? # Perhaps: if so, this could be expanded upon. Seems the most usual case @@ -271,18 +263,16 @@ def _is_experimental_rule_enabled( PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.member_event", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.member", - "_cache_key": "_member", - } - ], - "actions": ["dont_notify"], - }, + rule_id="global/override/.m.rule.member_event", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.member", + "_cache_key": "_member", + } + ], + actions=["dont_notify"], ), # 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 @@ -291,74 +281,66 @@ def _is_experimental_rule_enabled( PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.contains_display_name", - "conditions": [{"kind": "contains_display_name"}], - "actions": [ - "notify", - {"set_tweak": "sound", "value": "default"}, - {"set_tweak": "highlight"}, - ], - }, + rule_id="global/override/.m.rule.contains_display_name", + conditions=[{"kind": "contains_display_name"}], + actions=[ + "notify", + {"set_tweak": "sound", "value": "default"}, + {"set_tweak": "highlight"}, + ], ), PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.roomnotif", - "conditions": [ - { - "kind": "event_match", - "key": "content.body", - "pattern": "@room", - "_cache_key": "_roomnotif_content", - }, - { - "kind": "sender_notification_permission", - "key": "room", - "_cache_key": "_roomnotif_pl", - }, - ], - "actions": ["notify", {"set_tweak": "highlight", "value": True}], - }, + rule_id="global/override/.m.rule.roomnotif", + conditions=[ + { + "kind": "event_match", + "key": "content.body", + "pattern": "@room", + "_cache_key": "_roomnotif_content", + }, + { + "kind": "sender_notification_permission", + "key": "room", + "_cache_key": "_roomnotif_pl", + }, + ], + actions=["notify", {"set_tweak": "highlight", "value": True}], ), PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.tombstone", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.tombstone", - "_cache_key": "_tombstone", - }, - { - "kind": "event_match", - "key": "state_key", - "pattern": "", - "_cache_key": "_tombstone_statekey", - }, - ], - "actions": ["notify", {"set_tweak": "highlight", "value": True}], - }, + rule_id="global/override/.m.rule.tombstone", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.tombstone", + "_cache_key": "_tombstone", + }, + { + "kind": "event_match", + "key": "state_key", + "pattern": "", + "_cache_key": "_tombstone_statekey", + }, + ], + actions=["notify", {"set_tweak": "highlight", "value": True}], ), PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.m.rule.reaction", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.reaction", - "_cache_key": "_reaction", - } - ], - "actions": ["dont_notify"], - }, + rule_id="global/override/.m.rule.reaction", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.reaction", + "_cache_key": "_reaction", + } + ], + actions=["dont_notify"], ), # 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 @@ -366,24 +348,22 @@ def _is_experimental_rule_enabled( PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["override"], - **{ - "rule_id": "global/override/.org.matrix.msc3786.rule.room.server_acl", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.server_acl", - "_cache_key": "_room_server_acl", - }, - { - "kind": "event_match", - "key": "state_key", - "pattern": "", - "_cache_key": "_room_server_acl_state_key", - }, - ], - "actions": [], - }, + rule_id="global/override/.org.matrix.msc3786.rule.room.server_acl", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.server_acl", + "_cache_key": "_room_server_acl", + }, + { + "kind": "event_match", + "key": "state_key", + "pattern": "", + "_cache_key": "_room_server_acl_state_key", + }, + ], + actions=[], ), ] @@ -392,146 +372,132 @@ def _is_experimental_rule_enabled( PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["underride"], - **{ - "rule_id": "global/underride/.m.rule.call", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.call.invite", - "_cache_key": "_call", - } - ], - "actions": [ - "notify", - {"set_tweak": "sound", "value": "ring"}, - {"set_tweak": "highlight", "value": False}, - ], - }, + rule_id="global/underride/.m.rule.call", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.call.invite", + "_cache_key": "_call", + } + ], + actions=[ + "notify", + {"set_tweak": "sound", "value": "ring"}, + {"set_tweak": "highlight", "value": False}, + ], ), # XXX: once m.direct is standardised everywhere, we should use it to detect # a DM from the user's perspective rather than this heuristic. PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["underride"], - **{ - "rule_id": "global/underride/.m.rule.room_one_to_one", - "conditions": [ - {"kind": "room_member_count", "is": "2", "_cache_key": "member_count"}, - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.message", - "_cache_key": "_message", - }, - ], - "actions": [ - "notify", - {"set_tweak": "sound", "value": "default"}, - {"set_tweak": "highlight", "value": False}, - ], - }, + rule_id="global/underride/.m.rule.room_one_to_one", + conditions=[ + {"kind": "room_member_count", "is": "2", "_cache_key": "member_count"}, + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.message", + "_cache_key": "_message", + }, + ], + actions=[ + "notify", + {"set_tweak": "sound", "value": "default"}, + {"set_tweak": "highlight", "value": False}, + ], ), # XXX: this is going to fire for events which aren't m.room.messages # but are encrypted (e.g. m.call.*)... PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["underride"], - **{ - "rule_id": "global/underride/.m.rule.encrypted_room_one_to_one", - "conditions": [ - {"kind": "room_member_count", "is": "2", "_cache_key": "member_count"}, - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.encrypted", - "_cache_key": "_encrypted", - }, - ], - "actions": [ - "notify", - {"set_tweak": "sound", "value": "default"}, - {"set_tweak": "highlight", "value": False}, - ], - }, + rule_id="global/underride/.m.rule.encrypted_room_one_to_one", + conditions=[ + {"kind": "room_member_count", "is": "2", "_cache_key": "member_count"}, + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.encrypted", + "_cache_key": "_encrypted", + }, + ], + actions=[ + "notify", + {"set_tweak": "sound", "value": "default"}, + {"set_tweak": "highlight", "value": False}, + ], ), PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["underride"], - **{ - "rule_id": "global/underride/.org.matrix.msc3772.thread_reply", - "conditions": [ - { - "kind": "org.matrix.msc3772.relation_match", - "rel_type": "m.thread", - # Match the requester's MXID. - "sender_type": "user_id", - } - ], - "actions": ["notify", {"set_tweak": "highlight", "value": False}], - }, + rule_id="global/underride/.org.matrix.msc3772.thread_reply", + conditions=[ + { + "kind": "org.matrix.msc3772.relation_match", + "rel_type": "m.thread", + # Match the requester's MXID. + "sender_type": "user_id", + } + ], + actions=["notify", {"set_tweak": "highlight", "value": False}], ), PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["underride"], - **{ - "rule_id": "global/underride/.m.rule.message", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.message", - "_cache_key": "_message", - } - ], - "actions": ["notify", {"set_tweak": "highlight", "value": False}], - }, + rule_id="global/underride/.m.rule.message", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.message", + "_cache_key": "_message", + } + ], + actions=["notify", {"set_tweak": "highlight", "value": False}], ), # XXX: this is going to fire for events which aren't m.room.messages # but are encrypted (e.g. m.call.*)... PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["underride"], - **{ - "rule_id": "global/underride/.m.rule.encrypted", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "m.room.encrypted", - "_cache_key": "_encrypted", - } - ], - "actions": ["notify", {"set_tweak": "highlight", "value": False}], - }, + rule_id="global/underride/.m.rule.encrypted", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "m.room.encrypted", + "_cache_key": "_encrypted", + } + ], + actions=["notify", {"set_tweak": "highlight", "value": False}], ), PushRule( default=True, priority_class=PRIORITY_CLASS_MAP["underride"], - **{ - "rule_id": "global/underride/.im.vector.jitsi", - "conditions": [ - { - "kind": "event_match", - "key": "type", - "pattern": "im.vector.modular.widgets", - "_cache_key": "_type_modular_widgets", - }, - { - "kind": "event_match", - "key": "content.type", - "pattern": "jitsi", - "_cache_key": "_content_type_jitsi", - }, - { - "kind": "event_match", - "key": "state_key", - "pattern": "*", - "_cache_key": "_is_state_event", - }, - ], - "actions": ["notify", {"set_tweak": "highlight", "value": False}], - }, + rule_id="global/underride/.im.vector.jitsi", + conditions=[ + { + "kind": "event_match", + "key": "type", + "pattern": "im.vector.modular.widgets", + "_cache_key": "_type_modular_widgets", + }, + { + "kind": "event_match", + "key": "content.type", + "pattern": "jitsi", + "_cache_key": "_content_type_jitsi", + }, + { + "kind": "event_match", + "key": "state_key", + "pattern": "*", + "_cache_key": "_is_state_event", + }, + ], + actions=["notify", {"set_tweak": "highlight", "value": False}], ), ]