Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit c8a730c

Browse files
committed
implement MSC4267 automatically forgetting room on leave
Signed-off-by: strawberry <[email protected]>
1 parent bb0b57e commit c8a730c

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

conduwuit-example.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,19 @@
445445
#
446446
#allow_federation = true
447447

448-
# This item is undocumented. Please contribute documentation for it.
448+
# Allows federation requests to be made to itself
449+
#
450+
# This isn't intended and is very likely a bug if federation requests are
451+
# being sent to yourself. This currently mainly exists for development
452+
# purposes.
449453
#
450454
#federation_loopback = false
451455

456+
# Always calls /forget on behalf of the user if leaving a room. This is a
457+
# part of MSC4267 "Automatically forgetting rooms on leave"
458+
#
459+
#forget_forced_upon_leave = false
460+
452461
# Set this to true to require authentication on the normally
453462
# unauthenticated profile retrieval endpoints (GET)
454463
# "/_matrix/client/v3/profile/{userId}".

src/api/client/capabilities.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ pub(crate) async fn get_capabilities_route(
4242
.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))
4343
.expect("this is valid JSON we created");
4444

45+
capabilities
46+
.set(
47+
"org.matrix.msc4267.forget_forced_upon_leave",
48+
json!({"enabled": services.config.forget_forced_upon_leave}),
49+
)
50+
.expect("valid JSON we created");
51+
4552
Ok(get_capabilities::v3::Response { capabilities })
4653
}

src/core/config/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,19 @@ pub struct Config {
558558
#[serde(default = "true_fn")]
559559
pub allow_federation: bool,
560560

561+
/// Allows federation requests to be made to itself
562+
///
563+
/// This isn't intended and is very likely a bug if federation requests are
564+
/// being sent to yourself. This currently mainly exists for development
565+
/// purposes.
561566
#[serde(default)]
562567
pub federation_loopback: bool,
563568

569+
/// Always calls /forget on behalf of the user if leaving a room. This is a
570+
/// part of MSC4267 "Automatically forgetting rooms on leave"
571+
#[serde(default)]
572+
pub forget_forced_upon_leave: bool,
573+
564574
/// Set this to true to require authentication on the normally
565575
/// unauthenticated profile retrieval endpoints (GET)
566576
/// "/_matrix/client/v3/profile/{userId}".

src/service/rooms/state_cache/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ruma::{
2828
serde::Raw,
2929
};
3030

31-
use crate::{Dep, account_data, appservice::RegistrationInfo, globals, rooms, users};
31+
use crate::{Dep, account_data, appservice::RegistrationInfo, config, globals, rooms, users};
3232

3333
pub struct Service {
3434
appservice_in_room_cache: AppServiceInRoomCache,
@@ -38,6 +38,7 @@ pub struct Service {
3838

3939
struct Services {
4040
account_data: Dep<account_data::Service>,
41+
config: Dep<config::Service>,
4142
globals: Dep<globals::Service>,
4243
state_accessor: Dep<rooms::state_accessor::Service>,
4344
users: Dep<users::Service>,
@@ -70,6 +71,7 @@ impl crate::Service for Service {
7071
appservice_in_room_cache: RwLock::new(HashMap::new()),
7172
services: Services {
7273
account_data: args.depend::<account_data::Service>("account_data"),
74+
config: args.depend::<config::Service>("config"),
7375
globals: args.depend::<globals::Service>("globals"),
7476
state_accessor: args
7577
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
@@ -268,7 +270,9 @@ impl Service {
268270
| MembershipState::Leave | MembershipState::Ban => {
269271
self.mark_as_left(user_id, room_id);
270272

271-
if self.services.globals.user_is_local(user_id) {
273+
if self.services.globals.user_is_local(user_id)
274+
&& self.services.config.forget_forced_upon_leave
275+
{
272276
self.forget(room_id, user_id);
273277
}
274278
},

0 commit comments

Comments
 (0)