Skip to main content

tuwunel_admin/room/alias/
mod.rs

1mod list;
2mod remove;
3mod set;
4mod which;
5
6use clap::Subcommand;
7use ruma::{OwnedRoomAliasId, OwnedRoomId};
8use tuwunel_core::Result;
9use tuwunel_service::Services;
10
11use crate::admin_command_dispatch;
12
13#[admin_command_dispatch(handler_prefix = "alias")]
14#[derive(Debug, Subcommand)]
15pub(crate) enum RoomAliasCommand {
16	/// - Make an alias point to a room.
17	Set {
18		#[arg(short, long)]
19		/// Set the alias even if a room is already using it
20		force: bool,
21
22		/// The room id to set the alias on
23		room_id: OwnedRoomId,
24
25		/// The alias localpart to use (`alias`, not `#alias:servername.tld`)
26		room_alias_localpart: String,
27	},
28
29	/// - Remove a local alias
30	Remove {
31		/// The alias localpart to remove (`alias`, not `#alias:servername.tld`)
32		room_alias_localpart: String,
33	},
34
35	/// - Show which room is using an alias
36	Which {
37		/// The alias localpart to look up (`alias`, not
38		/// `#alias:servername.tld`)
39		room_alias_localpart: String,
40	},
41
42	/// - List aliases currently being used
43	List {
44		/// If set, only list the aliases for this room
45		room_id: Option<OwnedRoomId>,
46	},
47}
48
49fn parse_alias_from_localpart(
50	services: &Services,
51	room_alias_localpart: &String,
52) -> Result<OwnedRoomAliasId> {
53	let room_alias_str = format!("#{}:{}", room_alias_localpart, services.globals.server_name());
54
55	Ok(OwnedRoomAliasId::try_from(room_alias_str)?)
56}