diff options
author | Mathieu Velten <mathieuv@matrix.org> | 2023-06-16 14:17:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-16 14:17:02 +0200 |
commit | 0618bf94cdc56631e670b4e93e4dfaeae2162e73 (patch) | |
tree | 364472ca67d0ca96e6dc2502a7645b06a10a710d /synapse | |
parent | Regularly try to wake up dests instead of waiting for next PDU/EDU (#15743) (diff) | |
download | synapse-0618bf94cdc56631e670b4e93e4dfaeae2162e73.tar.xz |
push rules: fix internal conversion from _type to value (#15781)
Also fix wrong rule names for `is_user_mention` and `is_room_mention`.
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/push/clientformat.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/synapse/push/clientformat.py b/synapse/push/clientformat.py index 88b52c26a0..735cef0aed 100644 --- a/synapse/push/clientformat.py +++ b/synapse/push/clientformat.py @@ -41,12 +41,7 @@ def format_push_rules_for_user( rulearray.append(template_rule) - for type_key in ("pattern", "value"): - type_value = template_rule.pop(f"{type_key}_type", None) - if type_value == "user_id": - template_rule[type_key] = user.to_string() - elif type_value == "user_localpart": - template_rule[type_key] = user.localpart + _convert_type_to_value(template_rule, user) template_rule["enabled"] = enabled @@ -63,19 +58,20 @@ def format_push_rules_for_user( for c in template_rule["conditions"]: c.pop("_cache_key", None) - pattern_type = c.pop("pattern_type", None) - if pattern_type == "user_id": - c["pattern"] = user.to_string() - elif pattern_type == "user_localpart": - c["pattern"] = user.localpart - - sender_type = c.pop("sender_type", None) - if sender_type == "user_id": - c["sender"] = user.to_string() + _convert_type_to_value(c, user) return rules +def _convert_type_to_value(rule_or_cond: Dict[str, Any], user: UserID) -> None: + for type_key in ("pattern", "value"): + type_value = rule_or_cond.pop(f"{type_key}_type", None) + if type_value == "user_id": + rule_or_cond[type_key] = user.to_string() + elif type_value == "user_localpart": + rule_or_cond[type_key] = user.localpart + + def _add_empty_priority_class_arrays(d: Dict[str, list]) -> Dict[str, list]: for pc in PRIORITY_CLASS_MAP.keys(): d[pc] = [] |