events: Add redacted redaction event types
This commit is contained in:
parent
3ee4ac08fb
commit
c807f9f43d
@ -408,6 +408,10 @@ fn expand_redact_event(
|
|||||||
let ident = &input.ident;
|
let ident = &input.ident;
|
||||||
|
|
||||||
let mut generics = input.generics.clone();
|
let mut generics = input.generics.clone();
|
||||||
|
if generics.params.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!(generics.params.len(), 1, "expected one generic parameter");
|
assert_eq!(generics.params.len(), 1, "expected one generic parameter");
|
||||||
let ty_param = match &generics.params[0] {
|
let ty_param = match &generics.params[0] {
|
||||||
GenericParam::Type(ty) => ty.ident.clone(),
|
GenericParam::Type(ty) => ty.ident.clone(),
|
||||||
@ -477,7 +481,7 @@ fn expand_from_into(
|
|||||||
let fields: Vec<_> = fields.iter().flat_map(|f| &f.ident).collect();
|
let fields: Vec<_> = fields.iter().flat_map(|f| &f.ident).collect();
|
||||||
|
|
||||||
if let EventKindVariation::Sync | EventKindVariation::RedactedSync = var {
|
if let EventKindVariation::Sync | EventKindVariation::RedactedSync = var {
|
||||||
let full_struct = kind.to_event_ident(&var.to_full().unwrap());
|
let full_struct = kind.to_event_ident(&var.to_full().unwrap()).unwrap();
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
impl #impl_generics ::std::convert::From<#full_struct #ty_gen>
|
impl #impl_generics ::std::convert::From<#full_struct #ty_gen>
|
||||||
|
@ -727,23 +727,6 @@ fn to_event_path(
|
|||||||
// There is no need to give a good compiler error as `to_camel_case` is called first.
|
// There is no need to give a good compiler error as `to_camel_case` is called first.
|
||||||
assert_eq!(&name[..2], "m.");
|
assert_eq!(&name[..2], "m.");
|
||||||
|
|
||||||
// Temporary hack
|
|
||||||
if *kind == EventKind::Message && name == "m.room.redaction" {
|
|
||||||
if *var == EventKindVariation::Redacted {
|
|
||||||
return quote! {
|
|
||||||
#ruma_events::RedactedMessageEvent<
|
|
||||||
#ruma_events::room::redaction::RedactedRedactionEventContent
|
|
||||||
>
|
|
||||||
};
|
|
||||||
} else if *var == EventKindVariation::RedactedSync {
|
|
||||||
return quote! {
|
|
||||||
#ruma_events::RedactedSyncMessageEvent<
|
|
||||||
#ruma_events::room::redaction::RedactedRedactionEventContent
|
|
||||||
>
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let path: Vec<_> = name[2..].split('.').collect();
|
let path: Vec<_> = name[2..].split('.').collect();
|
||||||
|
|
||||||
let event_str = path.last().unwrap();
|
let event_str = path.last().unwrap();
|
||||||
|
@ -133,8 +133,10 @@ impl EventKind {
|
|||||||
| (Self::State, V::Stripped)
|
| (Self::State, V::Stripped)
|
||||||
| (Self::State, V::Initial)
|
| (Self::State, V::Initial)
|
||||||
| (Self::Message, V::Redacted)
|
| (Self::Message, V::Redacted)
|
||||||
|
| (Self::Redaction, V::Redacted)
|
||||||
| (Self::State, V::Redacted)
|
| (Self::State, V::Redacted)
|
||||||
| (Self::Message, V::RedactedSync)
|
| (Self::Message, V::RedactedSync)
|
||||||
|
| (Self::Redaction, V::RedactedSync)
|
||||||
| (Self::State, V::RedactedSync) => Some(format_ident!("{}{}", var, self)),
|
| (Self::State, V::RedactedSync) => Some(format_ident!("{}{}", var, self)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@ -203,6 +205,10 @@ pub fn to_kind_variation(ident: &Ident) -> Option<(EventKind, EventKindVariation
|
|||||||
"PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)),
|
"PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)),
|
||||||
"RedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Full)),
|
"RedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Full)),
|
||||||
"SyncRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Sync)),
|
"SyncRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Sync)),
|
||||||
|
"RedactedRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Redacted)),
|
||||||
|
"RedactedSyncRedactionEvent" => {
|
||||||
|
Some((EventKind::Redaction, EventKindVariation::RedactedSync))
|
||||||
|
}
|
||||||
"DecryptedOlmV1Event" | "DecryptedMegolmV1Event" => {
|
"DecryptedOlmV1Event" | "DecryptedMegolmV1Event" => {
|
||||||
Some((EventKind::Decrypted, EventKindVariation::Full))
|
Some((EventKind::Decrypted, EventKindVariation::Full))
|
||||||
}
|
}
|
||||||
|
@ -34,16 +34,17 @@ pub struct RedactionEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Redact for RedactionEvent {
|
impl Redact for RedactionEvent {
|
||||||
// Temporary hack
|
type Redacted = RedactedRedactionEvent;
|
||||||
type Redacted = crate::RedactedMessageEvent<RedactedRedactionEventContent>;
|
|
||||||
|
|
||||||
fn redact(
|
fn redact(
|
||||||
self,
|
self,
|
||||||
redaction: SyncRedactionEvent,
|
redaction: SyncRedactionEvent,
|
||||||
version: &ruma_identifiers::RoomVersionId,
|
version: &ruma_identifiers::RoomVersionId,
|
||||||
) -> Self::Redacted {
|
) -> Self::Redacted {
|
||||||
crate::RedactedMessageEvent {
|
RedactedRedactionEvent {
|
||||||
content: self.content.redact(version),
|
content: self.content.redact(version),
|
||||||
|
// There is no released room version where this isn't redacted yet
|
||||||
|
redacts: None,
|
||||||
event_id: self.event_id,
|
event_id: self.event_id,
|
||||||
sender: self.sender,
|
sender: self.sender,
|
||||||
origin_server_ts: self.origin_server_ts,
|
origin_server_ts: self.origin_server_ts,
|
||||||
@ -53,6 +54,32 @@ impl Redact for RedactionEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Redacted redaction event.
|
||||||
|
#[derive(Clone, Debug, Event)]
|
||||||
|
#[allow(clippy::exhaustive_structs)]
|
||||||
|
pub struct RedactedRedactionEvent {
|
||||||
|
/// Data specific to the event type.
|
||||||
|
pub content: RedactedRedactionEventContent,
|
||||||
|
|
||||||
|
/// The ID of the event that was redacted.
|
||||||
|
pub redacts: Option<EventId>,
|
||||||
|
|
||||||
|
/// The globally unique event identifier for the user who sent the event.
|
||||||
|
pub event_id: EventId,
|
||||||
|
|
||||||
|
/// The fully-qualified ID of the user who sent this event.
|
||||||
|
pub sender: UserId,
|
||||||
|
|
||||||
|
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||||
|
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||||
|
|
||||||
|
/// The ID of the room associated with this event.
|
||||||
|
pub room_id: RoomId,
|
||||||
|
|
||||||
|
/// Additional key-value pairs not signed by the homeserver.
|
||||||
|
pub unsigned: RedactedUnsigned,
|
||||||
|
}
|
||||||
|
|
||||||
/// Redaction event without a `room_id`.
|
/// Redaction event without a `room_id`.
|
||||||
#[derive(Clone, Debug, Event)]
|
#[derive(Clone, Debug, Event)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
@ -77,16 +104,17 @@ pub struct SyncRedactionEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Redact for SyncRedactionEvent {
|
impl Redact for SyncRedactionEvent {
|
||||||
// Temporary hack
|
type Redacted = RedactedSyncRedactionEvent;
|
||||||
type Redacted = crate::RedactedSyncMessageEvent<RedactedRedactionEventContent>;
|
|
||||||
|
|
||||||
fn redact(
|
fn redact(
|
||||||
self,
|
self,
|
||||||
redaction: SyncRedactionEvent,
|
redaction: SyncRedactionEvent,
|
||||||
version: &ruma_identifiers::RoomVersionId,
|
version: &ruma_identifiers::RoomVersionId,
|
||||||
) -> Self::Redacted {
|
) -> Self::Redacted {
|
||||||
crate::RedactedSyncMessageEvent {
|
RedactedSyncRedactionEvent {
|
||||||
content: self.content.redact(version),
|
content: self.content.redact(version),
|
||||||
|
// There is no released room version where this isn't redacted yet
|
||||||
|
redacts: None,
|
||||||
event_id: self.event_id,
|
event_id: self.event_id,
|
||||||
sender: self.sender,
|
sender: self.sender,
|
||||||
origin_server_ts: self.origin_server_ts,
|
origin_server_ts: self.origin_server_ts,
|
||||||
@ -95,6 +123,29 @@ impl Redact for SyncRedactionEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Redacted redaction event without a `room_id`.
|
||||||
|
#[derive(Clone, Debug, Event)]
|
||||||
|
#[allow(clippy::exhaustive_structs)]
|
||||||
|
pub struct RedactedSyncRedactionEvent {
|
||||||
|
/// Data specific to the event type.
|
||||||
|
pub content: RedactedRedactionEventContent,
|
||||||
|
|
||||||
|
/// The ID of the event that was redacted.
|
||||||
|
pub redacts: Option<EventId>,
|
||||||
|
|
||||||
|
/// The globally unique event identifier for the user who sent the event.
|
||||||
|
pub event_id: EventId,
|
||||||
|
|
||||||
|
/// The fully-qualified ID of the user who sent this event.
|
||||||
|
pub sender: UserId,
|
||||||
|
|
||||||
|
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||||
|
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||||
|
|
||||||
|
/// Additional key-value pairs not signed by the homeserver.
|
||||||
|
pub unsigned: RedactedUnsigned,
|
||||||
|
}
|
||||||
|
|
||||||
/// A redaction of an event.
|
/// A redaction of an event.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user