Skip to main content

tuwunel_service/admin/
notices.rs

1use futures::FutureExt;
2use ruma::{RoomId, events::room::message::RoomMessageEventContent};
3use tuwunel_core::{Result, implement};
4
5/// Sends a notice gated on the admin_room_notices config; admin command
6/// responses use the unconditional notice().
7#[implement(super::Service)]
8pub async fn notify(&self, body: &str) {
9	if self.services.server.config.admin_room_notices {
10		self.notice(body).await;
11	}
12}
13
14/// Sends a message gated on the admin_room_notices config; admin command
15/// responses use the unconditional send_text().
16#[implement(super::Service)]
17pub async fn notify_loud(&self, body: &str) {
18	if self.services.server.config.admin_room_notices {
19		self.send_text(body).await;
20	}
21}
22
23/// Sends markdown notice to the admin room as the admin user.
24#[implement(super::Service)]
25pub async fn notice(&self, body: &str) {
26	self.send_message(RoomMessageEventContent::notice_markdown(body))
27		.await
28		.ok();
29}
30
31/// Sends markdown message (not an m.notice for notification reasons) to the
32/// admin room as the admin user.
33#[implement(super::Service)]
34pub async fn send_text(&self, body: &str) {
35	self.send_message(RoomMessageEventContent::text_markdown(body))
36		.await
37		.ok();
38}
39
40/// Sends a markdown report to the configured report room, falling back to
41/// the admin room, as the server user.
42#[implement(super::Service)]
43pub async fn send_report(&self, body: &str) {
44	let Ok(room_id) = self.get_report_room().await else {
45		return;
46	};
47
48	self.send_to_room(RoomMessageEventContent::text_markdown(body), &room_id)
49		.await
50		.ok();
51}
52
53/// Sends a message to the admin room as the admin user (see send_text() for
54/// convenience).
55#[implement(super::Service)]
56pub async fn send_message(&self, message_content: RoomMessageEventContent) -> Result {
57	let room_id = self.get_admin_room().await?;
58
59	self.send_to_room(message_content, &room_id).await
60}
61
62#[implement(super::Service)]
63async fn send_to_room(&self, content: RoomMessageEventContent, room_id: &RoomId) -> Result {
64	let user_id = &self.services.globals.server_user;
65
66	self.respond_to_room(content, room_id, user_id)
67		.boxed()
68		.await
69}