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

Commit

Permalink
Merge pull request #492 from matrix-org/rav/event_context_shiz_release
Browse files Browse the repository at this point in the history
Add 'event' result to 'context' endpoint
  • Loading branch information
richvdh committed Jan 14, 2016
2 parents 93afb40 + 49f33f6 commit 7ee1879
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
35 changes: 23 additions & 12 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,28 +864,39 @@ def get_event_context(self, user, room_id, event_id, limit, is_guest):
(excluding state).
Returns:
dict
dict, or None if the event isn't found
"""
before_limit = math.floor(limit/2.)
after_limit = limit - before_limit

now_token = yield self.hs.get_event_sources().get_current_token()

def filter_evts(events):
return self._filter_events_for_client(
user.to_string(),
events,
is_guest=is_guest)

event = yield self.store.get_event(event_id, get_prev_content=True,
allow_none=True)
if not event:
defer.returnValue(None)
return

filtered = yield(filter_evts([event]))
if not filtered:
raise AuthError(
403,
"You don't have permission to access that event."
)

results = yield self.store.get_events_around(
room_id, event_id, before_limit, after_limit
)

results["events_before"] = yield self._filter_events_for_client(
user.to_string(),
results["events_before"],
is_guest=is_guest,
)

results["events_after"] = yield self._filter_events_for_client(
user.to_string(),
results["events_after"],
is_guest=is_guest,
)
results["events_before"] = yield filter_evts(results["events_before"])
results["events_after"] = yield filter_evts(results["events_after"])
results["event"] = event

if results["events_after"]:
last_event_id = results["events_after"][-1].event_id
Expand Down
6 changes: 6 additions & 0 deletions synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,16 @@ def on_GET(self, request, room_id, event_id):
user, room_id, event_id, limit, is_guest
)

if not results:
raise SynapseError(
404, "Event not found.", errcode=Codes.NOT_FOUND
)

time_now = self.clock.time_msec()
results["events_before"] = [
serialize_event(event, time_now) for event in results["events_before"]
]
results["event"] = serialize_event(results["event"], time_now)
results["events_after"] = [
serialize_event(event, time_now) for event in results["events_after"]
]
Expand Down

0 comments on commit 7ee1879

Please sign in to comment.