Repository navigation
MSC1763: Implement /_matrix/client/unstable/org.matrix.msc1763/retention/configuration #19853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6c81669
51e96c1
2017fc7
1a6a525
63b2ec5
02e014e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The `GET /_matrix/client/unstable/org.matrix.msc1763/retention/configuration` endpoint is now provided when retention | ||
| is enabled and `experimental_features.msc1763_enabled` is enabled, based on | ||
| [MSC1763](https://github.com/matrix-org/matrix-spec-proposals/pull/1763). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # | ||
| # This file is licensed under the Affero General Public License (AGPL) version 3. | ||
| # | ||
| # Copyright (C) 2026 Element Creations Ltd. | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU Affero General Public License as | ||
| # published by the Free Software Foundation, either version 3 of the | ||
| # License, or (at your option) any later version. | ||
| # | ||
| # See the GNU Affero General Public License for more details: | ||
| # <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
|
|
||
| from http import HTTPStatus | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from typing_extensions import TypedDict | ||
|
|
||
| from synapse.http.server import HttpServer | ||
| from synapse.http.servlet import RestServlet | ||
| from synapse.http.site import SynapseRequest | ||
|
|
||
| from ._base import client_patterns | ||
|
|
||
| if TYPE_CHECKING: | ||
| from synapse.server import HomeServer | ||
|
|
||
|
|
||
| class RetentionPolicyDict(TypedDict, total=False): | ||
| min_lifetime: int | ||
| max_lifetime: int | ||
|
|
||
|
|
||
| class LifetimeBoundsDict(TypedDict, total=False): | ||
| min: int | ||
| max: int | ||
|
|
||
|
|
||
| class RetentionLimitsDict(TypedDict, total=False): | ||
| max_lifetime: LifetimeBoundsDict | ||
|
|
||
|
|
||
| class RetentionConfigurationResponse(TypedDict): | ||
| policies: dict[str, RetentionPolicyDict] | ||
| limits: RetentionLimitsDict | ||
|
|
||
|
|
||
| class RetentionConfigurationServlet(RestServlet): | ||
| """Implements MSC1763: /_matrix/client/unstable/org.matrix.msc1763/retention/configuration""" | ||
|
|
||
| PATTERNS = client_patterns( | ||
| "/org.matrix.msc1763/retention/configuration$", | ||
| releases=[], | ||
| v1=False, | ||
| unstable=True, | ||
| ) | ||
| CATEGORY = "Client API requests" | ||
|
|
||
| def __init__(self, hs: "HomeServer"): | ||
| super().__init__() | ||
| self.auth = hs.get_auth() | ||
| self._retention_config = hs.config.retention | ||
|
|
||
| async def on_GET( | ||
| self, request: SynapseRequest | ||
| ) -> tuple[int, RetentionConfigurationResponse]: | ||
| await self.auth.get_user_by_req(request) | ||
|
|
||
| default_policy: RetentionPolicyDict = {} | ||
| if self._retention_config.retention_default_min_lifetime is not None: | ||
| default_policy["min_lifetime"] = ( | ||
| self._retention_config.retention_default_min_lifetime | ||
| ) | ||
| if self._retention_config.retention_default_max_lifetime is not None: | ||
| default_policy["max_lifetime"] = ( | ||
| self._retention_config.retention_default_max_lifetime | ||
| ) | ||
|
|
||
| max_lifetime_limits: LifetimeBoundsDict = {} | ||
| if self._retention_config.retention_allowed_lifetime_min is not None: | ||
| max_lifetime_limits["min"] = ( | ||
| self._retention_config.retention_allowed_lifetime_min | ||
| ) | ||
| if self._retention_config.retention_allowed_lifetime_max is not None: | ||
| max_lifetime_limits["max"] = ( | ||
| self._retention_config.retention_allowed_lifetime_max | ||
| ) | ||
|
|
||
| limits: RetentionLimitsDict = {} | ||
| if max_lifetime_limits: | ||
| limits["max_lifetime"] = max_lifetime_limits | ||
|
|
||
| policies: dict[str, RetentionPolicyDict] = {} | ||
| if default_policy: | ||
| policies["*"] = default_policy | ||
|
|
||
| return HTTPStatus.OK, {"policies": policies, "limits": limits} | ||
|
|
||
|
|
||
| def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: | ||
| if hs.config.retention.retention_enabled and hs.config.experimental.msc1763_enabled: | ||
| RetentionConfigurationServlet(hs).register(http_server) | ||
|
Comment on lines
+100
to
+102
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Server-wide retention is kinda considered stable in Synapse (it's at least in the stable config) but this is introducing an unstable endpoint. Could you gate this behind an experimental feature? It's not great that Synapse is considering unstable room-level retention state events if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, fair cop. I'll do the do. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A future PR could fold the per-room state changes into this experimental feature, but for now it's just the config.