Handle MSC4242 in redact

This commit is contained in:
Erik Johnston
2026-05-27 12:57:30 +01:00
parent 15462d1d44
commit 925f5a1294
2 changed files with 13 additions and 2 deletions
+2
View File
@@ -61,6 +61,8 @@ pub mod event_field {
pub const REPLACES_STATE: &str = "replaces_state";
/// Event field: msc4354_sticky
pub const MSC4354_STICKY: &str = "msc4354_sticky";
// Event field: prev_state_events
pub const PREV_STATE_EVENTS: &str = "prev_state_events";
}
pub mod unsigned_field {
+11 -2
View File
@@ -24,8 +24,10 @@ use super::constants::{
redaction_field,
unsigned_field::AGE_TS,
};
use crate::canonical_json::CanonicalizationOptions;
use crate::room_versions::{EventFormatVersions, RoomVersion};
use crate::{
canonical_json::CanonicalizationOptions, events::constants::event_field::PREV_STATE_EVENTS,
};
/// Calculates the event_id of an event.
///
@@ -99,7 +101,6 @@ pub fn redact(event: &Value, room_version: &RoomVersion) -> anyhow::Result<Value
(STATE_KEY),
(DEPTH),
(PREV_EVENTS),
(AUTH_EVENTS),
(ORIGIN_SERVER_TS),
]);
@@ -108,6 +109,14 @@ pub fn redact(event: &Value, room_version: &RoomVersion) -> anyhow::Result<Value
allowed_keys.extend([PREV_STATE, MEMBERSHIP, ORIGIN]);
}
// Room versions with MSC4242 have `prev_state_events` instead of
// `auth_events`.
if room_version.msc4242_state_dags {
allowed_keys.insert(PREV_STATE_EVENTS);
} else {
allowed_keys.insert(AUTH_EVENTS);
}
let event_type = event
.get(TYPE)
.with_context(|| format!("Missing {TYPE} field in json"))?