events: Make StickerEventContent non-exhaustive
This commit is contained in:
parent
7f01a6d73b
commit
dc57620ae0
@ -11,6 +11,7 @@ pub type StickerEvent = MessageEvent<StickerEventContent>;
|
||||
|
||||
/// The payload for `StickerEvent`.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, MessageEventContent)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[ruma_event(type = "m.sticker")]
|
||||
pub struct StickerEventContent {
|
||||
/// A textual representation or associated description of the sticker image. This could
|
||||
@ -24,3 +25,10 @@ pub struct StickerEventContent {
|
||||
/// The URL to the sticker image. This must be a valid `mxc://` URI.
|
||||
pub url: MxcUri,
|
||||
}
|
||||
|
||||
impl StickerEventContent {
|
||||
/// Creates a new `StickerEventContent` with the given body, image info and URL.
|
||||
pub fn new(body: String, info: ImageInfo, url: MxcUri) -> Self {
|
||||
Self { body, info, url }
|
||||
}
|
||||
}
|
||||
|
@ -69,9 +69,9 @@ fn deserialize_message_event() {
|
||||
#[test]
|
||||
fn serialize_message_event() {
|
||||
let aliases_event = AnyMessageEvent::Sticker(MessageEvent {
|
||||
content: StickerEventContent {
|
||||
body: "Hello".into(),
|
||||
info: ImageInfo {
|
||||
content: StickerEventContent::new(
|
||||
"Hello".into(),
|
||||
ImageInfo {
|
||||
height: UInt::new(423),
|
||||
width: UInt::new(1011),
|
||||
mimetype: Some("image/png".into()),
|
||||
@ -87,8 +87,8 @@ fn serialize_message_event() {
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
blurhash: None,
|
||||
},
|
||||
url: mxc_uri!("mxc://matrix.org/arsrns98rsRSR"),
|
||||
},
|
||||
mxc_uri!("mxc://matrix.org/arsrns98rsRSR"),
|
||||
),
|
||||
event_id: event_id!("$h29iv0s8:example.com"),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
room_id: room_id!("!roomid:room.com"),
|
||||
|
@ -15,9 +15,9 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
||||
#[test]
|
||||
fn message_serialize_sticker() {
|
||||
let aliases_event = MessageEvent {
|
||||
content: AnyMessageEventContent::Sticker(StickerEventContent {
|
||||
body: "Hello".into(),
|
||||
info: ImageInfo {
|
||||
content: AnyMessageEventContent::Sticker(StickerEventContent::new(
|
||||
"Hello".into(),
|
||||
ImageInfo {
|
||||
height: UInt::new(423),
|
||||
width: UInt::new(1011),
|
||||
mimetype: Some("image/png".into()),
|
||||
@ -33,8 +33,8 @@ fn message_serialize_sticker() {
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
blurhash: None,
|
||||
},
|
||||
url: mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs"),
|
||||
}),
|
||||
mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs"),
|
||||
)),
|
||||
event_id: event_id!("$h29iv0s8:example.com"),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
room_id: room_id!("!roomid:room.com"),
|
||||
@ -195,6 +195,7 @@ fn deserialize_message_sticker() {
|
||||
blurhash: None,
|
||||
},
|
||||
url,
|
||||
..
|
||||
}),
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
|
Loading…
x
Reference in New Issue
Block a user