Skip to main content

tuwunel_admin/query/
pusher.rs

1use clap::Subcommand;
2use ruma::OwnedUserId;
3use tuwunel_core::Result;
4use tuwunel_macros::{admin_command, admin_command_dispatch};
5
6#[admin_command_dispatch]
7#[derive(Debug, Subcommand)]
8pub(crate) enum PusherCommand {
9	/// - Returns all the pushers for the user.
10	GetPushers {
11		/// Full user ID
12		user_id: OwnedUserId,
13	},
14
15	/// - Manually delete a pusher for a user.
16	RemovePusher {
17		/// Full user ID
18		user_id: OwnedUserId,
19
20		/// Pushkey
21		pushkey: String,
22	},
23}
24
25#[admin_command]
26pub(super) async fn get_pushers(&self, user_id: OwnedUserId) -> Result {
27	let timer = tokio::time::Instant::now();
28	let results = self.services.pusher.get_pushers(&user_id).await;
29	let query_time = timer.elapsed();
30
31	self.write_string(format!("Query completed in {query_time:?}:\n\n```rs\n{results:#?}```"))
32		.await
33}
34
35#[admin_command]
36pub(super) async fn remove_pusher(&self, user_id: OwnedUserId, pushkey: String) -> Result {
37	let exists = self
38		.services
39		.pusher
40		.get_pusher(&user_id, &pushkey)
41		.await
42		.is_ok();
43
44	self.services
45		.pusher
46		.delete_pusher(&user_id, &pushkey)
47		.await;
48
49	let message = if exists {
50		"Pusher deleted."
51	} else {
52		"Pusher was not found but deletion was still attempted."
53	};
54
55	self.write_str(message).await
56}