From 283370ff2fd490cdfb5862ec0c44e00cd8a0fc5b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 7 Jun 2020 16:15:24 +0200 Subject: [PATCH] Add more event kinds --- src/event_kinds.rs | 24 +++++++++++++++++++++--- src/lib.rs | 6 ++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/event_kinds.rs b/src/event_kinds.rs index 93de3bfd..be0d71a5 100644 --- a/src/event_kinds.rs +++ b/src/event_kinds.rs @@ -11,7 +11,16 @@ use serde::{ Serialize, Serializer, }; -use crate::{MessageEventContent, RoomEventContent, StateEventContent, TryFromRaw, UnsignedData}; +use crate::{ + BasicEventContent, MessageEventContent, RoomEventContent, StateEventContent, + ToDeviceEventContent, TryFromRaw, UnsignedData, +}; + +/// A basic event – one that consists only of it's type and the `content` object. +#[derive(Clone, Debug, Event)] +pub struct BasicEvent { + pub content: C, +} /// Message event. #[derive(Clone, Debug, Event)] @@ -22,7 +31,7 @@ pub struct MessageEvent { /// The globally unique event identifier for the user who sent the event. pub event_id: EventId, - /// Contains the fully-qualified ID of the user who sent this event. + /// 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. @@ -44,7 +53,7 @@ pub struct StateEvent { /// The globally unique event identifier for the user who sent the event. pub event_id: EventId, - /// Contains the fully-qualified ID of the user who sent this event. + /// 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. @@ -65,3 +74,12 @@ pub struct StateEvent { /// Additional key-value pairs not signed by the homeserver. pub unsigned: UnsignedData, } + +#[derive(Clone, Debug, Event)] +pub struct ToDeviceEvent { + /// Data specific to the event type. + pub content: C, + + /// The fully-qualified ID of the user who sent this event. + pub sender: UserId, +} diff --git a/src/lib.rs b/src/lib.rs index 084cc750..5d3f4417 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -217,6 +217,9 @@ pub trait EventContent: Sized + Serialize { fn from_parts(event_type: &str, content: Box) -> Result; } +/// Marker trait for the content of a basic event. +pub trait BasicEventContent: EventContent {} + /// Marker trait for the content of a room event. pub trait RoomEventContent: EventContent {} @@ -225,3 +228,6 @@ pub trait MessageEventContent: RoomEventContent {} /// Marker trait for the content of a state event. pub trait StateEventContent: RoomEventContent {} + +/// Marker trait for event content types that are commonly sent using to-device messaging. +pub trait ToDeviceEventContent: EventContent {}