From 3a623dbdc3ae6f5f3b4d12e5257c6e4d6c76dfd1 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 30 Aug 2024 17:17:00 -0400 Subject: [PATCH] add force_leave_room admin command Signed-off-by: strawberry --- src/admin/user/commands.rs | 20 +++++++++++++++++++- src/admin/user/mod.rs | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index c36a3c1d..b84fe873 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, fmt::Write as _}; -use api::client::{join_room_by_id_helper, leave_all_rooms, update_avatar_url, update_displayname}; +use api::client::{join_room_by_id_helper, leave_all_rooms, leave_room, update_avatar_url, update_displayname}; use conduit::{error, info, utils, warn, PduBuilder, Result}; use ruma::{ events::{ @@ -369,6 +369,24 @@ pub(super) async fn force_join_room( ))) } +#[admin_command] +pub(super) async fn force_leave_room( + &self, user_id: String, room_id: OwnedRoomOrAliasId, +) -> Result { + let user_id = parse_local_user_id(self.services, &user_id)?; + let room_id = self.services.rooms.alias.resolve(&room_id).await?; + + assert!( + self.services.globals.user_is_local(&user_id), + "Parsed user_id must be a local user" + ); + leave_room(self.services, &user_id, &room_id, None).await?; + + Ok(RoomMessageEventContent::notice_markdown(format!( + "{user_id} has left {room_id}.", + ))) +} + #[admin_command] pub(super) async fn make_user_admin(&self, user_id: String) -> Result { let user_id = parse_local_user_id(self.services, &user_id)?; diff --git a/src/admin/user/mod.rs b/src/admin/user/mod.rs index f6ecd5e8..d8d740bf 100644 --- a/src/admin/user/mod.rs +++ b/src/admin/user/mod.rs @@ -73,6 +73,12 @@ pub(super) enum UserCommand { room_id: OwnedRoomOrAliasId, }, + /// - Manually leave a local user from a room. + ForceLeaveRoom { + user_id: String, + room_id: OwnedRoomOrAliasId, + }, + /// - Grant server-admin privileges to a user. MakeUserAdmin { user_id: String,