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

Commit

Permalink
Support the stable dir parameter for /relations. (#13920)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
clokep committed Sep 27, 2022
1 parent 299b00d commit 87fe9db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog.d/13920.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support a `dir` parameter on the `/relations` endpoint per [MSC3715](https://github.com/matrix-org/matrix-doc/pull/3715).
24 changes: 15 additions & 9 deletions synapse/rest/client/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ async def on_GET(
requester = await self.auth.get_user_by_req(request, allow_guest=True)

limit = parse_integer(request, "limit", default=5)
if self._msc3715_enabled:
direction = parse_string(
request,
"org.matrix.msc3715.dir",
default="b",
allowed_values=["f", "b"],
)
else:
direction = "b"
# Fetch the direction parameter, if provided.
#
# TODO Use PaginationConfig.from_request when the unstable parameter is
# no longer needed.
direction = parse_string(request, "dir", allowed_values=["f", "b"])
if direction is None:
if self._msc3715_enabled:
direction = parse_string(
request,
"org.matrix.msc3715.dir",
default="b",
allowed_values=["f", "b"],
)
else:
direction = "b"
from_token_str = parse_string(request, "from")
to_token_str = parse_string(request, "to")

Expand Down
6 changes: 2 additions & 4 deletions tests/rest/client/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ def test_background_update(self) -> None:


class RelationPaginationTestCase(BaseRelationsTestCase):
@unittest.override_config({"experimental_features": {"msc3715_enabled": True}})
def test_basic_paginate_relations(self) -> None:
"""Tests that calling pagination API correctly the latest relations."""
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
Expand Down Expand Up @@ -771,7 +770,7 @@ def test_basic_paginate_relations(self) -> None:
channel = self.make_request(
"GET",
f"/_matrix/client/v1/rooms/{self.room}/relations"
f"/{self.parent_id}?limit=1&org.matrix.msc3715.dir=f",
f"/{self.parent_id}?limit=1&dir=f",
access_token=self.user_token,
)
self.assertEqual(200, channel.code, channel.json_body)
Expand All @@ -788,7 +787,6 @@ def test_basic_paginate_relations(self) -> None:
channel.json_body["chunk"][0],
)

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

channel = self.make_request(
"GET",
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}?org.matrix.msc3715.dir=f&limit=3{from_token}",
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}?dir=f&limit=3{from_token}",
access_token=self.user_token,
)
self.assertEqual(200, channel.code, channel.json_body)
Expand Down

0 comments on commit 87fe9db

Please sign in to comment.