2024-07-16 08:05:25 +00:00
|
|
|
use axum::extract::State;
|
2026-04-10 11:47:01 -04:00
|
|
|
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
2024-12-15 00:05:47 -05:00
|
|
|
use ruma::{
|
2026-04-11 14:21:29 -04:00
|
|
|
api::client::redact::redact_event, assign, events::room::redaction::RoomRedactionEventContent,
|
2024-12-15 00:05:47 -05:00
|
|
|
};
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2026-07-16 13:38:37 +02:00
|
|
|
use crate::{Ruma, client_ip::ClientIp};
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2021-08-31 19:14:37 +02:00
|
|
|
/// # `PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}`
|
|
|
|
|
///
|
|
|
|
|
/// Tries to send a redaction event into the room.
|
|
|
|
|
///
|
|
|
|
|
/// - TODO: Handle txn id
|
2024-07-16 08:05:25 +00:00
|
|
|
pub(crate) async fn redact_event_route(
|
2024-12-15 00:05:47 -05:00
|
|
|
State(services): State<crate::State>,
|
2026-07-12 17:30:05 +01:00
|
|
|
ClientIp(client_ip): ClientIp, // NOTE: required for updating device metadata
|
2024-12-15 00:05:47 -05:00
|
|
|
body: Ruma<redact_event::v3::Request>,
|
2024-07-16 08:05:25 +00:00
|
|
|
) -> Result<redact_event::v3::Response> {
|
2026-05-27 12:15:16 -04:00
|
|
|
let sender_user = body.identity.expect_sender_user()?;
|
2025-12-02 14:46:13 +00:00
|
|
|
services
|
|
|
|
|
.users
|
2026-05-26 13:28:23 -04:00
|
|
|
.update_device_last_seen(sender_user, body.identity.sender_device(), client_ip)
|
2025-12-02 14:46:13 +00:00
|
|
|
.await;
|
2025-04-26 23:06:43 +00:00
|
|
|
let body = &body.body;
|
2025-06-28 20:37:09 +01:00
|
|
|
if services.users.is_suspended(sender_user).await? {
|
|
|
|
|
// TODO: Users can redact their own messages while suspended
|
|
|
|
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
|
|
|
|
}
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2026-04-11 14:21:29 -04:00
|
|
|
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
2021-07-13 15:44:25 +02:00
|
|
|
|
2024-07-16 08:05:25 +00:00
|
|
|
let event_id = services
|
2023-11-25 18:29:38 -05:00
|
|
|
.rooms
|
|
|
|
|
.timeline
|
|
|
|
|
.build_and_append_pdu(
|
2026-04-10 11:47:01 -04:00
|
|
|
PartialPdu {
|
2024-12-28 00:57:02 +00:00
|
|
|
redacts: Some(body.event_id.clone()),
|
2026-04-11 14:21:29 -04:00
|
|
|
..PartialPdu::timeline(
|
|
|
|
|
&assign!(RoomRedactionEventContent::new_v11(body.event_id.clone()), {
|
|
|
|
|
reason: body.reason.clone()
|
|
|
|
|
}),
|
|
|
|
|
)
|
2023-11-25 18:29:38 -05:00
|
|
|
},
|
|
|
|
|
sender_user,
|
2025-09-17 20:46:03 +00:00
|
|
|
Some(&body.room_id),
|
2023-11-25 18:29:38 -05:00
|
|
|
&state_lock,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2021-08-03 11:10:58 +02:00
|
|
|
drop(state_lock);
|
2021-07-13 15:44:25 +02:00
|
|
|
|
2026-04-11 14:21:29 -04:00
|
|
|
Ok(redact_event::v3::Response::new(event_id))
|
2020-07-30 18:14:47 +02:00
|
|
|
}
|