Skip to content

Commit

Permalink
add force_leave_room admin command
Browse files Browse the repository at this point in the history
Signed-off-by: strawberry <strawberry@puppygock.gay>
  • Loading branch information
girlbossceo committed Aug 30, 2024
1 parent ae98610 commit 3a623db
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/admin/user/commands.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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<RoomMessageEventContent> {
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<RoomMessageEventContent> {
let user_id = parse_local_user_id(self.services, &user_id)?;
Expand Down
6 changes: 6 additions & 0 deletions src/admin/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3a623db

Please sign in to comment.