mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Add enable/disable overlay for push rules (REST API not yet hooked up)
This commit is contained in:
parent
a025055643
commit
94fa334b01
@ -82,6 +82,8 @@ class Pusher(object):
|
|||||||
r['conditions'] = json.loads(r['conditions'])
|
r['conditions'] = json.loads(r['conditions'])
|
||||||
r['actions'] = json.loads(r['actions'])
|
r['actions'] = json.loads(r['actions'])
|
||||||
|
|
||||||
|
enabled_map = yield self.store.get_push_rules_enabled_for_user_name(self.user_name)
|
||||||
|
|
||||||
user = UserID.from_string(self.user_name)
|
user = UserID.from_string(self.user_name)
|
||||||
|
|
||||||
rules = baserules.list_with_base_rules(rawrules, user)
|
rules = baserules.list_with_base_rules(rawrules, user)
|
||||||
@ -107,6 +109,8 @@ class Pusher(object):
|
|||||||
room_member_count += 1
|
room_member_count += 1
|
||||||
|
|
||||||
for r in rules:
|
for r in rules:
|
||||||
|
if r['rule_id'] in enabled_map and not enabled_map[r['rule_id']]:
|
||||||
|
continue
|
||||||
matches = True
|
matches = True
|
||||||
|
|
||||||
conditions = r['conditions']
|
conditions = r['conditions']
|
||||||
|
@ -45,6 +45,7 @@ def make_base_rules(user, kind):
|
|||||||
def make_base_content_rules(user):
|
def make_base_content_rules(user):
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
'rule_id': '.m.rule.contains_user_name',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
{
|
{
|
||||||
'kind': 'event_match',
|
'kind': 'event_match',
|
||||||
@ -66,6 +67,7 @@ def make_base_content_rules(user):
|
|||||||
def make_base_override_rules():
|
def make_base_override_rules():
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
'rule_id': '.m.rule.contains_display_name',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
{
|
{
|
||||||
'kind': 'contains_display_name'
|
'kind': 'contains_display_name'
|
||||||
@ -80,6 +82,7 @@ def make_base_override_rules():
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
'rule_id': '.m.rule.room_two_members',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
{
|
{
|
||||||
'kind': 'room_member_count',
|
'kind': 'room_member_count',
|
||||||
|
@ -45,6 +45,17 @@ class PushRuleStore(SQLBaseStore):
|
|||||||
|
|
||||||
defer.returnValue(dicts)
|
defer.returnValue(dicts)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def get_push_rules_enabled_for_user_name(self, user_name):
|
||||||
|
results = yield self._simple_select_list(
|
||||||
|
PushRuleEnableTable.table_name,
|
||||||
|
{'user_name': user_name},
|
||||||
|
PushRuleEnableTable.fields
|
||||||
|
)
|
||||||
|
defer.returnValue(
|
||||||
|
{r['rule_id']: False if r['enabled'] == 0 else True for r in results}
|
||||||
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def add_push_rule(self, before, after, **kwargs):
|
def add_push_rule(self, before, after, **kwargs):
|
||||||
vals = copy.copy(kwargs)
|
vals = copy.copy(kwargs)
|
||||||
@ -216,3 +227,12 @@ class PushRuleTable(Table):
|
|||||||
]
|
]
|
||||||
|
|
||||||
EntryType = collections.namedtuple("PushRuleEntry", fields)
|
EntryType = collections.namedtuple("PushRuleEntry", fields)
|
||||||
|
|
||||||
|
class PushRuleEnableTable(Table):
|
||||||
|
table_name = "push_rules_enable"
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
"user_name",
|
||||||
|
"rule_id",
|
||||||
|
"enabled"
|
||||||
|
]
|
9
synapse/storage/schema/delta/next_pushrules2.sql
Normal file
9
synapse/storage/schema/delta/next_pushrules2.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS push_rules_enable (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_name TEXT NOT NULL,
|
||||||
|
rule_id TEXT NOT NULL,
|
||||||
|
enabled TINYINT,
|
||||||
|
UNIQUE(user_name, rule_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS push_rules_enable_user_name on push_rules_enable (user_name);
|
@ -44,3 +44,13 @@ CREATE TABLE IF NOT EXISTS push_rules (
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS push_rules_user_name on push_rules (user_name);
|
CREATE INDEX IF NOT EXISTS push_rules_user_name on push_rules (user_name);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS push_rules_enable (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_name TEXT NOT NULL,
|
||||||
|
rule_id TEXT NOT NULL,
|
||||||
|
enabled TINYINT,
|
||||||
|
UNIQUE(user_name, rule_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS push_rules_enable_user_name on push_rules_enable (user_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user