tuwunel_admin/room/alias/
set.rs1use ruma::OwnedRoomId;
2use tuwunel_core::{Err, Result, err};
3
4use super::parse_alias_from_localpart;
5use crate::admin_command;
6
7#[admin_command]
8pub(super) async fn alias_set(
9 &self,
10 force: bool,
11 room_id: OwnedRoomId,
12 room_alias_localpart: String,
13) -> Result {
14 let room_alias = parse_alias_from_localpart(self.services, &room_alias_localpart)?;
15
16 match self
17 .services
18 .alias
19 .resolve_local_alias(&room_alias)
20 .await
21 {
22 | Ok(id) => {
23 if !force {
24 return Err!(
25 "Refusing to overwrite in use alias for {id}, use -f or --force to overwrite"
26 );
27 }
28
29 self.services
30 .alias
31 .set_alias(&room_alias, &room_id)
32 .map_err(|err| err!("Failed to remove alias: {err}"))?;
33
34 write!(self, "Successfully overwrote alias (formerly {id})").await
35 },
36 | _ => {
37 self.services
38 .alias
39 .set_alias(&room_alias, &room_id)
40 .map_err(|err| err!("Failed to remove alias: {err}"))?;
41
42 self.write_str("Successfully set alias").await
43 },
44 }
45}