diff options
author | Brendan Abolivier <babolivier@matrix.org> | 2020-08-10 11:48:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-10 11:48:01 +0100 |
commit | cdbb8e6d6e36e0b6bc36e676d8fe66c96986b399 (patch) | |
tree | 107cf5525dc4dffda31be025ea138485aed68073 /synapse/storage | |
parent | Convert directory, e2e_room_keys, end_to_end_keys, monthly_active_users datab... (diff) | |
parent | Typo (diff) | |
download | synapse-cdbb8e6d6e36e0b6bc36e676d8fe66c96986b399.tar.xz |
Implement new experimental push rules (#7997)
With an undocumented configuration setting to enable them for specific users.
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/databases/main/push_rule.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py index 264521635f..19a0211a03 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py @@ -38,7 +38,7 @@ from synapse.util.caches.stream_change_cache import StreamChangeCache logger = logging.getLogger(__name__) -def _load_rules(rawrules, enabled_map): +def _load_rules(rawrules, enabled_map, use_new_defaults=False): ruleslist = [] for rawrule in rawrules: rule = dict(rawrule) @@ -48,7 +48,7 @@ def _load_rules(rawrules, enabled_map): ruleslist.append(rule) # We're going to be mutating this a lot, so do a deep copy - rules = list(list_with_base_rules(ruleslist)) + rules = list(list_with_base_rules(ruleslist, use_new_defaults)) for i, rule in enumerate(rules): rule_id = rule["rule_id"] @@ -104,6 +104,8 @@ class PushRulesWorkerStore( prefilled_cache=push_rules_prefill, ) + self._users_new_default_push_rules = hs.config.users_new_default_push_rules + @abc.abstractmethod def get_max_push_rules_stream_id(self): """Get the position of the push rules stream. @@ -133,7 +135,9 @@ class PushRulesWorkerStore( enabled_map = yield self.get_push_rules_enabled_for_user(user_id) - rules = _load_rules(rows, enabled_map) + use_new_defaults = user_id in self._users_new_default_push_rules + + rules = _load_rules(rows, enabled_map, use_new_defaults) return rules @@ -193,7 +197,11 @@ class PushRulesWorkerStore( enabled_map_by_user = yield self.bulk_get_push_rules_enabled(user_ids) for user_id, rules in results.items(): - results[user_id] = _load_rules(rules, enabled_map_by_user.get(user_id, {})) + use_new_defaults = user_id in self._users_new_default_push_rules + + results[user_id] = _load_rules( + rules, enabled_map_by_user.get(user_id, {}), use_new_defaults, + ) return results |