Skip to content

Commit

Permalink
Send content rules with pattern_type to clients
Browse files Browse the repository at this point in the history
Dirty fix for matrix-org#14348

A proper fix would have proper tests and factor out the pattern_type
cases as well as clean up the logic.

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
  • Loading branch information
deepbluev7 committed Nov 2, 2022
1 parent 19a57f4 commit f7d2ad2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions synapse/push/clientformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def format_push_rules_for_user(

rulearray.append(template_rule)

pattern_type = template_rule.pop("pattern_type", None)
if pattern_type == "user_id":
template_rule["pattern"] = user.to_string()
elif pattern_type == "user_localpart":
template_rule["pattern"] = user.localpart

template_rule["enabled"] = enabled

if "conditions" not in template_rule:
Expand Down Expand Up @@ -93,10 +99,14 @@ def _rule_to_template(rule: PushRule) -> Optional[Dict[str, Any]]:
if len(rule.conditions) != 1:
return None
thecond = rule.conditions[0]
if "pattern" not in thecond:
return None

templaterule = {"actions": rule.actions}
templaterule["pattern"] = thecond["pattern"]
if "pattern" in thecond:
templaterule["pattern"] = thecond["pattern"]
elif "pattern_type" in thecond:
templaterule["pattern_type"] = thecond["pattern_type"]
else:
return None
else:
# This should not be reached unless this function is not kept in sync
# with PRIORITY_CLASS_INVERSE_MAP.
Expand Down

0 comments on commit f7d2ad2

Please sign in to comment.