Skip to main content

tuwunel_admin/room/directory/
mod.rs

1mod list;
2mod publish;
3mod unpublish;
4
5use clap::Subcommand;
6use ruma::{OwnedRoomOrAliasId, RoomAliasId, RoomOrAliasId};
7use tuwunel_core::{Err, Result};
8use tuwunel_service::Services;
9
10use crate::admin_command_dispatch;
11
12#[admin_command_dispatch(handler_prefix = "directory")]
13#[derive(Debug, Subcommand)]
14pub(crate) enum RoomDirectoryCommand {
15	/// - Publish a room to the room directory
16	Publish {
17		/// The room id or local alias of the room to publish; an alias is
18		/// also published as the directory entry's alias
19		room: OwnedRoomOrAliasId,
20
21		/// Publish even if the room is unknown to the server, without
22		/// recording an alias
23		#[arg(long)]
24		force: bool,
25	},
26
27	/// - Unpublish a room to the room directory
28	Unpublish {
29		/// The room id or local alias of the room to unpublish
30		room: OwnedRoomOrAliasId,
31	},
32
33	/// - List rooms that are published
34	List {
35		page: Option<usize>,
36	},
37}
38
39/// Parse the alias form of the argument, rejecting a remote alias: these
40/// commands resolve without federation.
41fn local_alias<'a>(
42	services: &Services,
43	room: &'a RoomOrAliasId,
44) -> Result<Option<&'a RoomAliasId>> {
45	match <&RoomAliasId>::try_from(room).ok() {
46		| Some(alias) if !services.globals.alias_is_local(alias) =>
47			Err!("Alias {alias} is not local to this server; use the room id instead"),
48		| alias => Ok(alias),
49	}
50}