events: Introduce Redact trait
This commit is contained in:
parent
c07c3fa6d5
commit
702b619417
@ -486,9 +486,10 @@ fn expand_redact(
|
|||||||
|
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
impl #ident {
|
impl #ruma_events::Redact for #ident {
|
||||||
/// Redacts `Self` given a valid `Redaction[Sync]Event`.
|
type Redacted = #redacted_enum;
|
||||||
pub fn redact(
|
|
||||||
|
fn redact(
|
||||||
self,
|
self,
|
||||||
redaction: #ruma_events::room::redaction::SyncRedactionEvent,
|
redaction: #ruma_events::room::redaction::SyncRedactionEvent,
|
||||||
version: &#ruma_identifiers::RoomVersionId,
|
version: &#ruma_identifiers::RoomVersionId,
|
||||||
|
@ -4,7 +4,7 @@ use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
|
|||||||
use serde::{de, Serialize};
|
use serde::{de, Serialize};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
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! {
|
event_enum! {
|
||||||
/// Any global account data event.
|
/// 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>;
|
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.
|
/// Trait to define the behavior of redact an event's content object.
|
||||||
pub trait RedactContent {
|
pub trait RedactContent {
|
||||||
/// The redacted form of the event's content.
|
/// The redacted form of the event's content.
|
||||||
|
@ -10,7 +10,7 @@ use ruma_events::{
|
|||||||
redaction::{RedactionEventContent, SyncRedactionEvent},
|
redaction::{RedactionEventContent, SyncRedactionEvent},
|
||||||
},
|
},
|
||||||
AnyMessageEvent, AnyRedactedMessageEvent, AnyRedactedSyncMessageEvent,
|
AnyMessageEvent, AnyRedactedMessageEvent, AnyRedactedSyncMessageEvent,
|
||||||
AnyRedactedSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent, RedactedMessageEvent,
|
AnyRedactedSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent, Redact, RedactedMessageEvent,
|
||||||
RedactedSyncMessageEvent, RedactedSyncStateEvent, RedactedUnsigned, Unsigned,
|
RedactedSyncMessageEvent, RedactedSyncStateEvent, RedactedUnsigned, Unsigned,
|
||||||
};
|
};
|
||||||
use ruma_identifiers::{event_id, room_id, user_id, RoomVersionId};
|
use ruma_identifiers::{event_id, room_id, user_id, RoomVersionId};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user