events: Introduce Redact trait
This commit is contained in:
parent
c07c3fa6d5
commit
702b619417
@ -486,9 +486,10 @@ fn expand_redact(
|
||||
|
||||
Some(quote! {
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
/// Redacts `Self` given a valid `Redaction[Sync]Event`.
|
||||
pub fn redact(
|
||||
impl #ruma_events::Redact for #ident {
|
||||
type Redacted = #redacted_enum;
|
||||
|
||||
fn redact(
|
||||
self,
|
||||
redaction: #ruma_events::room::redaction::SyncRedactionEvent,
|
||||
version: &#ruma_identifiers::RoomVersionId,
|
||||
|
@ -4,7 +4,7 @@ use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
|
||||
use serde::{de, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use crate::{from_raw_json_value, room::redaction::SyncRedactionEvent, EventDeHelper};
|
||||
use crate::{from_raw_json_value, room::redaction::SyncRedactionEvent, EventDeHelper, Redact};
|
||||
|
||||
event_enum! {
|
||||
/// Any global account data event.
|
||||
|
@ -275,6 +275,18 @@ pub trait EventContent: Sized + Serialize {
|
||||
fn from_parts(event_type: &str, content: Box<RawJsonValue>) -> Result<Self, serde_json::Error>;
|
||||
}
|
||||
|
||||
/// Trait to define the behavior of redacting an event.
|
||||
pub trait Redact {
|
||||
/// The redacted form of the event.
|
||||
type Redacted;
|
||||
|
||||
/// Transforms `self` into a redacted form (removing most fields) according to the spec.
|
||||
///
|
||||
/// A small number of events have room-version specific redaction behavior, so a version has to
|
||||
/// be specified.
|
||||
fn redact(self, redaction: SyncRedactionEvent, version: &RoomVersionId) -> Self::Redacted;
|
||||
}
|
||||
|
||||
/// Trait to define the behavior of redact an event's content object.
|
||||
pub trait RedactContent {
|
||||
/// The redacted form of the event's content.
|
||||
|
@ -10,7 +10,7 @@ use ruma_events::{
|
||||
redaction::{RedactionEventContent, SyncRedactionEvent},
|
||||
},
|
||||
AnyMessageEvent, AnyRedactedMessageEvent, AnyRedactedSyncMessageEvent,
|
||||
AnyRedactedSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent, RedactedMessageEvent,
|
||||
AnyRedactedSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent, Redact, RedactedMessageEvent,
|
||||
RedactedSyncMessageEvent, RedactedSyncStateEvent, RedactedUnsigned, Unsigned,
|
||||
};
|
||||
use ruma_identifiers::{event_id, room_id, user_id, RoomVersionId};
|
||||
|
Loading…
x
Reference in New Issue
Block a user