tuwunel_api/client/
redact.rs1use axum::extract::State;
2use ruma::{
3 api::client::redact::redact_event, events::room::redaction::RoomRedactionEventContent,
4};
5use tuwunel_core::{Err, Result, matrix::pdu::PduBuilder, warn};
6
7use crate::Ruma;
8
9pub(crate) async fn redact_event_route(
15 State(services): State<crate::State>,
16 body: Ruma<redact_event::v3::Request>,
17) -> Result<redact_event::v3::Response> {
18 let sender_user = body.sender_user();
19
20 if services.config.disable_local_redactions
21 && !services.admin.user_is_admin(sender_user).await
22 {
23 warn!(
24 %sender_user,
25 event_id = %body.event_id,
26 "Local redactions are disabled, non-admin user attempted to redact an event"
27 );
28 return Err!(Request(Forbidden("Redactions are disabled on this server.")));
29 }
30
31 let state_lock = services.state.mutex.lock(&body.room_id).await;
32
33 let event_id = services
34 .timeline
35 .build_and_append_pdu(
36 PduBuilder {
37 redacts: Some(body.event_id.clone()),
38 ..PduBuilder::timeline(&RoomRedactionEventContent {
39 redacts: Some(body.event_id.clone()),
40 reason: body.reason.clone(),
41 })
42 },
43 sender_user,
44 &body.room_id,
45 &state_lock,
46 )
47 .await?;
48
49 drop(state_lock);
50
51 Ok(redact_event::v3::Response { event_id })
52}