2020-07-30 17:14:47 +01:00
|
|
|
use super::State;
|
|
|
|
use crate::{pdu::PduBuilder, ConduitResult, Database, Ruma};
|
|
|
|
use ruma::{
|
|
|
|
api::client::r0::redact::redact_event,
|
|
|
|
events::{room::redaction, EventType},
|
|
|
|
};
|
2021-06-08 17:10:00 +01:00
|
|
|
use std::sync::Arc;
|
2020-07-30 17:14:47 +01:00
|
|
|
|
|
|
|
#[cfg(feature = "conduit_bin")]
|
|
|
|
use rocket::put;
|
|
|
|
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "conduit_bin",
|
|
|
|
put("/_matrix/client/r0/rooms/<_>/redact/<_>/<_>", data = "<body>")
|
|
|
|
)]
|
2021-02-28 11:41:03 +00:00
|
|
|
#[tracing::instrument(skip(db, body))]
|
2020-09-14 19:23:19 +01:00
|
|
|
pub async fn redact_event_route(
|
2021-06-08 17:10:00 +01:00
|
|
|
db: State<'_, Arc<Database>>,
|
2020-09-08 16:32:03 +01:00
|
|
|
body: Ruma<redact_event::Request<'_>>,
|
2020-07-30 17:14:47 +01:00
|
|
|
) -> ConduitResult<redact_event::Response> {
|
2020-10-18 19:33:12 +01:00
|
|
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
2020-07-30 17:14:47 +01:00
|
|
|
|
2020-10-05 21:19:22 +01:00
|
|
|
let event_id = db.rooms.build_and_append_pdu(
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomRedaction,
|
|
|
|
content: serde_json::to_value(redaction::RedactionEventContent {
|
|
|
|
reason: body.reason.clone(),
|
|
|
|
})
|
|
|
|
.expect("event is valid, we just created it"),
|
|
|
|
unsigned: None,
|
|
|
|
state_key: None,
|
|
|
|
redacts: Some(body.event_id.clone()),
|
|
|
|
},
|
2020-10-18 19:33:12 +01:00
|
|
|
&sender_user,
|
2020-10-05 21:19:22 +01:00
|
|
|
&body.room_id,
|
2021-01-15 16:05:57 +00:00
|
|
|
&db,
|
2020-10-05 21:19:22 +01:00
|
|
|
)?;
|
2020-07-30 17:14:47 +01:00
|
|
|
|
2020-10-21 20:28:02 +01:00
|
|
|
db.flush().await?;
|
|
|
|
|
2020-07-30 17:14:47 +01:00
|
|
|
Ok(redact_event::Response { event_id }.into())
|
|
|
|
}
|