mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
7e4071c117
**Does not yet work!** Currently, state resolution does not correctly resolve conflicting states. Everything else appears to work as expected, so stateres will be fixed soon, then we should be clear for takeoff. Also: a lot of things currently accept a nullable room ID that really just don't need to. This will need tidying up before merge. Some authentication checks have also been disabled temporarily but nothing important. A lot of things are tagged with `TODO(hydra)`, those need resolving before merge. External contributors should PR to the `hydra/public` branch, *not* ` main`. --- This PR should be squash merged. Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/943 Co-authored-by: nexy7574 <git@nexy7574.co.uk> Co-committed-by: nexy7574 <git@nexy7574.co.uk>
56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
use conduwuit_core::{
|
|
Result, err, implement,
|
|
matrix::event::Event,
|
|
utils::{self},
|
|
};
|
|
use ruma::EventId;
|
|
|
|
use super::ExtractBody;
|
|
use crate::rooms::short::ShortRoomId;
|
|
|
|
/// Replace a PDU with the redacted form.
|
|
#[implement(super::Service)]
|
|
#[tracing::instrument(name = "redact", level = "debug", skip(self))]
|
|
pub async fn redact_pdu<Pdu: Event + Send + Sync>(
|
|
&self,
|
|
event_id: &EventId,
|
|
reason: &Pdu,
|
|
shortroomid: ShortRoomId,
|
|
) -> Result {
|
|
// TODO: Don't reserialize, keep original json
|
|
let Ok(pdu_id) = self.get_pdu_id(event_id).await else {
|
|
// If event does not exist, just noop
|
|
return Ok(());
|
|
};
|
|
|
|
let mut pdu = self
|
|
.get_pdu_from_id(&pdu_id)
|
|
.await
|
|
.map(Event::into_pdu)
|
|
.map_err(|e| {
|
|
err!(Database(error!(?pdu_id, ?event_id, ?e, "PDU ID points to invalid PDU.")))
|
|
})?;
|
|
|
|
if let Ok(content) = pdu.get_content::<ExtractBody>() {
|
|
if let Some(body) = content.body {
|
|
self.services
|
|
.search
|
|
.deindex_pdu(shortroomid, &pdu_id, &body);
|
|
}
|
|
}
|
|
|
|
let room_version_id = self
|
|
.services
|
|
.state
|
|
.get_room_version(&pdu.room_id_or_hash())
|
|
.await?;
|
|
|
|
pdu.redact(&room_version_id, reason.to_value())?;
|
|
|
|
let obj = utils::to_canonical_object(&pdu).map_err(|e| {
|
|
err!(Database(error!(?event_id, ?e, "Failed to convert PDU to canonical JSON")))
|
|
})?;
|
|
|
|
self.replace_pdu(&pdu_id, &obj).await
|
|
}
|