From 50c2d2b80151c888ebb49153d1e8b0c9dee02c44 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 9 Jul 2024 06:15:45 +0000 Subject: [PATCH] add command to force join user to room (#136) Signed-off-by: Jason Volk --- src/admin/user/commands.rs | 16 +++++++++++++++- src/admin/user/mod.rs | 12 +++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 12aa0170..218dadb9 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -8,7 +8,7 @@ use ruma::{ tag::{TagEvent, TagEventContent, TagInfo}, RoomAccountDataEventType, }, - OwnedRoomId, OwnedUserId, RoomId, + OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, RoomId, }; use tracing::{error, info, warn}; @@ -334,6 +334,20 @@ pub(super) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Resu Ok(RoomMessageEventContent::text_html(output_plain, output_html)) } +pub(super) async fn force_join_room( + _body: Vec<&str>, user_id: String, room_id: OwnedRoomOrAliasId, +) -> Result { + let user_id = parse_local_user_id(&user_id)?; + let room_id = services().rooms.alias.resolve(&room_id).await?; + + assert!(service::user_is_local(&user_id), "Parsed user_id must be a local user"); + join_room_by_id_helper(&user_id, &room_id, None, &[], None).await?; + + Ok(RoomMessageEventContent::notice_markdown(format!( + "{user_id} has been joined to {room_id}.", + ))) +} + pub(super) async fn put_room_tag( _body: Vec<&str>, user_id: String, room_id: Box, tag: String, ) -> Result { diff --git a/src/admin/user/mod.rs b/src/admin/user/mod.rs index 088133a5..e7d3d251 100644 --- a/src/admin/user/mod.rs +++ b/src/admin/user/mod.rs @@ -2,7 +2,7 @@ mod commands; use clap::Subcommand; use conduit::Result; -use ruma::{events::room::message::RoomMessageEventContent, RoomId}; +use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomOrAliasId, RoomId}; use self::commands::*; @@ -65,6 +65,12 @@ pub(super) enum UserCommand { user_id: String, }, + /// - Manually join a local user to a room. + ForceJoinRoom { + user_id: String, + room_id: OwnedRoomOrAliasId, + }, + /// - Puts a room tag for the specified user and room ID. /// /// This is primarily useful if you'd like to set your admin room @@ -113,6 +119,10 @@ pub(super) async fn process(command: UserCommand, body: Vec<&str>) -> Result list_joined_rooms(body, user_id).await?, + UserCommand::ForceJoinRoom { + user_id, + room_id, + } => force_join_room(body, user_id, room_id).await?, UserCommand::PutRoomTag { user_id, room_id,