Create and use Event::redacts()

This commit is contained in:
Erik Johnston committed 2026-06-22 11:21:36 +01:00
1 parent a1cd8f3a53
commit 586368ce9c
2 files changed
+15 -10

No files matched your search

+14 -4
View File
@@ -58,6 +58,7 @@ use pyo3::{
wrap_pyfunction, Bound, IntoPyObject, PyAny, PyResult, Python,
};
use pythonize::{depythonize, pythonize};
use serde_json::Value;
use crate::events::{
constants::event_type::M_ROOM_MEMBER,
@@ -604,8 +605,19 @@ impl Event {
}
}
#[getter]
fn redacts<'py>(&self, py: Python<'py>) -> PyResult<Option<Bound<'py, PyAny>>> {
/// Returns the `redacts` field of this event, if it has one.
#[getter(redacts)]
fn redacts_py<'py>(&self, py: Python<'py>) -> PyResult<Option<Bound<'py, PyAny>>> {
let value = self.redacts();
value
.map(|v| pythonize(py, v).map_err(Into::into))
.transpose()
}
}
impl Event {
/// Returns the `redacts` field of this event, if it has one.
pub fn redacts(&self) -> Option<&Value> {
let common = &self.parsed_event.common_fields;
let value = if self.room_version.updated_redaction_rules {
common.content.get_field(REDACTS)
@@ -613,8 +625,6 @@ impl Event {
common.other_fields.get(REDACTS)
};
value
.map(|v| pythonize(py, v).map_err(Into::into))
.transpose()
}
}
+1 -6
View File
@@ -549,12 +549,7 @@ fn serialize_event_value(
// already in the version-correct place; copy it to the *other* one too,
// for forwards/backwards-compatibility with clients.
if event.r#type() == M_ROOM_REDACTION {
let common = &event.parsed_event.common_fields;
let redacts = if event.room_version.updated_redaction_rules {
common.content.get_field(REDACTS)
} else {
common.other_fields.get(REDACTS)
};
let redacts = event.redacts();
// Skip a present-but-null value: the Python `e.redacts` property
// surfaced JSON null as `None`, and the old code guarded with
// `e.redacts is not None`.