diff --git a/src/content_enums.rs b/src/content_enums.rs index f7e5edd9..40766930 100644 --- a/src/content_enums.rs +++ b/src/content_enums.rs @@ -1,5 +1,17 @@ use ruma_events_macros::event_content_enum; +event_content_enum! { + /// A basic event. + name: AnyBasicEventContent, + events: [ + "m.direct", + "m.dummy", + "m.ignored_user_list", + "m.push_rules", + "m.room_key", + ] +} + event_content_enum! { /// Any message event's content. name: AnyMessageEventContent, @@ -40,9 +52,3 @@ event_content_enum! { name: AnyEphemeralRoomEventContent, events: [ "m.typing", "m.receipt" ] } - -event_content_enum! { - /// A basic event. - name: AnyBasicEventContent, - events: [ "m.ignored_user_list", "m.room_key" ] -} diff --git a/src/direct.rs b/src/direct.rs index a7104bb1..4c433a27 100644 --- a/src/direct.rs +++ b/src/direct.rs @@ -1,22 +1,36 @@ //! Types for the *m.direct* event. -use std::collections::BTreeMap; +use std::{ + collections::BTreeMap, + ops::{Deref, DerefMut}, +}; -use ruma_events_macros::ruma_event; +use ruma_events_macros::BasicEventContent; use ruma_identifiers::{RoomId, UserId}; +use serde::{Deserialize, Serialize}; -ruma_event! { - /// Informs the client about the rooms that are considered direct by a user. - DirectEvent { - kind: Event, - event_type: "m.direct", - content_type_alias: { - /// The payload for `DirectEvent`. - /// - /// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that - /// particular user. - BTreeMap> - }, +/// Informs the client about the rooms that are considered direct by a user. +pub type DirectEvent = crate::BasicEvent; + +/// The payload for `DirectEvent`. +/// +/// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that +/// particular user. +#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[ruma_event(type = "m.direct")] +pub struct DirectEventContent(pub BTreeMap>); + +impl Deref for DirectEventContent { + type Target = BTreeMap>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for DirectEventContent { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 } } @@ -32,7 +46,7 @@ mod tests { #[test] fn serialization() { - let mut content: DirectEventContent = BTreeMap::new(); + let mut content = DirectEventContent(BTreeMap::new()); let alice = UserId::new("ruma.io").unwrap(); let room = vec![RoomId::new("ruma.io").unwrap()]; diff --git a/src/dummy.rs b/src/dummy.rs index 8c7f514b..c2d70a1c 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -1,38 +1,55 @@ //! Types for the *m.dummy* event. -use ruma_events_macros::ruma_event; -use ruma_serde::empty::Empty; +use std::ops::{Deref, DerefMut}; -ruma_event! { - /// This event type is used to indicate new Olm sessions for end-to-end encryption. - /// - /// Typically it is encrypted as an *m.room.encrypted* event, then sent as a to-device event. - /// - /// The event does not have any content associated with it. The sending client is expected to - /// send a key share request shortly after this message, causing the receiving client to process - /// this *m.dummy* event as the most recent event and using the keyshare request to set up the - /// session. The keyshare request and *m.dummy* combination should result in the original - /// sending client receiving keys over the newly established session. - DummyEvent { - kind: Event, - event_type: "m.dummy", - content_type_alias: { - /// The payload for `DummyEvent`. - Empty - } +use ruma_events_macros::BasicEventContent; +use ruma_serde::empty::Empty; +use serde::{Deserialize, Serialize}; + +use crate::BasicEvent; + +/// This event type is used to indicate new Olm sessions for end-to-end encryption. +/// +/// Typically it is encrypted as an *m.room.encrypted* event, then sent as a to-device event. +/// +/// The event does not have any content associated with it. The sending client is expected to +/// send a key share request shortly after this message, causing the receiving client to process +/// this *m.dummy* event as the most recent event and using the keyshare request to set up the +/// session. The keyshare request and *m.dummy* combination should result in the original +/// sending client receiving keys over the newly established session. +pub type DummyEvent = BasicEvent; + +#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[ruma_event(type = "m.dummy")] +/// The payload for `DummyEvent`. +pub struct DummyEventContent(pub Empty); + +impl Deref for DummyEventContent { + type Target = Empty; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for DummyEventContent { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 } } #[cfg(test)] mod tests { - use super::{DummyEvent, Empty}; + use super::{DummyEvent, DummyEventContent, Empty}; use crate::EventJson; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; #[test] fn serialization() { - let dummy_event = DummyEvent { content: Empty }; + let dummy_event = DummyEvent { + content: DummyEventContent(Empty), + }; let actual = to_json_value(dummy_event).unwrap(); let expected = json!({ diff --git a/src/lib.rs b/src/lib.rs index 1469d909..d3bcf808 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,14 +145,14 @@ extern crate self as ruma_events; pub mod call; pub mod custom; -// pub mod direct; -// pub mod dummy; +pub mod direct; +pub mod dummy; pub mod forwarded_room_key; pub mod fully_read; pub mod ignored_user_list; pub mod key; pub mod presence; -// pub mod push_rules; +pub mod push_rules; pub mod receipt; pub mod room; pub mod room_key; diff --git a/src/push_rules.rs b/src/push_rules.rs index a7f6490c..85aa831c 100644 --- a/src/push_rules.rs +++ b/src/push_rules.rs @@ -1,18 +1,19 @@ //! Types for the the *m.push_rules* event. -use ruma_events_macros::ruma_event; +use ruma_events_macros::BasicEventContent; use serde::{Deserialize, Serialize}; -ruma_event! { - /// Describes all push rules for a user. - PushRulesEvent { - kind: Event, - event_type: "m.push_rules", - content: { - /// The global ruleset. - pub global: Ruleset, - }, - } +use crate::BasicEvent; + +/// Describes all push rules for a user. +pub type PushRulesEvent = BasicEvent; + +/// The payload for `PushRulesEvent`. +#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[ruma_event(type = "m.push_rules")] +pub struct PushRulesEventContent { + /// The global ruleset. + pub global: Ruleset, } pub use ruma_common::push::Action; @@ -153,7 +154,7 @@ mod tests { use matches::assert_matches; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; - use super::PushCondition; + use super::{PushCondition, PushRulesEvent}; use crate::EventJson; #[test]