mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 08:29:25 -05:00
Send room name and first alias in notification poke.
This commit is contained in:
parent
e3e2fc3255
commit
2ca2dbc821
@ -61,6 +61,19 @@ class Pusher(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def get_context_for_event(self, ev):
|
||||||
|
name_aliases = yield self.store.get_room_name_and_aliases(
|
||||||
|
ev['room_id']
|
||||||
|
)
|
||||||
|
|
||||||
|
ctx = {'aliases': name_aliases[1]}
|
||||||
|
if name_aliases[0] is not None:
|
||||||
|
ctx['name'] = name_aliases[0]
|
||||||
|
|
||||||
|
defer.returnValue(ctx)
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def start(self):
|
def start(self):
|
||||||
if not self.last_token:
|
if not self.last_token:
|
||||||
|
@ -50,6 +50,7 @@ class HttpPusher(Pusher):
|
|||||||
self.data_minus_url.update(self.data)
|
self.data_minus_url.update(self.data)
|
||||||
del self.data_minus_url['url']
|
del self.data_minus_url['url']
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def _build_notification_dict(self, event):
|
def _build_notification_dict(self, event):
|
||||||
# we probably do not want to push for every presence update
|
# we probably do not want to push for every presence update
|
||||||
# (we may want to be able to set up notifications when specific
|
# (we may want to be able to set up notifications when specific
|
||||||
@ -57,9 +58,11 @@ class HttpPusher(Pusher):
|
|||||||
# Actually, presence events will not get this far now because we
|
# Actually, presence events will not get this far now because we
|
||||||
# need to filter them out in the main Pusher code.
|
# need to filter them out in the main Pusher code.
|
||||||
if 'event_id' not in event:
|
if 'event_id' not in event:
|
||||||
return None
|
defer.returnValue(None)
|
||||||
|
|
||||||
return {
|
ctx = yield self.get_context_for_event(event)
|
||||||
|
|
||||||
|
d = {
|
||||||
'notification': {
|
'notification': {
|
||||||
'transition': 'new',
|
'transition': 'new',
|
||||||
# everything is new for now: we don't have read receipts
|
# everything is new for now: we don't have read receipts
|
||||||
@ -85,9 +88,16 @@ class HttpPusher(Pusher):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(ctx['aliases']):
|
||||||
|
d['notification']['roomAlias'] = ctx['aliases'][0]
|
||||||
|
if 'name' in ctx:
|
||||||
|
d['notification']['roomName'] = ctx['name']
|
||||||
|
|
||||||
|
defer.returnValue(d)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def dispatch_push(self, event):
|
def dispatch_push(self, event):
|
||||||
notification_dict = self._build_notification_dict(event)
|
notification_dict = yield self._build_notification_dict(event)
|
||||||
if not notification_dict:
|
if not notification_dict:
|
||||||
defer.returnValue([])
|
defer.returnValue([])
|
||||||
try:
|
try:
|
||||||
|
@ -384,6 +384,41 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
events = yield self._parse_events(results)
|
events = yield self._parse_events(results)
|
||||||
defer.returnValue(events)
|
defer.returnValue(events)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def get_room_name_and_aliases(self, room_id):
|
||||||
|
del_sql = (
|
||||||
|
"SELECT event_id FROM redactions WHERE redacts = e.event_id "
|
||||||
|
"LIMIT 1"
|
||||||
|
)
|
||||||
|
|
||||||
|
sql = (
|
||||||
|
"SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
|
||||||
|
"INNER JOIN current_state_events as c ON e.event_id = c.event_id "
|
||||||
|
"INNER JOIN state_events as s ON e.event_id = s.event_id "
|
||||||
|
"WHERE c.room_id = ? "
|
||||||
|
) % {
|
||||||
|
"redacted": del_sql,
|
||||||
|
}
|
||||||
|
|
||||||
|
sql += " AND (s.type = 'm.room.name' AND s.state_key = '')"
|
||||||
|
sql += " OR s.type = 'm.room.aliases'"
|
||||||
|
args = (room_id,)
|
||||||
|
|
||||||
|
results = yield self._execute_and_decode(sql, *args)
|
||||||
|
|
||||||
|
events = yield self._parse_events(results)
|
||||||
|
|
||||||
|
name = None
|
||||||
|
aliases = []
|
||||||
|
|
||||||
|
for e in events:
|
||||||
|
if e.type == 'm.room.name':
|
||||||
|
name = e.content['name']
|
||||||
|
elif e.type == 'm.room.aliases':
|
||||||
|
aliases.extend(e.content['aliases'])
|
||||||
|
|
||||||
|
defer.returnValue((name, aliases))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _get_min_token(self):
|
def _get_min_token(self):
|
||||||
row = yield self._execute(
|
row = yield self._execute(
|
||||||
|
Loading…
Reference in New Issue
Block a user