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

Commit d88421a

Browse files
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.
1 parent af67c7c commit d88421a

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

changelog.d/5626.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include the original event when asking for its relations.

synapse/rest/client/v2_alpha/relations.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ def on_GET(self, request, room_id, parent_id, relation_type=None, event_type=Non
145145
room_id, requester.user.to_string()
146146
)
147147

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

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

175175
now = self.clock.time_msec()
176+
original_event = yield self._event_serializer.serialize_event(event, now)
176177
events = yield self._event_serializer.serialize_events(events, now)
177178

178179
return_value = result.to_dict()
179180
return_value["chunk"] = events
181+
return_value["original_event"] = original_event
180182

181183
defer.returnValue((200, return_value))
182184

synapse/storage/relations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def to_dict(self):
6060
class RelationPaginationToken(object):
6161
"""Pagination token for relation pagination API.
6262
63-
As the results are order by topological ordering, we can use the
63+
As the results are in topological order, we can use the
6464
`topological_ordering` and `stream_ordering` fields of the events at the
6565
boundaries of the chunk as pagination tokens.
6666

tests/rest/client/v2_alpha/test_relations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def test_basic_paginate_relations(self):
126126
channel.json_body["chunk"][0],
127127
)
128128

129+
# We also expect to get the original event (the id of which is self.parent_id)
130+
self.assertEquals(
131+
channel.json_body["original_event"]["event_id"], self.parent_id
132+
)
133+
129134
# Make sure next_batch has something in it that looks like it could be a
130135
# valid token.
131136
self.assertIsInstance(

0 commit comments

Comments
 (0)