1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-07-27 17:28:36 +00:00
conduit/src/api/client_server/redact.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

2021-07-13 15:44:25 +02:00
use std::sync::Arc;
use crate::{Result, Ruma, services, service::pdu::PduBuilder};
2020-07-30 18:14:47 +02:00
use ruma::{
2022-02-18 15:33:14 +01:00
api::client::redact::redact_event,
2022-04-06 21:31:29 +02:00
events::{room::redaction::RoomRedactionEventContent, RoomEventType},
2020-07-30 18:14:47 +02:00
};
use serde_json::value::to_raw_value;
2020-07-30 18:14:47 +02: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
2020-09-14 20:23:19 +02:00
pub async fn redact_event_route(
2022-04-06 21:31:29 +02:00
body: Ruma<redact_event::v3::IncomingRequest>,
2022-02-18 15:33:14 +01:00
) -> Result<redact_event::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let body = body.body;
2020-07-30 18:14:47 +02:00
2021-08-03 11:10:58 +02:00
let mutex_state = Arc::clone(
services().globals
2021-08-03 11:10:58 +02:00
.roomid_mutex_state
2021-07-13 15:44:25 +02:00
.write()
.unwrap()
.entry(body.room_id.clone())
.or_default(),
);
2021-08-03 11:10:58 +02:00
let state_lock = mutex_state.lock().await;
2021-07-13 15:44:25 +02:00
2022-10-05 09:34:25 +02:00
let event_id = services().rooms.timeline.build_and_append_pdu(
2020-10-05 22:19:22 +02:00
PduBuilder {
2022-04-06 21:31:29 +02:00
event_type: RoomEventType::RoomRedaction,
content: to_raw_value(&RoomRedactionEventContent {
2020-10-05 22:19:22 +02:00
reason: body.reason.clone(),
})
.expect("event is valid, we just created it"),
unsigned: None,
state_key: None,
redacts: Some(body.event_id.into()),
2020-10-05 22:19:22 +02:00
},
sender_user,
2020-10-05 22:19:22 +02:00
&body.room_id,
2021-08-03 11:10:58 +02:00
&state_lock,
2020-10-05 22:19:22 +02:00
)?;
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
let event_id = (*event_id).to_owned();
2022-02-18 15:33:14 +01:00
Ok(redact_event::v3::Response { event_id })
2020-07-30 18:14:47 +02:00
}