tuwunel_admin/query/sending/
mod.rs1mod active_requests;
2mod active_requests_for;
3mod get_latest_edu_count;
4mod parked_rooms;
5mod queued_requests;
6
7use clap::Subcommand;
8use ruma::{OwnedServerName, OwnedUserId};
9use tuwunel_core::{Err, Result};
10use tuwunel_service::sending::Destination;
11
12use crate::admin_command_dispatch;
13
14#[admin_command_dispatch(handler_prefix = "sending")]
15#[derive(Debug, Subcommand)]
16pub(crate) enum SendingCommand {
18 ActiveRequests,
20
21 ActiveRequestsFor {
33 #[arg(short, long)]
34 appservice_id: Option<String>,
35 #[arg(short, long)]
36 server_name: Option<OwnedServerName>,
37 #[arg(short, long)]
38 user_id: Option<OwnedUserId>,
39 #[arg(short, long)]
40 push_key: Option<String>,
41 },
42
43 QueuedRequests {
55 #[arg(short, long)]
56 appservice_id: Option<String>,
57 #[arg(short, long)]
58 server_name: Option<OwnedServerName>,
59 #[arg(short, long)]
60 user_id: Option<OwnedUserId>,
61 #[arg(short, long)]
62 push_key: Option<String>,
63 },
64
65 GetLatestEduCount {
66 server_name: OwnedServerName,
67 },
68
69 ParkedRooms,
74}
75
76fn parse_destination(
77 appservice_id: Option<String>,
78 server_name: Option<OwnedServerName>,
79 user_id: Option<OwnedUserId>,
80 push_key: Option<String>,
81) -> Result<Destination> {
82 if appservice_id.is_none() && server_name.is_none() && user_id.is_none() && push_key.is_none()
83 {
84 return Err!(
85 "An appservice ID, server name, or a user ID with push key must be specified via \
86 arguments. See --help for more details.",
87 );
88 }
89
90 match (appservice_id, server_name, user_id, push_key) {
91 | (Some(appservice_id), None, None, None) => {
92 if appservice_id.is_empty() {
93 return Err!(
94 "An appservice ID, server name, or a user ID with push key must be \
95 specified via arguments. See --help for more details.",
96 );
97 }
98
99 Ok(Destination::Appservice(appservice_id))
100 },
101 | (None, Some(server_name), None, None) => Ok(Destination::Federation(server_name)),
102 | (None, None, Some(user_id), Some(push_key)) => {
103 if push_key.is_empty() {
104 return Err!(
105 "An appservice ID, server name, or a user ID with push key must be \
106 specified via arguments. See --help for more details.",
107 );
108 }
109
110 Ok(Destination::Push(user_id, push_key))
111 },
112 | (Some(_), Some(_), Some(_), Some(_)) => Err!(
113 "An appservice ID, server name, or a user ID with push key must be specified via \
114 arguments. Not all of them See --help for more details.",
115 ),
116 | _ => Err!(
117 "An appservice ID, server name, or a user ID with push key must be specified via \
118 arguments. See --help for more details.",
119 ),
120 }
121}