mirror of https://gitlab.com/famedly/conduit
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
Rust
57 lines
1.5 KiB
Rust
3 years ago
|
use std::sync::Arc;
|
||
|
|
||
2 years ago
|
use crate::{database::DatabaseGuard, pdu::PduBuilder, Result, Ruma};
|
||
4 years ago
|
use ruma::{
|
||
2 years ago
|
api::client::redact::redact_event,
|
||
2 years ago
|
events::{room::redaction::RoomRedactionEventContent, RoomEventType},
|
||
4 years ago
|
};
|
||
|
|
||
3 years ago
|
use serde_json::value::to_raw_value;
|
||
4 years ago
|
|
||
3 years ago
|
/// # `PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}`
|
||
|
///
|
||
|
/// Tries to send a redaction event into the room.
|
||
|
///
|
||
|
/// - TODO: Handle txn id
|
||
4 years ago
|
pub async fn redact_event_route(
|
||
3 years ago
|
db: DatabaseGuard,
|
||
2 years ago
|
body: Ruma<redact_event::v3::IncomingRequest>,
|
||
2 years ago
|
) -> Result<redact_event::v3::Response> {
|
||
4 years ago
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||
3 years ago
|
let body = body.body;
|
||
4 years ago
|
|
||
3 years ago
|
let mutex_state = Arc::clone(
|
||
3 years ago
|
db.globals
|
||
3 years ago
|
.roomid_mutex_state
|
||
3 years ago
|
.write()
|
||
|
.unwrap()
|
||
|
.entry(body.room_id.clone())
|
||
|
.or_default(),
|
||
|
);
|
||
3 years ago
|
let state_lock = mutex_state.lock().await;
|
||
3 years ago
|
|
||
4 years ago
|
let event_id = db.rooms.build_and_append_pdu(
|
||
|
PduBuilder {
|
||
2 years ago
|
event_type: RoomEventType::RoomRedaction,
|
||
3 years ago
|
content: to_raw_value(&RoomRedactionEventContent {
|
||
4 years ago
|
reason: body.reason.clone(),
|
||
|
})
|
||
|
.expect("event is valid, we just created it"),
|
||
|
unsigned: None,
|
||
|
state_key: None,
|
||
3 years ago
|
redacts: Some(body.event_id.into()),
|
||
4 years ago
|
},
|
||
3 years ago
|
sender_user,
|
||
4 years ago
|
&body.room_id,
|
||
4 years ago
|
&db,
|
||
3 years ago
|
&state_lock,
|
||
4 years ago
|
)?;
|
||
4 years ago
|
|
||
3 years ago
|
drop(state_lock);
|
||
3 years ago
|
|
||
3 years ago
|
db.flush()?;
|
||
4 years ago
|
|
||
3 years ago
|
let event_id = (*event_id).to_owned();
|
||
2 years ago
|
Ok(redact_event::v3::Response { event_id })
|
||
4 years ago
|
}
|