Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Factor out function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Velten committed Jun 14, 2023
1 parent e6830ed commit e8c1f44
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions synapse/push/clientformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def format_push_rules_for_user(

rulearray.append(template_rule)

_convert_type_to_value(template_rule, user)

template_rule["enabled"] = enabled

if "conditions" not in template_rule:
Expand All @@ -56,16 +58,20 @@ def format_push_rules_for_user(
for c in template_rule["conditions"]:
c.pop("_cache_key", None)

for type_key in ("pattern", "sender", "value"):
type_value = c.pop(f"{type_key}_type", None)
if type_value == "user_id":
c[type_key] = user.to_string()
elif type_value == "user_localpart":
c[type_key] = user.localpart
_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] = []
Expand Down

0 comments on commit e8c1f44

Please sign in to comment.