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

Commit 87fe9db

Browse files
authored
Support the stable dir parameter for /relations. (#13920)
Since MSC3715 has passed FCP, the stable parameter can be used. This currently falls back to the unstable parameter if the stable parameter is not provided (and MSC3715 support is enabled in the configuration).
1 parent 299b00d commit 87fe9db

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

changelog.d/13920.feature

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

synapse/rest/client/relations.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,21 @@ async def on_GET(
5656
requester = await self.auth.get_user_by_req(request, allow_guest=True)
5757

5858
limit = parse_integer(request, "limit", default=5)
59-
if self._msc3715_enabled:
60-
direction = parse_string(
61-
request,
62-
"org.matrix.msc3715.dir",
63-
default="b",
64-
allowed_values=["f", "b"],
65-
)
66-
else:
67-
direction = "b"
59+
# Fetch the direction parameter, if provided.
60+
#
61+
# TODO Use PaginationConfig.from_request when the unstable parameter is
62+
# no longer needed.
63+
direction = parse_string(request, "dir", allowed_values=["f", "b"])
64+
if direction is None:
65+
if self._msc3715_enabled:
66+
direction = parse_string(
67+
request,
68+
"org.matrix.msc3715.dir",
69+
default="b",
70+
allowed_values=["f", "b"],
71+
)
72+
else:
73+
direction = "b"
6874
from_token_str = parse_string(request, "from")
6975
to_token_str = parse_string(request, "to")
7076

tests/rest/client/test_relations.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ def test_background_update(self) -> None:
728728

729729

730730
class RelationPaginationTestCase(BaseRelationsTestCase):
731-
@unittest.override_config({"experimental_features": {"msc3715_enabled": True}})
732731
def test_basic_paginate_relations(self) -> None:
733732
"""Tests that calling pagination API correctly the latest relations."""
734733
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
@@ -771,7 +770,7 @@ def test_basic_paginate_relations(self) -> None:
771770
channel = self.make_request(
772771
"GET",
773772
f"/_matrix/client/v1/rooms/{self.room}/relations"
774-
f"/{self.parent_id}?limit=1&org.matrix.msc3715.dir=f",
773+
f"/{self.parent_id}?limit=1&dir=f",
775774
access_token=self.user_token,
776775
)
777776
self.assertEqual(200, channel.code, channel.json_body)
@@ -788,7 +787,6 @@ def test_basic_paginate_relations(self) -> None:
788787
channel.json_body["chunk"][0],
789788
)
790789

791-
@unittest.override_config({"experimental_features": {"msc3715_enabled": True}})
792790
def test_repeated_paginate_relations(self) -> None:
793791
"""Test that if we paginate using a limit and tokens then we get the
794792
expected events.
@@ -838,7 +836,7 @@ def test_repeated_paginate_relations(self) -> None:
838836

839837
channel = self.make_request(
840838
"GET",
841-
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}?org.matrix.msc3715.dir=f&limit=3{from_token}",
839+
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}?dir=f&limit=3{from_token}",
842840
access_token=self.user_token,
843841
)
844842
self.assertEqual(200, channel.code, channel.json_body)

0 commit comments

Comments
 (0)