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

Commit 4d7e74b

Browse files
authored
Support the MSC3715 for /relations. (#11941)
This adds an unstable org.matrix.msc3715.dir parameter which acts like dir on /mesages.
1 parent b65acea commit 4d7e74b

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

changelog.d/11941.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support the `dir` parameter on the `/relations` endpoint, per [MSC3715](https://github.com/matrix-org/matrix-doc/pull/3715).

synapse/rest/client/relations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ async def on_GET(
111111
raise SynapseError(404, "Unknown parent event.")
112112

113113
limit = parse_integer(request, "limit", default=5)
114+
direction = parse_string(
115+
request, "org.matrix.msc3715.dir", default="b", allowed_values=["f", "b"]
116+
)
114117
from_token_str = parse_string(request, "from")
115118
to_token_str = parse_string(request, "to")
116119

@@ -128,6 +131,7 @@ async def on_GET(
128131
relation_type=relation_type,
129132
event_type=event_type,
130133
limit=limit,
134+
direction=direction,
131135
from_token=from_token,
132136
to_token=to_token,
133137
)

tests/rest/client/test_relations.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,28 @@ def test_basic_paginate_relations(self):
169169
"""Tests that calling pagination API correctly the latest relations."""
170170
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
171171
self.assertEquals(200, channel.code, channel.json_body)
172+
first_annotation_id = channel.json_body["event_id"]
172173

173174
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "b")
174175
self.assertEquals(200, channel.code, channel.json_body)
175-
annotation_id = channel.json_body["event_id"]
176+
second_annotation_id = channel.json_body["event_id"]
176177

177178
channel = self.make_request(
178179
"GET",
179-
"/_matrix/client/unstable/rooms/%s/relations/%s?limit=1"
180-
% (self.room, self.parent_id),
180+
f"/_matrix/client/unstable/rooms/{self.room}/relations/{self.parent_id}?limit=1",
181181
access_token=self.user_token,
182182
)
183183
self.assertEquals(200, channel.code, channel.json_body)
184184

185-
# We expect to get back a single pagination result, which is the full
186-
# relation event we sent above.
185+
# We expect to get back a single pagination result, which is the latest
186+
# full relation event we sent above.
187187
self.assertEquals(len(channel.json_body["chunk"]), 1, channel.json_body)
188188
self.assert_dict(
189-
{"event_id": annotation_id, "sender": self.user_id, "type": "m.reaction"},
189+
{
190+
"event_id": second_annotation_id,
191+
"sender": self.user_id,
192+
"type": "m.reaction",
193+
},
190194
channel.json_body["chunk"][0],
191195
)
192196

@@ -201,6 +205,27 @@ def test_basic_paginate_relations(self):
201205
channel.json_body.get("next_batch"), str, channel.json_body
202206
)
203207

208+
# Request the relations again, but with a different direction.
209+
channel = self.make_request(
210+
"GET",
211+
f"/_matrix/client/unstable/rooms/{self.room}/relations"
212+
f"/{self.parent_id}?limit=1&org.matrix.msc3715.dir=f",
213+
access_token=self.user_token,
214+
)
215+
self.assertEquals(200, channel.code, channel.json_body)
216+
217+
# We expect to get back a single pagination result, which is the earliest
218+
# full relation event we sent above.
219+
self.assertEquals(len(channel.json_body["chunk"]), 1, channel.json_body)
220+
self.assert_dict(
221+
{
222+
"event_id": first_annotation_id,
223+
"sender": self.user_id,
224+
"type": "m.reaction",
225+
},
226+
channel.json_body["chunk"][0],
227+
)
228+
204229
def _stream_token_to_relation_token(self, token: str) -> str:
205230
"""Convert a StreamToken into a legacy token (RelationPaginationToken)."""
206231
room_key = self.get_success(StreamToken.from_string(self.store, token)).room_key

0 commit comments

Comments
 (0)