Add RedactionEventStub, event enums

This commit is contained in:
Jonas Platte 2020-06-10 21:04:03 +02:00
parent 2a91dc1eb7
commit bc5b7aa3e2
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 100 additions and 2 deletions

View File

@ -1,4 +1,14 @@
use ruma_events_macros::event_content_enum;
use serde::{Deserialize, Serialize};
use crate::{
event_kinds::{
BasicEvent, EphemeralRoomEvent, MessageEvent, MessageEventStub, StateEvent, StateEventStub,
StrippedStateEventStub,
},
presence::PresenceEvent,
room::redaction::{RedactionEvent, RedactionEventStub},
};
event_content_enum! {
/// Any basic event.
@ -78,3 +88,67 @@ event_content_enum! {
"m.room.encrypted",
]
}
/// Any basic event, one that has no (well-known) fields outside of `content`.
pub type AnyBasicEvent = BasicEvent<AnyBasicEventContent>;
/// Any ephemeral room event.
pub type AnyEphemeralRoomEvent = EphemeralRoomEvent<AnyEphemeralRoomEventContent>;
/// Any message event.
pub type AnyMessageEvent = MessageEvent<AnyMessageEventContent>;
/// Any message event stub (message event without a `room_id`, as returned in `/sync` responses)
pub type AnyMessageEventStub = MessageEventStub<AnyMessageEventContent>;
/// Any state event.
pub type AnyStateEvent = StateEvent<AnyStateEventContent>;
/// Any state event stub (state event without a `room_id`, as returned in `/sync` responses)
pub type AnyStateEventStub = StateEventStub<AnyStateEventContent>;
/// Any stripped state event stub (stripped-down state event, as returned for rooms the user has
/// been invited to in `/sync` responses)
pub type AnyStrippedStateEventStub = StrippedStateEventStub<AnyStateEventContent>;
/// Any event.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum AnyEvent {
/// Any basic event.
Basic(AnyBasicEvent),
/// `"m.presence"`, the only non-room event with a `sender` field.
Presence(PresenceEvent),
/// Any ephemeral room event.
Ephemeral(AnyEphemeralRoomEvent),
/// Any message event.
Message(AnyMessageEvent),
/// `"m.room.redaction"`, the only room event with a `redacts` field.
Redaction(RedactionEvent),
/// Any state event.
State(AnyStateEvent),
}
/// Any room event.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum AnyRoomEvent {
/// Any message event.
Message(AnyMessageEvent),
/// `"m.room.redaction"`, the only room event with a `redacts` field.
Redaction(RedactionEvent),
/// Any state event.
State(AnyStateEvent),
}
/// Any room event stub (room event without a `room_id`, as returned in `/sync` responses)
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum AnyRoomEventStub {
/// Any message event stub
Message(AnyMessageEventStub),
/// `"m.room.redaction"` stub
Redaction(RedactionEventStub),
/// Any state event stub
StateEvent(AnyStateEventStub),
}

View File

@ -160,8 +160,10 @@ pub use self::{
algorithm::Algorithm,
custom::{CustomBasicEvent, CustomMessageEvent, CustomStateEvent},
enums::{
AnyBasicEventContent, AnyEphemeralRoomEventContent, AnyMessageEventContent,
AnyStateEventContent, AnyToDeviceEventContent,
AnyBasicEvent, AnyBasicEventContent, AnyEphemeralRoomEvent, AnyEphemeralRoomEventContent,
AnyEvent, AnyMessageEvent, AnyMessageEventContent, AnyMessageEventStub, AnyRoomEvent,
AnyRoomEventStub, AnyStateEvent, AnyStateEventContent, AnyStateEventStub,
AnyStrippedStateEventStub, AnyToDeviceEventContent,
},
error::{FromStrError, InvalidEvent, InvalidInput},
event_kinds::{

View File

@ -33,6 +33,28 @@ pub struct RedactionEvent {
pub unsigned: UnsignedData,
}
/// Redaction event without a `room_id`.
#[derive(Clone, Debug, Event)]
pub struct RedactionEventStub {
/// Data specific to the event type.
pub content: RedactionEventContent,
/// The ID of the event that was redacted.
pub redacts: 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: SystemTime,
/// Additional key-value pairs not signed by the homeserver.
pub unsigned: UnsignedData,
}
/// A redaction of an event.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.room.redaction")]