summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-02-26 18:07:44 +0000
committerDavid Baker <dave@matrix.org>2015-02-26 18:07:44 +0000
commit19590881568f5aafd1b1d0b12cd6c10954ee60b1 (patch)
tree094ea5b8d0d973d0ffd0b635cf97ce37c2df154c /synapse/storage
parentwhitespace (diff)
downloadsynapse-19590881568f5aafd1b1d0b12cd6c10954ee60b1.tar.xz
Add API for getting/setting enabled-ness of push rules.
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/push_rule.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py
index cd8d0f6dde..6c38565773 100644
--- a/synapse/storage/push_rule.py
+++ b/synapse/storage/push_rule.py
@@ -57,6 +57,17 @@ class PushRuleStore(SQLBaseStore):
         )
 
     @defer.inlineCallbacks
+    def get_push_rule_enabled_by_user_name_rule_id(self, user_name, rule_id):
+        results = yield self._simple_select_list(
+            PushRuleEnableTable.table_name,
+            {'user_name': user_name, 'rule_id': rule_id},
+            ['enabled']
+        )
+        if len(results) == 0:
+            defer.returnValue(True)
+        defer.returnValue(results[0])
+
+    @defer.inlineCallbacks
     def add_push_rule(self, before, after, **kwargs):
         vals = copy.copy(kwargs)
         if 'conditions' in vals:
@@ -204,6 +215,19 @@ class PushRuleStore(SQLBaseStore):
             {'user_name': user_name, 'rule_id': rule_id}
         )
 
+    @defer.inlineCallbacks
+    def set_push_rule_enabled(self, user_name, rule_id, enabled):
+        if enabled:
+            yield self._simple_delete_one(
+                PushRuleEnableTable.table_name,
+                {'user_name': user_name, 'rule_id': rule_id}
+            )
+        else:
+            yield self._simple_upsert(
+                PushRuleEnableTable.table_name,
+                {'user_name': user_name, 'rule_id': rule_id},
+                {'enabled': False}
+            )
 
 class RuleNotFoundException(Exception):
     pass