Store nothing instead of ['dont_notify'] for events with no notification required: much as it would be nice to be able to tell between the event not having been processed and there being no notification for it, this isn't worth filling up the table with ['dont_notify'] I think. Consequently treat the empty actions array as dont_notify and filter dont_notify out of the result.
This commit is contained in:
parent
aa667ee396
commit
5e909c73d7
|
@ -157,21 +157,7 @@ class Pusher(object):
|
||||||
actions = yield rule_evaluator.actions_for_event(single_event)
|
actions = yield rule_evaluator.actions_for_event(single_event)
|
||||||
tweaks = rule_evaluator.tweaks_for_actions(actions)
|
tweaks = rule_evaluator.tweaks_for_actions(actions)
|
||||||
|
|
||||||
if len(actions) == 0:
|
if 'notify' in actions:
|
||||||
logger.warn("Empty actions! Using default action.")
|
|
||||||
actions = Pusher.DEFAULT_ACTIONS
|
|
||||||
|
|
||||||
if 'notify' not in actions and 'dont_notify' not in actions:
|
|
||||||
logger.warn("Neither notify nor dont_notify in actions: adding default")
|
|
||||||
actions.extend(Pusher.DEFAULT_ACTIONS)
|
|
||||||
|
|
||||||
if 'dont_notify' in actions:
|
|
||||||
logger.debug(
|
|
||||||
"%s for %s: dont_notify",
|
|
||||||
single_event['event_id'], self.user_name
|
|
||||||
)
|
|
||||||
processed = True
|
|
||||||
else:
|
|
||||||
rejected = yield self.dispatch_push(single_event, tweaks)
|
rejected = yield self.dispatch_push(single_event, tweaks)
|
||||||
self.has_unread = True
|
self.has_unread = True
|
||||||
if isinstance(rejected, list) or isinstance(rejected, tuple):
|
if isinstance(rejected, list) or isinstance(rejected, tuple):
|
||||||
|
@ -192,6 +178,8 @@ class Pusher(object):
|
||||||
yield self.hs.get_pusherpool().remove_pusher(
|
yield self.hs.get_pusherpool().remove_pusher(
|
||||||
self.app_id, pk, self.user_name
|
self.app_id, pk, self.user_name
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
processed = True
|
||||||
|
|
||||||
if not self.alive:
|
if not self.alive:
|
||||||
return
|
return
|
||||||
|
|
|
@ -35,7 +35,6 @@ class ActionGenerator:
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def handle_event(self, event):
|
def handle_event(self, event):
|
||||||
users = yield self.store.get_users_in_room(event['room_id'])
|
users = yield self.store.get_users_in_room(event['room_id'])
|
||||||
logger.error("users in room: %r", users)
|
|
||||||
|
|
||||||
for uid in users:
|
for uid in users:
|
||||||
evaluator = yield push_rule_evaluator.\
|
evaluator = yield push_rule_evaluator.\
|
||||||
|
@ -44,6 +43,7 @@ class ActionGenerator:
|
||||||
)
|
)
|
||||||
actions = yield evaluator.actions_for_event(event)
|
actions = yield evaluator.actions_for_event(event)
|
||||||
logger.info("actions for user %s: %s", uid, actions)
|
logger.info("actions for user %s: %s", uid, actions)
|
||||||
self.store.set_actions_for_event(
|
if len(actions):
|
||||||
event['event_id'], uid, None, actions
|
self.store.set_actions_for_event(
|
||||||
)
|
event['event_id'], uid, None, actions
|
||||||
|
)
|
||||||
|
|
|
@ -43,7 +43,7 @@ def evaluator_for_user_name_and_profile_tag(user_name, profile_tag, room_id, sto
|
||||||
|
|
||||||
|
|
||||||
class PushRuleEvaluator:
|
class PushRuleEvaluator:
|
||||||
DEFAULT_ACTIONS = ['dont_notify']
|
DEFAULT_ACTIONS = []
|
||||||
INEQUALITY_EXPR = re.compile("^([=<>]*)([0-9]*)$")
|
INEQUALITY_EXPR = re.compile("^([=<>]*)([0-9]*)$")
|
||||||
|
|
||||||
def __init__(self, user_name, profile_tag, raw_rules, enabled_map, room_id,
|
def __init__(self, user_name, profile_tag, raw_rules, enabled_map, room_id,
|
||||||
|
@ -85,7 +85,7 @@ class PushRuleEvaluator:
|
||||||
"""
|
"""
|
||||||
if ev['user_id'] == self.user_name:
|
if ev['user_id'] == self.user_name:
|
||||||
# let's assume you probably know about messages you sent yourself
|
# let's assume you probably know about messages you sent yourself
|
||||||
defer.returnValue(['dont_notify'])
|
defer.returnValue([])
|
||||||
|
|
||||||
room_id = ev['room_id']
|
room_id = ev['room_id']
|
||||||
|
|
||||||
|
@ -131,6 +131,11 @@ class PushRuleEvaluator:
|
||||||
"%s matches for user %s, event %s",
|
"%s matches for user %s, event %s",
|
||||||
r['rule_id'], self.user_name, ev['event_id']
|
r['rule_id'], self.user_name, ev['event_id']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# filter out dont_notify as we treat an empty actions list
|
||||||
|
# as dont_notify, and this doesn't take up a row in our database
|
||||||
|
actions = [x for x in actions if x != 'dont_notify']
|
||||||
|
|
||||||
defer.returnValue(actions)
|
defer.returnValue(actions)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
Loading…
Reference in New Issue