Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix invite pushes
Browse files Browse the repository at this point in the history
 * If the event is an invite event, add the invitee to list of user we run push rules for (if they have a pusher etc)
 * Move invite_for_me to be higher prio than member events otherwise member events matches them
 * Spell override right
  • Loading branch information
dbkr committed Apr 8, 2016
1 parent 7b6d519 commit ed3979d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 39 deletions.
6 changes: 3 additions & 3 deletions synapse/push/action_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from twisted.internet import defer

from .bulk_push_rule_evaluator import evaluator_for_room_id
from .bulk_push_rule_evaluator import evaluator_for_event

import logging

Expand All @@ -35,8 +35,8 @@ def __init__(self, hs):

@defer.inlineCallbacks
def handle_push_actions_for_event(self, event, context, handler):
bulk_evaluator = yield evaluator_for_room_id(
event.room_id, self.hs, self.store
bulk_evaluator = yield evaluator_for_event(
event, self.hs, self.store
)

actions_by_user = yield bulk_evaluator.action_for_event_by_user(
Expand Down
72 changes: 37 additions & 35 deletions synapse/push/baserules.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def make_base_append_rules(kind, modified_base_rules):
rules = []

if kind == 'override':
rules = BASE_APPEND_OVRRIDE_RULES
rules = BASE_APPEND_OVERRIDE_RULES
elif kind == 'underride':
rules = BASE_APPEND_UNDERRIDE_RULES
elif kind == 'content':
Expand Down Expand Up @@ -148,7 +148,7 @@ def make_base_prepend_rules(kind, modified_base_rules):
]


BASE_APPEND_OVRRIDE_RULES = [
BASE_APPEND_OVERRIDE_RULES = [
{
'rule_id': 'global/override/.m.rule.suppress_notices',
'conditions': [
Expand All @@ -163,6 +163,40 @@ def make_base_prepend_rules(kind, modified_base_rules):
'dont_notify',
]
},
# NB. .m.rule.invite_for_me must be higher prio than .m.rule.member_event
# otherwise invites will be matched by .m.rule.member_event
{
'rule_id': 'global/underride/.m.rule.invite_for_me',
'conditions': [
{
'kind': 'event_match',
'key': 'type',
'pattern': 'm.room.member',
'_id': '_member',
},
{
'kind': 'event_match',
'key': 'content.membership',
'pattern': 'invite',
'_id': '_invite_member',
},
{
'kind': 'event_match',
'key': 'state_key',
'pattern_type': 'user_id'
},
],
'actions': [
'notify',
{
'set_tweak': 'sound',
'value': 'default'
}, {
'set_tweak': 'highlight',
'value': False
}
]
},
# Will we sometimes want to know about people joining and leaving?
# Perhaps: if so, this could be expanded upon. Seems the most usual case
# is that we don't though. We add this override rule so that even if
Expand Down Expand Up @@ -251,38 +285,6 @@ def make_base_prepend_rules(kind, modified_base_rules):
}
]
},
{
'rule_id': 'global/underride/.m.rule.invite_for_me',
'conditions': [
{
'kind': 'event_match',
'key': 'type',
'pattern': 'm.room.member',
'_id': '_member',
},
{
'kind': 'event_match',
'key': 'content.membership',
'pattern': 'invite',
'_id': '_invite_member',
},
{
'kind': 'event_match',
'key': 'state_key',
'pattern_type': 'user_id'
},
],
'actions': [
'notify',
{
'set_tweak': 'sound',
'value': 'default'
}, {
'set_tweak': 'highlight',
'value': False
}
]
},
{
'rule_id': 'global/underride/.m.rule.message',
'conditions': [
Expand Down Expand Up @@ -315,7 +317,7 @@ def make_base_prepend_rules(kind, modified_base_rules):
r['default'] = True
BASE_RULE_IDS.add(r['rule_id'])

for r in BASE_APPEND_OVRRIDE_RULES:
for r in BASE_APPEND_OVERRIDE_RULES:
r['priority_class'] = PRIORITY_CLASS_MAP['override']
r['default'] = True
BASE_RULE_IDS.add(r['rule_id'])
Expand Down
12 changes: 11 additions & 1 deletion synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def _get_rules(room_id, user_ids, store):


@defer.inlineCallbacks
def evaluator_for_room_id(room_id, hs, store):
def evaluator_for_event(event, hs, store):
room_id = event.room_id
users_with_pushers = yield store.get_users_with_pushers_in_room(room_id)
receipts = yield store.get_receipts_for_room(room_id, "m.read")

Expand All @@ -79,6 +80,15 @@ def evaluator_for_room_id(room_id, hs, store):
if hs.is_mine_id(r['user_id']):
user_ids.add(r['user_id'])

# if this event is an invite event, we may need to run rules for the user
# who's been invited, otherwise they won't get told they've been invited
if event.type == 'm.room.member' and event.content['membership'] == 'invite':
invited_user = event.state_key
if invited_user and hs.is_mine_id(invited_user):
has_pusher = yield store.user_has_pusher(invited_user)
if has_pusher:
user_ids.add(invited_user)

user_ids = list(user_ids)

rules_by_user = yield _get_rules(room_id, user_ids, store)
Expand Down
7 changes: 7 additions & 0 deletions synapse/storage/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def _decode_pushers_rows(self, rows):

return rows

@defer.inlineCallbacks
def user_has_pusher(self, user_id):
ret = yield self._simple_select_one_onecol(
"pushers", {"user_name": user_id}, "id", allow_none=True
)
defer.returnValue(ret is not None)

@defer.inlineCallbacks
def get_pushers_by_app_id_and_pushkey(self, app_id, pushkey):
def r(txn):
Expand Down

0 comments on commit ed3979d

Please sign in to comment.