Declare a few state event content structs without the ruma_event! macro
This commit is contained in:
parent
ef6e2e7023
commit
eceef3b96d
@ -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: {
|
||||
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
|
||||
#[ruma_event(type = "m.room.aliases")]
|
||||
pub struct AliasesEventContent {
|
||||
/// A list of room aliases.
|
||||
pub aliases: Vec<RoomAliasId>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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,14 +10,12 @@ 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: {
|
||||
#[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<Box<ImageInfo>>,
|
||||
@ -24,6 +23,4 @@ ruma_event! {
|
||||
/// Information about the avatar thumbnail image.
|
||||
/// URL of the avatar image.
|
||||
pub url: String,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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: {
|
||||
#[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",
|
||||
default,
|
||||
deserialize_with = "ruma_serde::empty_string_as_none",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub alias: Option<RoomAliasId>,
|
||||
|
||||
/// List of alternative aliases to the room.
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Vec::is_empty"
|
||||
)]
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub alt_aliases: Vec<RoomAliasId>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -2,17 +2,15 @@
|
||||
|
||||
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: {
|
||||
#[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,
|
||||
|
||||
@ -31,8 +29,6 @@ ruma_event! {
|
||||
/// A reference to the room this room replaces, if the previous room was upgraded.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub predecessor: Option<PreviousRoom>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to an old room replaced during a room version upgrade.
|
||||
|
52
src/state.rs
52
src/state.rs
@ -456,20 +456,7 @@ mod tests {
|
||||
from_json_value::<StateEvent<AnyStateEventContent>>(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"
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user