summary refs log tree commit diff
path: root/synapse/push
diff options
context:
space:
mode:
authorDavid Baker <dbkr@users.noreply.github.com>2016-01-22 15:25:52 +0000
committerDavid Baker <dbkr@users.noreply.github.com>2016-01-22 15:25:52 +0000
commit74f49f99f9d82f749897ca52b1fd92fe634476c5 (patch)
tree39227aed811880ffbcd5a23c07a08b1f8edead22 /synapse/push
parentMerge pull request #519 from matrix-org/dbkr/treecache (diff)
parentDon't crash if a user has no push rule enabled entries (diff)
downloadsynapse-74f49f99f9d82f749897ca52b1fd92fe634476c5.tar.xz
Merge pull request #520 from matrix-org/dbkr/bulk_push_overlay_enabled
Overlay the push_rules_enabled map for users
Diffstat (limited to 'synapse/push')
-rw-r--r--synapse/push/bulk_push_rule_evaluator.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py
index b91c165e2b..06250d2d96 100644
--- a/synapse/push/bulk_push_rule_evaluator.py
+++ b/synapse/push/bulk_push_rule_evaluator.py
@@ -36,6 +36,7 @@ def decode_rule_json(rule):
 @defer.inlineCallbacks
 def _get_rules(room_id, user_ids, store):
     rules_by_user = yield store.bulk_get_push_rules(user_ids)
+    rules_enabled_by_user = yield store.bulk_get_push_rules_enabled(user_ids)
 
     rules_by_user = {
         uid: baserules.list_with_base_rules([
@@ -44,6 +45,22 @@ def _get_rules(room_id, user_ids, store):
         ])
         for uid in user_ids
     }
+
+    # We apply the rules-enabled map here: bulk_get_push_rules doesn't
+    # fetch disabled rules, but this won't account for any server default
+    # rules the user has disabled, so we need to do this too.
+    for uid in user_ids:
+        if uid not in rules_enabled_by_user:
+            continue
+
+        user_enabled_map = rules_enabled_by_user[uid]
+
+        for rule in rules_by_user[uid]:
+            rule_id = rule['rule_id']
+
+            if rule_id in user_enabled_map:
+                rule['enabled'] = user_enabled_map[rule_id]
+
     defer.returnValue(rules_by_user)