Include the original event in /relations (#5626)

When asking for the relations of an event, include the original event in the response. This will mostly be used for efficiently showing edit history, but could be useful in other circumstances.
This commit is contained in:
Andrew Morgan 2019-07-09 13:43:08 +01:00 committed by GitHub
parent af67c7c1de
commit d88421ab03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

1
changelog.d/5626.feature Normal file
View file

@ -0,0 +1 @@
Include the original event when asking for its relations.

View file

@ -145,9 +145,9 @@ class RelationPaginationServlet(RestServlet):
room_id, requester.user.to_string() room_id, requester.user.to_string()
) )
# This checks that a) the event exists and b) the user is allowed to # This gets the original event and checks that a) the event exists and
# view it. # b) the user is allowed to view it.
yield self.event_handler.get_event(requester.user, room_id, parent_id) event = yield self.event_handler.get_event(requester.user, room_id, parent_id)
limit = parse_integer(request, "limit", default=5) limit = parse_integer(request, "limit", default=5)
from_token = parse_string(request, "from") from_token = parse_string(request, "from")
@ -173,10 +173,12 @@ class RelationPaginationServlet(RestServlet):
) )
now = self.clock.time_msec() now = self.clock.time_msec()
original_event = yield self._event_serializer.serialize_event(event, now)
events = yield self._event_serializer.serialize_events(events, now) events = yield self._event_serializer.serialize_events(events, now)
return_value = result.to_dict() return_value = result.to_dict()
return_value["chunk"] = events return_value["chunk"] = events
return_value["original_event"] = original_event
defer.returnValue((200, return_value)) defer.returnValue((200, return_value))

View file

@ -60,7 +60,7 @@ class PaginationChunk(object):
class RelationPaginationToken(object): class RelationPaginationToken(object):
"""Pagination token for relation pagination API. """Pagination token for relation pagination API.
As the results are order by topological ordering, we can use the As the results are in topological order, we can use the
`topological_ordering` and `stream_ordering` fields of the events at the `topological_ordering` and `stream_ordering` fields of the events at the
boundaries of the chunk as pagination tokens. boundaries of the chunk as pagination tokens.

View file

@ -126,6 +126,11 @@ class RelationsTestCase(unittest.HomeserverTestCase):
channel.json_body["chunk"][0], channel.json_body["chunk"][0],
) )
# We also expect to get the original event (the id of which is self.parent_id)
self.assertEquals(
channel.json_body["original_event"]["event_id"], self.parent_id
)
# Make sure next_batch has something in it that looks like it could be a # Make sure next_batch has something in it that looks like it could be a
# valid token. # valid token.
self.assertIsInstance( self.assertIsInstance(