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.
|
//! Types for the *m.room.aliases* event.
|
||||||
|
|
||||||
use ruma_events_macros::ruma_event;
|
use ruma_events_macros::{FromRaw, StateEventContent};
|
||||||
use ruma_identifiers::RoomAliasId;
|
use ruma_identifiers::RoomAliasId;
|
||||||
|
use serde::Serialize;
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -9,14 +10,10 @@ use crate::{
|
|||||||
EventContent, EventJson, RoomEventContent, StateEventContent,
|
EventContent, EventJson, RoomEventContent, StateEventContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
ruma_event! {
|
/// Informs the room about what room aliases it has been given.
|
||||||
/// Informs the room about what room aliases it has been given.
|
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
|
||||||
AliasesEvent {
|
#[ruma_event(type = "m.room.aliases")]
|
||||||
kind: StateEvent,
|
pub struct AliasesEventContent {
|
||||||
event_type: "m.room.aliases",
|
|
||||||
content: {
|
|
||||||
/// A list of room aliases.
|
/// A list of room aliases.
|
||||||
pub aliases: Vec<RoomAliasId>,
|
pub aliases: Vec<RoomAliasId>,
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Types for the *m.room.avatar* event.
|
//! 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 serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use super::ImageInfo;
|
use super::ImageInfo;
|
||||||
@ -9,14 +10,12 @@ use crate::{
|
|||||||
EventContent, EventJson, RoomEventContent, StateEventContent,
|
EventContent, EventJson, RoomEventContent, StateEventContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
ruma_event! {
|
/// A picture that is associated with the room.
|
||||||
/// A picture that is associated with the room.
|
///
|
||||||
///
|
/// This can be displayed alongside the room information.
|
||||||
/// This can be displayed alongside the room information.
|
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
|
||||||
AvatarEvent {
|
#[ruma_event(type = "m.room.avatar")]
|
||||||
kind: StateEvent,
|
pub struct AvatarEventContent {
|
||||||
event_type: "m.room.avatar",
|
|
||||||
content: {
|
|
||||||
/// Information about the avatar image.
|
/// Information about the avatar image.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<Box<ImageInfo>>,
|
pub info: Option<Box<ImageInfo>>,
|
||||||
@ -24,6 +23,4 @@ ruma_event! {
|
|||||||
/// Information about the avatar thumbnail image.
|
/// Information about the avatar thumbnail image.
|
||||||
/// URL of the avatar image.
|
/// URL of the avatar image.
|
||||||
pub url: String,
|
pub url: String,
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,27 @@
|
|||||||
//! Types for the *m.room.canonical_alias* event.
|
//! 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 ruma_identifiers::RoomAliasId;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
ruma_event! {
|
/// Informs the room as to which alias is the canonical one.
|
||||||
/// Informs the room as to which alias is the canonical one.
|
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
|
||||||
CanonicalAliasEvent {
|
#[ruma_event(type = "m.room.canonical_alias")]
|
||||||
kind: StateEvent,
|
pub struct CanonicalAliasEventContent {
|
||||||
event_type: "m.room.canonical_alias",
|
|
||||||
content: {
|
|
||||||
/// The canonical alias.
|
/// The canonical alias.
|
||||||
///
|
///
|
||||||
/// Rooms with `alias: None` should be treated the same as a room
|
/// Rooms with `alias: None` should be treated the same as a room
|
||||||
/// with no canonical alias.
|
/// with no canonical alias.
|
||||||
#[serde(
|
#[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"
|
skip_serializing_if = "Option::is_none"
|
||||||
)]
|
)]
|
||||||
pub alias: Option<RoomAliasId>,
|
pub alias: Option<RoomAliasId>,
|
||||||
|
|
||||||
/// List of alternative aliases to the room.
|
/// List of alternative aliases to the room.
|
||||||
#[serde(
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
default,
|
|
||||||
skip_serializing_if = "Vec::is_empty"
|
|
||||||
)]
|
|
||||||
pub alt_aliases: Vec<RoomAliasId>,
|
pub alt_aliases: Vec<RoomAliasId>,
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -2,17 +2,15 @@
|
|||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use ruma_events_macros::ruma_event;
|
use ruma_events_macros::{FromRaw, StateEventContent};
|
||||||
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
|
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
|
||||||
use serde::{Deserialize, Serialize};
|
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
|
||||||
/// This is the first event in a room and cannot be changed. It acts as the root of all other
|
/// events.
|
||||||
/// events.
|
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
|
||||||
CreateEvent {
|
#[ruma_event(type = "m.room.create")]
|
||||||
kind: StateEvent,
|
pub struct CreateEventContent {
|
||||||
event_type: "m.room.create",
|
|
||||||
content: {
|
|
||||||
/// The `user_id` of the room creator. This is set by the homeserver.
|
/// The `user_id` of the room creator. This is set by the homeserver.
|
||||||
pub creator: UserId,
|
pub creator: UserId,
|
||||||
|
|
||||||
@ -31,8 +29,6 @@ ruma_event! {
|
|||||||
/// A reference to the room this room replaces, if the previous room was upgraded.
|
/// A reference to the room this room replaces, if the previous room was upgraded.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub predecessor: Option<PreviousRoom>,
|
pub predecessor: Option<PreviousRoom>,
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A reference to an old room replaced during a room version upgrade.
|
/// 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(),
|
from_json_value::<StateEvent<AnyStateEventContent>>(json_data).unwrap(),
|
||||||
StateEvent {
|
StateEvent {
|
||||||
content: AnyStateEventContent::RoomAvatar(AvatarEventContent {
|
content: AnyStateEventContent::RoomAvatar(AvatarEventContent {
|
||||||
info: Some(ImageInfo {
|
info: Some(info),
|
||||||
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,
|
|
||||||
}),
|
|
||||||
url,
|
url,
|
||||||
}),
|
}),
|
||||||
event_id,
|
event_id,
|
||||||
@ -483,15 +470,34 @@ mod tests {
|
|||||||
&& room_id == RoomId::try_from("!roomid:room.com").unwrap()
|
&& room_id == RoomId::try_from("!roomid:room.com").unwrap()
|
||||||
&& sender == UserId::try_from("@carl:example.com").unwrap()
|
&& sender == UserId::try_from("@carl:example.com").unwrap()
|
||||||
&& state_key == ""
|
&& state_key == ""
|
||||||
&& height == UInt::new(423)
|
&& matches!(
|
||||||
&& width == UInt::new(1011)
|
info.as_ref(),
|
||||||
&& mimetype == "image/png"
|
ImageInfo {
|
||||||
&& size == UInt::new(84242)
|
height,
|
||||||
&& thumb_width == UInt::new(800)
|
width,
|
||||||
&& thumb_height == UInt::new(334)
|
mimetype: Some(mimetype),
|
||||||
&& thumb_mimetype == Some("image/png".to_string())
|
size,
|
||||||
&& thumb_size == UInt::new(82595)
|
thumbnail_info: Some(thumbnail_info),
|
||||||
&& thumbnail_url == "mxc://matrix.org"
|
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"
|
&& url == "http://www.matrix.org"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user