summary refs log tree commit diff
path: root/synapse/handlers/room.py
diff options
context:
space:
mode:
authorRichard van der Hoff <github@rvanderhoff.org.uk>2016-01-14 11:17:29 +0000
committerRichard van der Hoff <github@rvanderhoff.org.uk>2016-01-14 11:17:29 +0000
commit7ee1879ed467fc8605403e396c965f57465fe840 (patch)
treef88e43925281cf8a0d9faa620eb16d4d104a6062 /synapse/handlers/room.py
parentSkip, rather than erroring, invalid guest requests (diff)
parentAdd 'event' result to 'context' endpoint (diff)
downloadsynapse-7ee1879ed467fc8605403e396c965f57465fe840.tar.xz
Merge pull request #492 from matrix-org/rav/event_context_shiz_release github/release-v0.12.1 release-v0.12.1
Add 'event' result to 'context' endpoint
Diffstat (limited to 'synapse/handlers/room.py')
-rw-r--r--synapse/handlers/room.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index 725b318cfe..5291089366 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -864,28 +864,39 @@ class RoomContextHandler(BaseHandler):
                 (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