tuwunel_api/client/report/
report_room.rs1use axum::extract::State;
2use ruma::api::client::room::report_room;
3use tuwunel_core::{Err, Result, info};
4
5use super::REASON_MAX_LEN;
6use crate::{ClientIp, Ruma};
7
8#[tracing::instrument(skip_all, fields(%client), name = "report_room")]
12pub(crate) async fn report_room_route(
13 State(services): State<crate::State>,
14 ClientIp(client): ClientIp,
15 body: Ruma<report_room::v3::Request>,
16) -> Result<report_room::v3::Response> {
17 let sender_user = body.sender_user();
18
19 info!(
20 "Received room report by user {sender_user} for room {} with reason: \"{}\"",
21 body.room_id, body.reason,
22 );
23
24 if body.reason.len() > REASON_MAX_LEN {
25 return Err!(Request(InvalidParam(
26 "Reason too long, should be {REASON_MAX_LEN} characters or fewer"
27 )));
28 }
29
30 if !services
31 .state_cache
32 .server_in_room(&services.server.name, &body.room_id)
33 .await
34 {
35 return Err!(Request(NotFound(
36 "Room does not exist to us, no local users have joined at all"
37 )));
38 }
39
40 services
41 .admin
42 .send_report(&format!(
43 "@room Room report received from {}\nReport Reason: {}\n\nRoom ID: {}",
44 sender_user, body.reason, body.room_id,
45 ))
46 .await;
47
48 Ok(report_room::v3::Response {})
49}