Skip to main content

tuwunel_admin/query/
short.rs

1use clap::Subcommand;
2use ruma::{OwnedEventId, OwnedRoomOrAliasId};
3use tuwunel_core::Result;
4
5use crate::{admin_command, admin_command_dispatch};
6
7#[admin_command_dispatch]
8#[derive(Debug, Subcommand)]
9/// Query tables from database
10pub(crate) enum ShortCommand {
11	ShortEventId {
12		event_id: OwnedEventId,
13	},
14
15	ShortRoomId {
16		room_id: OwnedRoomOrAliasId,
17	},
18}
19
20#[admin_command]
21pub(super) async fn short_event_id(&self, event_id: OwnedEventId) -> Result {
22	let shortid = self
23		.services
24		.short
25		.get_shorteventid(&event_id)
26		.await?;
27
28	self.write_str(&format!("{shortid:#?}")).await
29}
30
31#[admin_command]
32pub(super) async fn short_room_id(&self, room_id: OwnedRoomOrAliasId) -> Result {
33	let room_id = self
34		.services
35		.alias
36		.maybe_resolve(&room_id)
37		.await?;
38
39	let shortid = self
40		.services
41		.short
42		.get_shortroomid(&room_id)
43		.await?;
44
45	self.write_str(&format!("{shortid:#?}")).await
46}