Skip to main content

tuwunel_admin/query/sending/
mod.rs

1mod 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)]
16/// All the getters and iterators from src/service/sending/
17pub(crate) enum SendingCommand {
18	/// - Queries database for all `servercurrentevent_data`
19	ActiveRequests,
20
21	/// - Queries database for `servercurrentevent_data` but for a specific
22	///   destination
23	///
24	/// This command takes only *one* format of these arguments:
25	///
26	/// appservice_id
27	/// server_name
28	/// user_id AND push_key
29	///
30	/// See src/service/sending/dest.rs for the definition of the `Destination`
31	/// enum
32	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	/// - Queries database for `servernameevent_data` which are the queued up
44	///   requests that will eventually be sent
45	///
46	/// This command takes only *one* format of these arguments:
47	///
48	/// appservice_id
49	/// server_name
50	/// user_id AND push_key
51	///
52	/// See src/service/sending/dest.rs for the definition of the `Destination`
53	/// enum
54	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	/// - Lists rooms held back from servers that keep rejecting them
70	///
71	/// A park whose time has passed is retried with the next transaction to
72	/// its server; its count resets once the room is delivered.
73	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}