diff options
author | David Teller <d.o.teller+github@gmail.com> | 2021-01-18 15:02:22 +0100 |
---|---|---|
committer | David Teller <d.o.teller+github@gmail.com> | 2021-01-28 12:29:49 +0100 |
commit | 10332c175c829a21b6565bc5e865bca154ffb084 (patch) | |
tree | 78f0aba8ad638ec3058c8e8c076c2f35d12f03ad /synapse/rest/admin/rooms.py | |
parent | Add notes on integrating with Facebook for SSO login. (#9244) (diff) | |
download | synapse-10332c175c829a21b6565bc5e865bca154ffb084.tar.xz |
New API /_synapse/admin/rooms/{roomId}/context/{eventId}
Signed-off-by: David Teller <davidt@element.io>
Diffstat (limited to 'synapse/rest/admin/rooms.py')
-rw-r--r-- | synapse/rest/admin/rooms.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py index f14915d47e..6539655289 100644 --- a/synapse/rest/admin/rooms.py +++ b/synapse/rest/admin/rooms.py @@ -566,3 +566,56 @@ class ForwardExtremitiesRestServlet(RestServlet): extremities = await self.store.get_forward_extremities_for_room(room_id) return 200, {"count": len(extremities), "results": extremities} + +class RoomEventContextServlet(RestServlet): + PATTERNS = admin_patterns("/rooms/(?P<room_id>[^/]*)/context/(?P<event_id>[^/]*)$") + + def __init__(self, hs): + super().__init__() + self.clock = hs.get_clock() + self.room_context_handler = hs.get_room_context_handler() + self._event_serializer = hs.get_event_client_serializer() + self.auth = hs.get_auth() + + async def on_GET(self, request, room_id, event_id): + requester = await self.auth.get_user_by_req(request, allow_guest=True) + + limit = parse_integer(request, "limit", default=10) + + # picking the API shape for symmetry with /messages + filter_str = parse_string(request, b"filter", encoding="utf-8") + if filter_str: + filter_json = urlparse.unquote(filter_str) + event_filter = Filter( + json_decoder.decode(filter_json) + ) # type: Optional[Filter] + else: + event_filter = None + + results = await self.room_context_handler.get_event_context( + requester.user, + room_id, + event_id, + limit, + event_filter, + use_admin_priviledge=True, + ) + + if not results: + raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND) + + time_now = self.clock.time_msec() + results["events_before"] = await self._event_serializer.serialize_events( + results["events_before"], time_now + ) + results["event"] = await self._event_serializer.serialize_event( + results["event"], time_now + ) + results["events_after"] = await self._event_serializer.serialize_events( + results["events_after"], time_now + ) + results["state"] = await self._event_serializer.serialize_events( + results["state"], time_now + ) + + return 200, results |