1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-28 10:48:30 +00:00
continuwuity/src/client_server/redact.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

2021-07-13 15:44:25 +02:00
use std::sync::Arc;
2021-07-14 07:07:08 +00:00
use crate::{database::DatabaseGuard, pdu::PduBuilder, ConduitResult, Ruma};
2020-07-30 18:14:47 +02:00
use ruma::{
api::client::r0::redact::redact_event,
events::{room::redaction, EventType},
};
#[cfg(feature = "conduit_bin")]
use rocket::put;
#[cfg_attr(
feature = "conduit_bin",
put("/_matrix/client/r0/rooms/<_>/redact/<_>/<_>", data = "<body>")
)]
2021-02-28 12:41:03 +01:00
#[tracing::instrument(skip(db, body))]
2020-09-14 20:23:19 +02:00
pub async fn redact_event_route(
2021-07-14 07:07:08 +00:00
db: DatabaseGuard,
2020-09-08 17:32:03 +02:00
body: Ruma<redact_event::Request<'_>>,
2020-07-30 18:14:47 +02:00
) -> ConduitResult<redact_event::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
2020-07-30 18:14:47 +02:00
2021-07-13 15:44:25 +02:00
let mutex = Arc::clone(
db.globals
.roomid_mutex
.write()
.unwrap()
.entry(body.room_id.clone())
.or_default(),
);
let mutex_lock = mutex.lock().await;
2020-10-05 22:19:22 +02: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()),
},
&sender_user,
2020-10-05 22:19:22 +02:00
&body.room_id,
2021-01-15 11:05:57 -05:00
&db,
2021-07-13 15:44:25 +02:00
&mutex_lock,
2020-10-05 22:19:22 +02:00
)?;
2020-07-30 18:14:47 +02:00
2021-07-13 15:44:25 +02:00
drop(mutex_lock);
db.flush()?;
2020-07-30 18:14:47 +02:00
Ok(redact_event::Response { event_id }.into())
}