events: Make ImageInfo and ThumbnailInfo non-exhaustive
This commit is contained in:
parent
dc57620ae0
commit
486c9245b3
@ -30,7 +30,8 @@ pub mod tombstone;
|
||||
pub mod topic;
|
||||
|
||||
/// Metadata about an image.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct ImageInfo {
|
||||
/// The height of the image in pixels.
|
||||
#[serde(rename = "h", skip_serializing_if = "Option::is_none")]
|
||||
@ -71,8 +72,16 @@ pub struct ImageInfo {
|
||||
pub blurhash: Option<String>,
|
||||
}
|
||||
|
||||
impl ImageInfo {
|
||||
/// Creates an empty `ImageInfo`.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Metadata about a thumbnail.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct ThumbnailInfo {
|
||||
/// The height of the thumbnail in pixels.
|
||||
#[serde(rename = "h", skip_serializing_if = "Option::is_none")]
|
||||
@ -91,6 +100,13 @@ pub struct ThumbnailInfo {
|
||||
pub size: Option<UInt>,
|
||||
}
|
||||
|
||||
impl ThumbnailInfo {
|
||||
/// Creates an empty `ThumbnailInfo`.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// A file sent to a room with end-to-end encryption enabled.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct EncryptedFile {
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
use assign::assign;
|
||||
use js_int::UInt;
|
||||
use matches::assert_matches;
|
||||
use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
|
||||
@ -71,22 +72,19 @@ fn serialize_message_event() {
|
||||
let aliases_event = AnyMessageEvent::Sticker(MessageEvent {
|
||||
content: StickerEventContent::new(
|
||||
"Hello".into(),
|
||||
ImageInfo {
|
||||
assign!(ImageInfo::new(), {
|
||||
height: UInt::new(423),
|
||||
width: UInt::new(1011),
|
||||
mimetype: Some("image/png".into()),
|
||||
size: UInt::new(84242),
|
||||
thumbnail_info: Some(Box::new(ThumbnailInfo {
|
||||
thumbnail_info: Some(Box::new(assign!(ThumbnailInfo::new(), {
|
||||
width: UInt::new(800),
|
||||
height: UInt::new(334),
|
||||
mimetype: Some("image/png".into()),
|
||||
size: UInt::new(82595),
|
||||
})),
|
||||
}))),
|
||||
thumbnail_url: Some(mxc_uri!("mxc://matrix.org/mnrsnsRRS787TSts")),
|
||||
thumbnail_file: None,
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
blurhash: None,
|
||||
},
|
||||
}),
|
||||
mxc_uri!("mxc://matrix.org/arsrns98rsRSR"),
|
||||
),
|
||||
event_id: event_id!("$h29iv0s8:example.com"),
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
use assign::assign;
|
||||
use js_int::{uint, UInt};
|
||||
use matches::assert_matches;
|
||||
use ruma_events::{
|
||||
@ -17,22 +18,19 @@ fn message_serialize_sticker() {
|
||||
let aliases_event = MessageEvent {
|
||||
content: AnyMessageEventContent::Sticker(StickerEventContent::new(
|
||||
"Hello".into(),
|
||||
ImageInfo {
|
||||
assign!(ImageInfo::new(), {
|
||||
height: UInt::new(423),
|
||||
width: UInt::new(1011),
|
||||
mimetype: Some("image/png".into()),
|
||||
size: UInt::new(84242),
|
||||
thumbnail_info: Some(Box::new(ThumbnailInfo {
|
||||
thumbnail_info: Some(Box::new(assign!(ThumbnailInfo::new(), {
|
||||
width: UInt::new(800),
|
||||
height: UInt::new(334),
|
||||
mimetype: Some("image/png".into()),
|
||||
size: UInt::new(82595),
|
||||
})),
|
||||
}))),
|
||||
thumbnail_url: Some(mxc_uri!("mxc://matrix.org/irsns989Rrsn")),
|
||||
thumbnail_file: None,
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
blurhash: None,
|
||||
},
|
||||
}),
|
||||
mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs"),
|
||||
)),
|
||||
event_id: event_id!("$h29iv0s8:example.com"),
|
||||
@ -193,6 +191,7 @@ fn deserialize_message_sticker() {
|
||||
thumbnail_file: None,
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
blurhash: None,
|
||||
..
|
||||
},
|
||||
url,
|
||||
..
|
||||
@ -219,6 +218,7 @@ fn deserialize_message_sticker() {
|
||||
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".into())
|
||||
|
@ -223,8 +223,7 @@ fn deserialize_avatar_without_prev_content() {
|
||||
size,
|
||||
thumbnail_info: Some(thumbnail_info),
|
||||
thumbnail_url: Some(thumbnail_url),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
blurhash: None,
|
||||
..
|
||||
} if *height == UInt::new(423)
|
||||
&& *width == UInt::new(1011)
|
||||
&& *mimetype == "image/png"
|
||||
@ -236,6 +235,7 @@ fn deserialize_avatar_without_prev_content() {
|
||||
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".into())
|
||||
|
Loading…
x
Reference in New Issue
Block a user