forked from MirrorHub/synapse
Support the MSC3715 for /relations
. (#11941)
This adds an unstable org.matrix.msc3715.dir parameter which acts like dir on /mesages.
This commit is contained in:
parent
b65acead42
commit
4d7e74b2e5
3 changed files with 36 additions and 6 deletions
1
changelog.d/11941.feature
Normal file
1
changelog.d/11941.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Support the `dir` parameter on the `/relations` endpoint, per [MSC3715](https://github.com/matrix-org/matrix-doc/pull/3715).
|
|
@ -111,6 +111,9 @@ class RelationPaginationServlet(RestServlet):
|
||||||
raise SynapseError(404, "Unknown parent event.")
|
raise SynapseError(404, "Unknown parent event.")
|
||||||
|
|
||||||
limit = parse_integer(request, "limit", default=5)
|
limit = parse_integer(request, "limit", default=5)
|
||||||
|
direction = parse_string(
|
||||||
|
request, "org.matrix.msc3715.dir", default="b", allowed_values=["f", "b"]
|
||||||
|
)
|
||||||
from_token_str = parse_string(request, "from")
|
from_token_str = parse_string(request, "from")
|
||||||
to_token_str = parse_string(request, "to")
|
to_token_str = parse_string(request, "to")
|
||||||
|
|
||||||
|
@ -128,6 +131,7 @@ class RelationPaginationServlet(RestServlet):
|
||||||
relation_type=relation_type,
|
relation_type=relation_type,
|
||||||
event_type=event_type,
|
event_type=event_type,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
direction=direction,
|
||||||
from_token=from_token,
|
from_token=from_token,
|
||||||
to_token=to_token,
|
to_token=to_token,
|
||||||
)
|
)
|
||||||
|
|
|
@ -169,24 +169,28 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
"""Tests that calling pagination API correctly the latest relations."""
|
"""Tests that calling pagination API correctly the latest relations."""
|
||||||
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
|
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
first_annotation_id = channel.json_body["event_id"]
|
||||||
|
|
||||||
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "b")
|
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "b")
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
annotation_id = channel.json_body["event_id"]
|
second_annotation_id = channel.json_body["event_id"]
|
||||||
|
|
||||||
channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/relations/%s?limit=1"
|
f"/_matrix/client/unstable/rooms/{self.room}/relations/{self.parent_id}?limit=1",
|
||||||
% (self.room, self.parent_id),
|
|
||||||
access_token=self.user_token,
|
access_token=self.user_token,
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
# We expect to get back a single pagination result, which is the full
|
# We expect to get back a single pagination result, which is the latest
|
||||||
# relation event we sent above.
|
# full relation event we sent above.
|
||||||
self.assertEquals(len(channel.json_body["chunk"]), 1, channel.json_body)
|
self.assertEquals(len(channel.json_body["chunk"]), 1, channel.json_body)
|
||||||
self.assert_dict(
|
self.assert_dict(
|
||||||
{"event_id": annotation_id, "sender": self.user_id, "type": "m.reaction"},
|
{
|
||||||
|
"event_id": second_annotation_id,
|
||||||
|
"sender": self.user_id,
|
||||||
|
"type": "m.reaction",
|
||||||
|
},
|
||||||
channel.json_body["chunk"][0],
|
channel.json_body["chunk"][0],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -201,6 +205,27 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
channel.json_body.get("next_batch"), str, channel.json_body
|
channel.json_body.get("next_batch"), str, channel.json_body
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Request the relations again, but with a different direction.
|
||||||
|
channel = self.make_request(
|
||||||
|
"GET",
|
||||||
|
f"/_matrix/client/unstable/rooms/{self.room}/relations"
|
||||||
|
f"/{self.parent_id}?limit=1&org.matrix.msc3715.dir=f",
|
||||||
|
access_token=self.user_token,
|
||||||
|
)
|
||||||
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
|
# We expect to get back a single pagination result, which is the earliest
|
||||||
|
# full relation event we sent above.
|
||||||
|
self.assertEquals(len(channel.json_body["chunk"]), 1, channel.json_body)
|
||||||
|
self.assert_dict(
|
||||||
|
{
|
||||||
|
"event_id": first_annotation_id,
|
||||||
|
"sender": self.user_id,
|
||||||
|
"type": "m.reaction",
|
||||||
|
},
|
||||||
|
channel.json_body["chunk"][0],
|
||||||
|
)
|
||||||
|
|
||||||
def _stream_token_to_relation_token(self, token: str) -> str:
|
def _stream_token_to_relation_token(self, token: str) -> str:
|
||||||
"""Convert a StreamToken into a legacy token (RelationPaginationToken)."""
|
"""Convert a StreamToken into a legacy token (RelationPaginationToken)."""
|
||||||
room_key = self.get_success(StreamToken.from_string(self.store, token)).room_key
|
room_key = self.get_success(StreamToken.from_string(self.store, token)).room_key
|
||||||
|
|
Loading…
Reference in a new issue