diff --git a/src/room/aliases.rs b/src/room/aliases.rs index e4eca6c4..3762dc29 100644 --- a/src/room/aliases.rs +++ b/src/room/aliases.rs @@ -1,7 +1,8 @@ //! Types for the *m.room.aliases* event. -use ruma_events_macros::ruma_event; +use ruma_events_macros::{FromRaw, StateEventContent}; use ruma_identifiers::RoomAliasId; +use serde::Serialize; use serde_json::value::RawValue as RawJsonValue; use crate::{ @@ -9,14 +10,10 @@ use crate::{ EventContent, EventJson, RoomEventContent, StateEventContent, }; -ruma_event! { - /// Informs the room about what room aliases it has been given. - AliasesEvent { - kind: StateEvent, - event_type: "m.room.aliases", - content: { - /// A list of room aliases. - pub aliases: Vec, - }, - } +/// Informs the room about what room aliases it has been given. +#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)] +#[ruma_event(type = "m.room.aliases")] +pub struct AliasesEventContent { + /// A list of room aliases. + pub aliases: Vec, } diff --git a/src/room/avatar.rs b/src/room/avatar.rs index 50227143..ca87cca8 100644 --- a/src/room/avatar.rs +++ b/src/room/avatar.rs @@ -1,6 +1,7 @@ //! Types for the *m.room.avatar* event. -use ruma_events_macros::ruma_event; +use ruma_events_macros::{FromRaw, StateEventContent}; +use serde::Serialize; use serde_json::value::RawValue as RawJsonValue; use super::ImageInfo; @@ -9,21 +10,17 @@ use crate::{ EventContent, EventJson, RoomEventContent, StateEventContent, }; -ruma_event! { - /// A picture that is associated with the room. - /// - /// This can be displayed alongside the room information. - AvatarEvent { - kind: StateEvent, - event_type: "m.room.avatar", - content: { - /// Information about the avatar image. - #[serde(skip_serializing_if = "Option::is_none")] - pub info: Option>, +/// A picture that is associated with the room. +/// +/// This can be displayed alongside the room information. +#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)] +#[ruma_event(type = "m.room.avatar")] +pub struct AvatarEventContent { + /// Information about the avatar image. + #[serde(skip_serializing_if = "Option::is_none")] + pub info: Option>, - /// Information about the avatar thumbnail image. - /// URL of the avatar image. - pub url: String, - }, - } + /// Information about the avatar thumbnail image. + /// URL of the avatar image. + pub url: String, } diff --git a/src/room/canonical_alias.rs b/src/room/canonical_alias.rs index 3c5d73c5..59c7f51f 100644 --- a/src/room/canonical_alias.rs +++ b/src/room/canonical_alias.rs @@ -1,31 +1,27 @@ //! Types for the *m.room.canonical_alias* event. -use ruma_events_macros::ruma_event; +use ruma_events_macros::{FromRaw, StateEventContent}; use ruma_identifiers::RoomAliasId; +use serde::Serialize; -ruma_event! { - /// Informs the room as to which alias is the canonical one. - CanonicalAliasEvent { - kind: StateEvent, - event_type: "m.room.canonical_alias", - content: { - /// The canonical alias. - /// - /// Rooms with `alias: None` should be treated the same as a room - /// with no canonical alias. - #[serde( - default, deserialize_with = "ruma_serde::empty_string_as_none", - skip_serializing_if = "Option::is_none" - )] - pub alias: Option, - /// List of alternative aliases to the room. - #[serde( - default, - skip_serializing_if = "Vec::is_empty" - )] - pub alt_aliases: Vec, - }, - } +/// Informs the room as to which alias is the canonical one. +#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)] +#[ruma_event(type = "m.room.canonical_alias")] +pub struct CanonicalAliasEventContent { + /// The canonical alias. + /// + /// Rooms with `alias: None` should be treated the same as a room + /// with no canonical alias. + #[serde( + default, + deserialize_with = "ruma_serde::empty_string_as_none", + skip_serializing_if = "Option::is_none" + )] + pub alias: Option, + + /// List of alternative aliases to the room. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub alt_aliases: Vec, } #[cfg(test)] diff --git a/src/room/create.rs b/src/room/create.rs index 2abff616..fcdcea99 100644 --- a/src/room/create.rs +++ b/src/room/create.rs @@ -2,37 +2,33 @@ use std::convert::TryFrom; -use ruma_events_macros::ruma_event; +use ruma_events_macros::{FromRaw, StateEventContent}; use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId}; use serde::{Deserialize, Serialize}; -ruma_event! { - /// This is the first event in a room and cannot be changed. It acts as the root of all other - /// events. - CreateEvent { - kind: StateEvent, - event_type: "m.room.create", - content: { - /// The `user_id` of the room creator. This is set by the homeserver. - pub creator: UserId, +/// This is the first event in a room and cannot be changed. It acts as the root of all other +/// events. +#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)] +#[ruma_event(type = "m.room.create")] +pub struct CreateEventContent { + /// The `user_id` of the room creator. This is set by the homeserver. + pub creator: UserId, - /// Whether or not this room's data should be transferred to other homeservers. - #[serde( - rename = "m.federate", - default = "ruma_serde::default_true", - skip_serializing_if = "ruma_serde::is_true" - )] - pub federate: bool, + /// Whether or not this room's data should be transferred to other homeservers. + #[serde( + rename = "m.federate", + default = "ruma_serde::default_true", + skip_serializing_if = "ruma_serde::is_true" + )] + pub federate: bool, - /// The version of the room. Defaults to "1" if the key does not exist. - #[serde(default = "default_room_version_id")] - pub room_version: RoomVersionId, + /// The version of the room. Defaults to "1" if the key does not exist. + #[serde(default = "default_room_version_id")] + pub room_version: RoomVersionId, - /// A reference to the room this room replaces, if the previous room was upgraded. - #[serde(skip_serializing_if = "Option::is_none")] - pub predecessor: Option, - }, - } + /// A reference to the room this room replaces, if the previous room was upgraded. + #[serde(skip_serializing_if = "Option::is_none")] + pub predecessor: Option, } /// A reference to an old room replaced during a room version upgrade. diff --git a/src/state.rs b/src/state.rs index 48ae9011..e42a973a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -456,20 +456,7 @@ mod tests { from_json_value::>(json_data).unwrap(), StateEvent { content: AnyStateEventContent::RoomAvatar(AvatarEventContent { - info: Some(ImageInfo { - height, - width, - mimetype: Some(mimetype), - size, - thumbnail_info: Some(ThumbnailInfo { - width: thumb_width, - height: thumb_height, - mimetype: thumb_mimetype, - size: thumb_size, - }), - thumbnail_url: Some(thumbnail_url), - thumbnail_file: None, - }), + info: Some(info), url, }), event_id, @@ -483,15 +470,34 @@ mod tests { && room_id == RoomId::try_from("!roomid:room.com").unwrap() && sender == UserId::try_from("@carl:example.com").unwrap() && state_key == "" - && height == UInt::new(423) - && width == UInt::new(1011) - && mimetype == "image/png" - && size == UInt::new(84242) - && thumb_width == UInt::new(800) - && thumb_height == UInt::new(334) - && thumb_mimetype == Some("image/png".to_string()) - && thumb_size == UInt::new(82595) - && thumbnail_url == "mxc://matrix.org" + && matches!( + info.as_ref(), + ImageInfo { + height, + width, + mimetype: Some(mimetype), + size, + thumbnail_info: Some(thumbnail_info), + thumbnail_url: Some(thumbnail_url), + thumbnail_file: None, + } if *height == UInt::new(423) + && *width == UInt::new(1011) + && *mimetype == "image/png" + && *size == UInt::new(84242) + && matches!( + thumbnail_info.as_ref(), + ThumbnailInfo { + width: thumb_width, + height: thumb_height, + mimetype: thumb_mimetype, + size: thumb_size, + } if *thumb_width == UInt::new(800) + && *thumb_height == UInt::new(334) + && *thumb_mimetype == Some("image/png".to_string()) + && *thumb_size == UInt::new(82595) + && *thumbnail_url == "mxc://matrix.org" + ) + ) && url == "http://www.matrix.org" ); }