implement MSC4267 automatically forgetting room on leave

Signed-off-by: strawberry <june@girlboss.ceo>
This commit is contained in:
strawberry 2025-03-08 03:07:42 -05:00
parent bb0b57efb8
commit c8a730c29e
No known key found for this signature in database
4 changed files with 33 additions and 3 deletions

View file

@ -445,10 +445,19 @@
#
#allow_federation = true
# This item is undocumented. Please contribute documentation for it.
# Allows federation requests to be made to itself
#
# This isn't intended and is very likely a bug if federation requests are
# being sent to yourself. This currently mainly exists for development
# purposes.
#
#federation_loopback = false
# Always calls /forget on behalf of the user if leaving a room. This is a
# part of MSC4267 "Automatically forgetting rooms on leave"
#
#forget_forced_upon_leave = false
# Set this to true to require authentication on the normally
# unauthenticated profile retrieval endpoints (GET)
# "/_matrix/client/v3/profile/{userId}".

View file

@ -42,5 +42,12 @@ pub(crate) async fn get_capabilities_route(
.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))
.expect("this is valid JSON we created");
capabilities
.set(
"org.matrix.msc4267.forget_forced_upon_leave",
json!({"enabled": services.config.forget_forced_upon_leave}),
)
.expect("valid JSON we created");
Ok(get_capabilities::v3::Response { capabilities })
}

View file

@ -558,9 +558,19 @@ pub struct Config {
#[serde(default = "true_fn")]
pub allow_federation: bool,
/// Allows federation requests to be made to itself
///
/// This isn't intended and is very likely a bug if federation requests are
/// being sent to yourself. This currently mainly exists for development
/// purposes.
#[serde(default)]
pub federation_loopback: bool,
/// Always calls /forget on behalf of the user if leaving a room. This is a
/// part of MSC4267 "Automatically forgetting rooms on leave"
#[serde(default)]
pub forget_forced_upon_leave: bool,
/// Set this to true to require authentication on the normally
/// unauthenticated profile retrieval endpoints (GET)
/// "/_matrix/client/v3/profile/{userId}".

View file

@ -28,7 +28,7 @@ use ruma::{
serde::Raw,
};
use crate::{Dep, account_data, appservice::RegistrationInfo, globals, rooms, users};
use crate::{Dep, account_data, appservice::RegistrationInfo, config, globals, rooms, users};
pub struct Service {
appservice_in_room_cache: AppServiceInRoomCache,
@ -38,6 +38,7 @@ pub struct Service {
struct Services {
account_data: Dep<account_data::Service>,
config: Dep<config::Service>,
globals: Dep<globals::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
users: Dep<users::Service>,
@ -70,6 +71,7 @@ impl crate::Service for Service {
appservice_in_room_cache: RwLock::new(HashMap::new()),
services: Services {
account_data: args.depend::<account_data::Service>("account_data"),
config: args.depend::<config::Service>("config"),
globals: args.depend::<globals::Service>("globals"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
@ -268,7 +270,9 @@ impl Service {
| MembershipState::Leave | MembershipState::Ban => {
self.mark_as_left(user_id, room_id);
if self.services.globals.user_is_local(user_id) {
if self.services.globals.user_is_local(user_id)
&& self.services.config.forget_forced_upon_leave
{
self.forget(room_id, user_id);
}
},