mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-27 02:47:33 +00:00
Renamed `redacted_because_id` to `org.continuwuity.redacted_by` for proper namespacing; `get_unsigned_context` now lives in helpers.rs instead of `mod.rs`. The helper function also now explicitly wipes `unsigned` for `redacted_because` to avoid leaks (see comment).
40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use ruma::{RoomVersionId, canonical_json::redact_content_in_place};
|
|
use serde_json::{json, value::to_raw_value};
|
|
|
|
use crate::{Err, Result, err};
|
|
|
|
impl super::Pdu {
|
|
pub fn redact(
|
|
&mut self,
|
|
room_version_id: &RoomVersionId,
|
|
redacted_because: Option<&ruma::EventId>,
|
|
) -> Result {
|
|
let Some(rules) = room_version_id.rules() else {
|
|
return Err!("Cannot redact event for unknown room version {room_version_id}");
|
|
};
|
|
|
|
self.unsigned = None;
|
|
|
|
// a redacted sticky event is just a normal event (MSC4354)
|
|
self.sticky = None;
|
|
|
|
let mut content = serde_json::from_str(self.content.get()).map_err(|e| {
|
|
err!(Request(BadJson("Failed to deserialize content into type: {e}")))
|
|
})?;
|
|
|
|
redact_content_in_place(&mut content, &rules.redaction, self.kind.to_string());
|
|
|
|
if let Some(event_id) = redacted_because {
|
|
self.unsigned = to_raw_value(&json!({
|
|
"org.continuwuity.redacted_by": event_id,
|
|
}))
|
|
.expect("Failed to serialize unsigned")
|
|
.into();
|
|
}
|
|
|
|
self.content = to_raw_value(&content).expect("Failed to serialize content");
|
|
|
|
Ok(())
|
|
}
|
|
}
|