mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Remove support for the unstable dir flag on relations. (#14106)
From MSC3715, this was unused by clients (and there was no way for clients to know it was supported). Matrix 1.4 defines the stable field.
This commit is contained in:
parent
ab8047b4bf
commit
e03d7c5fd0
1
changelog.d/14106.removal
Normal file
1
changelog.d/14106.removal
Normal file
@ -0,0 +1 @@
|
|||||||
|
Remove the unstable identifier for [MSC3715](https://github.com/matrix-org/matrix-doc/pull/3715).
|
@ -100,9 +100,6 @@ class ExperimentalConfig(Config):
|
|||||||
# MSC3773: Thread notifications
|
# MSC3773: Thread notifications
|
||||||
self.msc3773_enabled: bool = experimental.get("msc3773_enabled", False)
|
self.msc3773_enabled: bool = experimental.get("msc3773_enabled", False)
|
||||||
|
|
||||||
# MSC3715: dir param on /relations.
|
|
||||||
self.msc3715_enabled: bool = experimental.get("msc3715_enabled", False)
|
|
||||||
|
|
||||||
# MSC3848: Introduce errcodes for specific event sending failures
|
# MSC3848: Introduce errcodes for specific event sending failures
|
||||||
self.msc3848_enabled: bool = experimental.get("msc3848_enabled", False)
|
self.msc3848_enabled: bool = experimental.get("msc3848_enabled", False)
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ from synapse.api.errors import SynapseError
|
|||||||
from synapse.events import EventBase, relation_from_event
|
from synapse.events import EventBase, relation_from_event
|
||||||
from synapse.logging.opentracing import trace
|
from synapse.logging.opentracing import trace
|
||||||
from synapse.storage.databases.main.relations import _RelatedEvent
|
from synapse.storage.databases.main.relations import _RelatedEvent
|
||||||
|
from synapse.streams.config import PaginationConfig
|
||||||
from synapse.types import JsonDict, Requester, StreamToken, UserID
|
from synapse.types import JsonDict, Requester, StreamToken, UserID
|
||||||
from synapse.visibility import filter_events_for_client
|
from synapse.visibility import filter_events_for_client
|
||||||
|
|
||||||
@ -72,13 +73,10 @@ class RelationsHandler:
|
|||||||
requester: Requester,
|
requester: Requester,
|
||||||
event_id: str,
|
event_id: str,
|
||||||
room_id: str,
|
room_id: str,
|
||||||
|
pagin_config: PaginationConfig,
|
||||||
|
include_original_event: bool,
|
||||||
relation_type: Optional[str] = None,
|
relation_type: Optional[str] = None,
|
||||||
event_type: Optional[str] = None,
|
event_type: Optional[str] = None,
|
||||||
limit: int = 5,
|
|
||||||
direction: str = "b",
|
|
||||||
from_token: Optional[StreamToken] = None,
|
|
||||||
to_token: Optional[StreamToken] = None,
|
|
||||||
include_original_event: bool = False,
|
|
||||||
) -> JsonDict:
|
) -> JsonDict:
|
||||||
"""Get related events of a event, ordered by topological ordering.
|
"""Get related events of a event, ordered by topological ordering.
|
||||||
|
|
||||||
@ -88,14 +86,10 @@ class RelationsHandler:
|
|||||||
requester: The user requesting the relations.
|
requester: The user requesting the relations.
|
||||||
event_id: Fetch events that relate to this event ID.
|
event_id: Fetch events that relate to this event ID.
|
||||||
room_id: The room the event belongs to.
|
room_id: The room the event belongs to.
|
||||||
|
pagin_config: The pagination config rules to apply, if any.
|
||||||
|
include_original_event: Whether to include the parent event.
|
||||||
relation_type: Only fetch events with this relation type, if given.
|
relation_type: Only fetch events with this relation type, if given.
|
||||||
event_type: Only fetch events with this event type, if given.
|
event_type: Only fetch events with this event type, if given.
|
||||||
limit: Only fetch the most recent `limit` events.
|
|
||||||
direction: Whether to fetch the most recent first (`"b"`) or the
|
|
||||||
oldest first (`"f"`).
|
|
||||||
from_token: Fetch rows from the given token, or from the start if None.
|
|
||||||
to_token: Fetch rows up to the given token, or up to the end if None.
|
|
||||||
include_original_event: Whether to include the parent event.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The pagination chunk.
|
The pagination chunk.
|
||||||
@ -114,6 +108,9 @@ class RelationsHandler:
|
|||||||
if event is None:
|
if event is None:
|
||||||
raise SynapseError(404, "Unknown parent event.")
|
raise SynapseError(404, "Unknown parent event.")
|
||||||
|
|
||||||
|
# TODO Update pagination config to not allow None limits.
|
||||||
|
assert pagin_config.limit is not None
|
||||||
|
|
||||||
# Note that ignored users are not passed into get_relations_for_event
|
# Note that ignored users are not passed into get_relations_for_event
|
||||||
# below. Ignored users are handled in filter_events_for_client (and by
|
# below. Ignored users are handled in filter_events_for_client (and by
|
||||||
# not passing them in here we should get a better cache hit rate).
|
# not passing them in here we should get a better cache hit rate).
|
||||||
@ -123,10 +120,10 @@ class RelationsHandler:
|
|||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
relation_type=relation_type,
|
relation_type=relation_type,
|
||||||
event_type=event_type,
|
event_type=event_type,
|
||||||
limit=limit,
|
limit=pagin_config.limit,
|
||||||
direction=direction,
|
direction=pagin_config.direction,
|
||||||
from_token=from_token,
|
from_token=pagin_config.from_token,
|
||||||
to_token=to_token,
|
to_token=pagin_config.to_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
events = await self._main_store.get_events_as_list(
|
events = await self._main_store.get_events_as_list(
|
||||||
@ -162,8 +159,10 @@ class RelationsHandler:
|
|||||||
if next_token:
|
if next_token:
|
||||||
return_value["next_batch"] = await next_token.to_string(self._main_store)
|
return_value["next_batch"] = await next_token.to_string(self._main_store)
|
||||||
|
|
||||||
if from_token:
|
if pagin_config.from_token:
|
||||||
return_value["prev_batch"] = await from_token.to_string(self._main_store)
|
return_value["prev_batch"] = await pagin_config.from_token.to_string(
|
||||||
|
self._main_store
|
||||||
|
)
|
||||||
|
|
||||||
return return_value
|
return return_value
|
||||||
|
|
||||||
|
@ -16,10 +16,11 @@ import logging
|
|||||||
from typing import TYPE_CHECKING, Optional, Tuple
|
from typing import TYPE_CHECKING, Optional, Tuple
|
||||||
|
|
||||||
from synapse.http.server import HttpServer
|
from synapse.http.server import HttpServer
|
||||||
from synapse.http.servlet import RestServlet, parse_integer, parse_string
|
from synapse.http.servlet import RestServlet
|
||||||
from synapse.http.site import SynapseRequest
|
from synapse.http.site import SynapseRequest
|
||||||
from synapse.rest.client._base import client_patterns
|
from synapse.rest.client._base import client_patterns
|
||||||
from synapse.types import JsonDict, StreamToken
|
from synapse.streams.config import PaginationConfig
|
||||||
|
from synapse.types import JsonDict
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
@ -41,9 +42,8 @@ class RelationPaginationServlet(RestServlet):
|
|||||||
def __init__(self, hs: "HomeServer"):
|
def __init__(self, hs: "HomeServer"):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.store = hs.get_datastores().main
|
self._store = hs.get_datastores().main
|
||||||
self._relations_handler = hs.get_relations_handler()
|
self._relations_handler = hs.get_relations_handler()
|
||||||
self._msc3715_enabled = hs.config.experimental.msc3715_enabled
|
|
||||||
|
|
||||||
async def on_GET(
|
async def on_GET(
|
||||||
self,
|
self,
|
||||||
@ -55,49 +55,24 @@ class RelationPaginationServlet(RestServlet):
|
|||||||
) -> Tuple[int, JsonDict]:
|
) -> Tuple[int, JsonDict]:
|
||||||
requester = await self.auth.get_user_by_req(request, allow_guest=True)
|
requester = await self.auth.get_user_by_req(request, allow_guest=True)
|
||||||
|
|
||||||
limit = parse_integer(request, "limit", default=5)
|
pagination_config = await PaginationConfig.from_request(
|
||||||
# Fetch the direction parameter, if provided.
|
self._store, request, default_limit=5, default_dir="b"
|
||||||
#
|
|
||||||
# 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")
|
|
||||||
|
|
||||||
# Return the relations
|
|
||||||
from_token = None
|
|
||||||
if from_token_str:
|
|
||||||
from_token = await StreamToken.from_string(self.store, from_token_str)
|
|
||||||
to_token = None
|
|
||||||
if to_token_str:
|
|
||||||
to_token = await StreamToken.from_string(self.store, to_token_str)
|
|
||||||
|
|
||||||
# The unstable version of this API returns an extra field for client
|
# The unstable version of this API returns an extra field for client
|
||||||
# compatibility, see https://github.com/matrix-org/synapse/issues/12930.
|
# compatibility, see https://github.com/matrix-org/synapse/issues/12930.
|
||||||
assert request.path is not None
|
assert request.path is not None
|
||||||
include_original_event = request.path.startswith(b"/_matrix/client/unstable/")
|
include_original_event = request.path.startswith(b"/_matrix/client/unstable/")
|
||||||
|
|
||||||
|
# Return the relations
|
||||||
result = await self._relations_handler.get_relations(
|
result = await self._relations_handler.get_relations(
|
||||||
requester=requester,
|
requester=requester,
|
||||||
event_id=parent_id,
|
event_id=parent_id,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
|
pagin_config=pagination_config,
|
||||||
|
include_original_event=include_original_event,
|
||||||
relation_type=relation_type,
|
relation_type=relation_type,
|
||||||
event_type=event_type,
|
event_type=event_type,
|
||||||
limit=limit,
|
|
||||||
direction=direction,
|
|
||||||
from_token=from_token,
|
|
||||||
to_token=to_token,
|
|
||||||
include_original_event=include_original_event,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return 200, result
|
return 200, result
|
||||||
|
@ -42,10 +42,12 @@ class PaginationConfig:
|
|||||||
cls,
|
cls,
|
||||||
store: "DataStore",
|
store: "DataStore",
|
||||||
request: SynapseRequest,
|
request: SynapseRequest,
|
||||||
raise_invalid_params: bool = True,
|
|
||||||
default_limit: Optional[int] = None,
|
default_limit: Optional[int] = None,
|
||||||
|
default_dir: str = "f",
|
||||||
) -> "PaginationConfig":
|
) -> "PaginationConfig":
|
||||||
direction = parse_string(request, "dir", default="f", allowed_values=["f", "b"])
|
direction = parse_string(
|
||||||
|
request, "dir", default=default_dir, allowed_values=["f", "b"]
|
||||||
|
)
|
||||||
|
|
||||||
from_tok_str = parse_string(request, "from")
|
from_tok_str = parse_string(request, "from")
|
||||||
to_tok_str = parse_string(request, "to")
|
to_tok_str = parse_string(request, "to")
|
||||||
|
Loading…
Reference in New Issue
Block a user