Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18196.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `forget_forced_upon_leave` capability as per [MSC4267](https://github.com/matrix-org/matrix-spec-proposals/pull/4267).
3 changes: 3 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,5 +567,8 @@ def read_config(
False,
)

# MSC4267: Automatically forgetting rooms on leave
self.msc4267_enabled: bool = experimental.get("msc4267_enabled", False)

# MSC4155: Invite filtering
self.msc4155_enabled: bool = experimental.get("msc4155_enabled", False)
2 changes: 1 addition & 1 deletion synapse/config/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:

# When enabled, users will forget rooms when they leave them, either via a
# leave, kick or ban.
self.forget_on_leave = config.get("forget_rooms_on_leave", False)
self.forget_on_leave: bool = config.get("forget_rooms_on_leave", False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're not very careful about making sure our config is the type of value we expect. But I guess this is tracked by matrix-org/synapse#12651 / #12651

The only place I see some validation is in synapse/config/server.py

Otherwise, I see a few places where we do bool(...) or strtobool(str(...))

To be clear, no action needed since this is the status quo.

5 changes: 5 additions & 0 deletions synapse/rest/client/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
"disallowed"
] = disallowed

if self.config.experimental.msc4267_enabled:
response["capabilities"]["org.matrix.msc4267.forget_forced_upon_leave"] = {
"enabled": self.config.room.forget_on_leave,
}

return HTTPStatus.OK, response


Expand Down
40 changes: 40 additions & 0 deletions tests/rest/client/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,43 @@ def test_get_get_token_login_fields_when_enabled(self) -> None:

self.assertEqual(channel.code, HTTPStatus.OK)
self.assertTrue(capabilities["m.get_login_token"]["enabled"])

@override_config(
{
"experimental_features": {"msc4267_enabled": True},
"forget_rooms_on_leave": True,
}
)
def test_get_forget_forced_upon_leave_with_auto_forget(self) -> None:
# Server auto-forgets on /leave, expect enabled client capability
access_token = self.get_success(
self.auth_handler.create_access_token_for_user_id(
self.user, device_id=None, valid_until_ms=None
)
)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, HTTPStatus.OK)
self.assertTrue(
capabilities["org.matrix.msc4267.forget_forced_upon_leave"]["enabled"]
)

@override_config(
{
"experimental_features": {"msc4267_enabled": True},
"forget_rooms_on_leave": False,
}
)
def test_get_forget_forced_upon_leave_without_auto_forget(self) -> None:
# Server doesn't auto-forget on /leave, expect disabled client capability
access_token = self.get_success(
self.auth_handler.create_access_token_for_user_id(
self.user, device_id=None, valid_until_ms=None
)
)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, HTTPStatus.OK)
self.assertFalse(
capabilities["org.matrix.msc4267.forget_forced_upon_leave"]["enabled"]
)