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

Commit

Permalink
Include the original event in /relations (#5626)
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 17, 2020
2 parents 2a59569 + d88421a commit 748ebe2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/5626.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include the original event when asking for its relations.
8 changes: 5 additions & 3 deletions synapse/rest/client/v2_alpha/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def on_GET(self, request, room_id, parent_id, relation_type=None, event_type=Non
room_id, requester.user.to_string()
)

# This checks that a) the event exists and b) the user is allowed to
# view it.
yield self.event_handler.get_event(requester.user, room_id, parent_id)
# This gets the original event and checks that a) the event exists and
# b) the user is allowed to view it.
event = yield self.event_handler.get_event(requester.user, room_id, parent_id)

limit = parse_integer(request, "limit", default=5)
from_token = parse_string(request, "from")
Expand All @@ -173,10 +173,12 @@ def on_GET(self, request, room_id, parent_id, relation_type=None, event_type=Non
)

now = self.clock.time_msec()
original_event = yield self._event_serializer.serialize_event(event, now)
events = yield self._event_serializer.serialize_events(events, now)

return_value = result.to_dict()
return_value["chunk"] = events
return_value["original_event"] = original_event

defer.returnValue((200, return_value))

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def to_dict(self):
class RelationPaginationToken(object):
"""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
boundaries of the chunk as pagination tokens.
Expand Down
5 changes: 5 additions & 0 deletions tests/rest/client/v2_alpha/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def test_basic_paginate_relations(self):
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
# valid token.
self.assertIsInstance(
Expand Down

0 comments on commit 748ebe2

Please sign in to comment.