events: Add FullStateEventContent::redact

This commit is contained in:
Jonas Platte 2023-04-11 13:33:35 +02:00
parent 2ccc0323f6
commit 1229fa4461
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
2 changed files with 16 additions and 1 deletions

View File

@ -22,6 +22,7 @@ Improvements:
- `PushCondition::EventMatch` and `FlattenedJson` now use escaped dotted paths, according to MSC3873
- Add unstable support for `event_property_is` push condition according to MSC3758
- Add unstable support for `event_property_contains` push condition according to MSC3966
- Add `FullStateEventContent::redact`
# 0.11.3

View File

@ -14,7 +14,8 @@ use super::{
};
use crate::{
serde::{from_raw_json_value, Raw},
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId,
RoomVersionId, UserId,
};
/// A global account data event.
@ -553,6 +554,19 @@ where
Self::Redacted(content) => content.event_type(),
}
}
/// Transform `self` into a redacted form (removing most or all fields) according to the spec.
///
/// If `self` is already [`Redacted`](Self::Redacted), return the inner data unmodified.
///
/// A small number of events have room-version specific redaction behavior, so a version has to
/// be specified.
pub fn redact(self, version: &RoomVersionId) -> C::Redacted {
match self {
FullStateEventContent::Original { content, .. } => content.redact(version),
FullStateEventContent::Redacted(content) => content,
}
}
}
macro_rules! impl_possibly_redacted_event {