add command to force join user to room (#136)

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-09 06:15:45 +00:00
parent 5dcdafe207
commit 50c2d2b801
2 changed files with 26 additions and 2 deletions

View file

@ -8,7 +8,7 @@ use ruma::{
tag::{TagEvent, TagEventContent, TagInfo}, tag::{TagEvent, TagEventContent, TagInfo},
RoomAccountDataEventType, RoomAccountDataEventType,
}, },
OwnedRoomId, OwnedUserId, RoomId, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, RoomId,
}; };
use tracing::{error, info, warn}; 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)) 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<RoomMessageEventContent> {
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( pub(super) async fn put_room_tag(
_body: Vec<&str>, user_id: String, room_id: Box<RoomId>, tag: String, _body: Vec<&str>, user_id: String, room_id: Box<RoomId>, tag: String,
) -> Result<RoomMessageEventContent> { ) -> Result<RoomMessageEventContent> {

View file

@ -2,7 +2,7 @@ mod commands;
use clap::Subcommand; use clap::Subcommand;
use conduit::Result; use conduit::Result;
use ruma::{events::room::message::RoomMessageEventContent, RoomId}; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomOrAliasId, RoomId};
use self::commands::*; use self::commands::*;
@ -65,6 +65,12 @@ pub(super) enum UserCommand {
user_id: String, 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. /// - Puts a room tag for the specified user and room ID.
/// ///
/// This is primarily useful if you'd like to set your admin room /// 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<Roo
UserCommand::ListJoinedRooms { UserCommand::ListJoinedRooms {
user_id, user_id,
} => list_joined_rooms(body, user_id).await?, } => list_joined_rooms(body, user_id).await?,
UserCommand::ForceJoinRoom {
user_id,
room_id,
} => force_join_room(body, user_id, room_id).await?,
UserCommand::PutRoomTag { UserCommand::PutRoomTag {
user_id, user_id,
room_id, room_id,