diff options
author | Mark Haines <mjark@negativecurvature.net> | 2016-02-26 14:28:28 +0000 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2016-02-26 14:28:28 +0000 |
commit | 4bf13a8207712c2d8384b735aff4450862107b7e (patch) | |
tree | 6097241510c835b64f918a5287429a4f6684fb5b /synapse/storage | |
parent | Merge pull request #608 from gergelypolonkai/syn-638 (diff) | |
parent | Add support for changing the actions for default rules (diff) | |
download | synapse-4bf13a8207712c2d8384b735aff4450862107b7e.tar.xz |
Merge pull request #609 from matrix-org/markjh/change_action
Add support for changing the actions for default rules See matrix-org/matrix-doc#283 Works by adding dummy rules to the push rules table with a negative priority class and then using those rules to clobber the default rule actions when adding the default rules in ``list_with_base_rules``
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/push_rule.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py index e19a81e41f..bb5c14d912 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/push_rule.py @@ -294,6 +294,31 @@ class PushRuleStore(SQLBaseStore): self.get_push_rules_enabled_for_user.invalidate, (user_id,) ) + def set_push_rule_actions(self, user_id, rule_id, actions, is_default_rule): + actions_json = json.dumps(actions) + + def set_push_rule_actions_txn(txn): + if is_default_rule: + # Add a dummy rule to the rules table with the user specified + # actions. + priority_class = -1 + priority = 1 + self._upsert_push_rule_txn( + txn, user_id, rule_id, priority_class, priority, + "[]", actions_json + ) + else: + self._simple_update_one_txn( + txn, + "push_rules", + {'user_name': user_id, 'rule_id': rule_id}, + {'actions': actions_json}, + ) + + return self.runInteraction( + "set_push_rule_actions", set_push_rule_actions_txn, + ) + class RuleNotFoundException(Exception): pass |