2020-07-30 18:14:47 +02:00
|
|
|
use ruma::{
|
2024-03-05 19:48:54 -05:00
|
|
|
api::client::redact::redact_event,
|
|
|
|
events::{room::redaction::RoomRedactionEventContent, TimelineEventType},
|
2020-07-30 18:14:47 +02:00
|
|
|
};
|
2021-10-13 10:16:45 +02:00
|
|
|
use serde_json::value::to_raw_value;
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2024-03-05 19:48:54 -05:00
|
|
|
use crate::{service::pdu::PduBuilder, services, Result, Ruma};
|
|
|
|
|
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-04-22 23:48:57 -04:00
|
|
|
pub(crate) async fn redact_event_route(body: Ruma<redact_event::v3::Request>) -> Result<redact_event::v3::Response> {
|
2024-03-05 19:48:54 -05:00
|
|
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
|
|
|
let body = body.body;
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2024-07-09 21:10:14 +00:00
|
|
|
let state_lock = services().rooms.state.mutex.lock(&body.room_id).await;
|
2021-07-13 15:44:25 +02:00
|
|
|
|
2024-03-05 19:48:54 -05:00
|
|
|
let event_id = services()
|
|
|
|
.rooms
|
|
|
|
.timeline
|
|
|
|
.build_and_append_pdu(
|
|
|
|
PduBuilder {
|
|
|
|
event_type: TimelineEventType::RoomRedaction,
|
|
|
|
content: to_raw_value(&RoomRedactionEventContent {
|
|
|
|
redacts: Some(body.event_id.clone()),
|
|
|
|
reason: body.reason.clone(),
|
|
|
|
})
|
|
|
|
.expect("event is valid, we just created it"),
|
|
|
|
unsigned: None,
|
|
|
|
state_key: None,
|
|
|
|
redacts: Some(body.event_id.into()),
|
|
|
|
},
|
|
|
|
sender_user,
|
|
|
|
&body.room_id,
|
|
|
|
&state_lock,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2024-03-05 19:48:54 -05:00
|
|
|
drop(state_lock);
|
2021-07-13 15:44:25 +02:00
|
|
|
|
2024-03-05 19:48:54 -05:00
|
|
|
let event_id = (*event_id).to_owned();
|
|
|
|
Ok(redact_event::v3::Response {
|
|
|
|
event_id,
|
|
|
|
})
|
2020-07-30 18:14:47 +02:00
|
|
|
}
|