0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 09:43:46 +01:00

Run filter_events_for_client

so we don't accidentally mail out events people shouldn't see
This commit is contained in:
David Baker 2016-04-27 17:50:49 +01:00
parent 4ed1e45869
commit 424a7f48f8
7 changed files with 24 additions and 20 deletions

View file

@ -192,7 +192,7 @@ class BaseHandler(object):
})
@defer.inlineCallbacks
def _filter_events_for_client(self, user_id, events, is_peeking=False):
def filter_events_for_client(self, user_id, events, is_peeking=False):
"""
Check which events a user is allowed to see

View file

@ -123,7 +123,7 @@ class MessageHandler(BaseHandler):
"end": next_token.to_string(),
})
events = yield self._filter_events_for_client(
events = yield self.filter_events_for_client(
user_id,
events,
is_peeking=(member_event_id is None),
@ -483,7 +483,7 @@ class MessageHandler(BaseHandler):
]
).addErrback(unwrapFirstError)
messages = yield self._filter_events_for_client(
messages = yield self.filter_events_for_client(
user_id, messages
)
@ -619,7 +619,7 @@ class MessageHandler(BaseHandler):
end_token=stream_token
)
messages = yield self._filter_events_for_client(
messages = yield self.filter_events_for_client(
user_id, messages, is_peeking=is_peeking
)
@ -700,7 +700,7 @@ class MessageHandler(BaseHandler):
consumeErrors=True,
).addErrback(unwrapFirstError)
messages = yield self._filter_events_for_client(
messages = yield self.filter_events_for_client(
user_id, messages, is_peeking=is_peeking,
)

View file

@ -449,7 +449,7 @@ class RoomContextHandler(BaseHandler):
now_token = yield self.hs.get_event_sources().get_current_token()
def filter_evts(events):
return self._filter_events_for_client(
return self.filter_events_for_client(
user.to_string(),
events,
is_peeking=is_guest)

View file

@ -172,7 +172,7 @@ class SearchHandler(BaseHandler):
filtered_events = search_filter.filter([r["event"] for r in results])
events = yield self._filter_events_for_client(
events = yield self.filter_events_for_client(
user.to_string(), filtered_events
)
@ -223,7 +223,7 @@ class SearchHandler(BaseHandler):
r["event"] for r in results
])
events = yield self._filter_events_for_client(
events = yield self.filter_events_for_client(
user.to_string(), filtered_events
)
@ -281,11 +281,11 @@ class SearchHandler(BaseHandler):
event.room_id, event.event_id, before_limit, after_limit
)
res["events_before"] = yield self._filter_events_for_client(
res["events_before"] = yield self.filter_events_for_client(
user.to_string(), res["events_before"]
)
res["events_after"] = yield self._filter_events_for_client(
res["events_after"] = yield self.filter_events_for_client(
user.to_string(), res["events_after"]
)

View file

@ -681,7 +681,7 @@ class SyncHandler(BaseHandler):
if recents is not None:
recents = sync_config.filter_collection.filter_room_timeline(recents)
recents = yield self._filter_events_for_client(
recents = yield self.filter_events_for_client(
sync_config.user.to_string(),
recents,
)
@ -702,7 +702,7 @@ class SyncHandler(BaseHandler):
loaded_recents = sync_config.filter_collection.filter_room_timeline(
events
)
loaded_recents = yield self._filter_events_for_client(
loaded_recents = yield self.filter_events_for_client(
sync_config.user.to_string(),
loaded_recents,
)

View file

@ -399,7 +399,7 @@ class Notifier(object):
if name == "room":
room_member_handler = self.hs.get_handlers().room_member_handler
new_events = yield room_member_handler._filter_events_for_client(
new_events = yield room_member_handler.filter_events_for_client(
user.to_string(),
new_events,
is_peeking=is_peeking,

View file

@ -155,13 +155,15 @@ class Mailer(object):
}
for n in notifs:
vars = yield self.get_notif_vars(n, notif_events[n['event_id']], room_state)
vars = yield self.get_notif_vars(
n, user_id, notif_events[n['event_id']], room_state
)
room_vars['notifs'].append(vars)
defer.returnValue(room_vars)
@defer.inlineCallbacks
def get_notif_vars(self, notif, notif_event, room_state):
def get_notif_vars(self, notif, user_id, notif_event, room_state):
results = yield self.store.get_events_around(
notif['room_id'], notif['event_id'],
before_limit=CONTEXT_BEFORE, after_limit=0
@ -173,15 +175,17 @@ class Mailer(object):
"messages": [],
}
for event in results['events_before']:
handler = self.hs.get_handlers().message_handler
the_events = yield handler.filter_events_for_client(
user_id, results["events_before"]
)
the_events.append(notif_event)
for event in the_events:
vars = self.get_message_vars(notif, event, room_state)
if vars is not None:
ret['messages'].append(vars)
vars = self.get_message_vars(notif, notif_event, room_state)
if vars is not None:
ret['messages'].append(vars)
defer.returnValue(ret)
def get_message_vars(self, notif, event, room_state):