1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc3552")]
use super::{
file::FileContent,
image::{ImageContent, ThumbnailContent},
message::MessageContent,
};
use crate::{events::room::ImageInfo, OwnedMxcUri};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.sticker", kind = MessageLike)]
pub struct StickerEventContent {
pub body: String,
pub info: ImageInfo,
pub url: OwnedMxcUri,
#[cfg(feature = "unstable-msc3552")]
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub message: Option<MessageContent>,
#[cfg(feature = "unstable-msc3552")]
#[serde(
rename = "org.matrix.msc1767.file",
alias = "m.file",
skip_serializing_if = "Option::is_none"
)]
pub file: Option<FileContent>,
#[cfg(feature = "unstable-msc3552")]
#[serde(
rename = "org.matrix.msc1767.image",
alias = "m.image",
skip_serializing_if = "Option::is_none"
)]
pub image: Option<Box<ImageContent>>,
#[cfg(feature = "unstable-msc3552")]
#[serde(
rename = "org.matrix.msc1767.thumbnail",
alias = "m.thumbnail",
skip_serializing_if = "Option::is_none"
)]
pub thumbnail: Option<Vec<ThumbnailContent>>,
#[cfg(feature = "unstable-msc3552")]
#[serde(
rename = "org.matrix.msc1767.caption",
alias = "m.caption",
with = "super::message::content_serde::as_vec",
default,
skip_serializing_if = "Option::is_none"
)]
pub caption: Option<MessageContent>,
}
impl StickerEventContent {
pub fn new(body: String, info: ImageInfo, url: OwnedMxcUri) -> Self {
Self {
#[cfg(feature = "unstable-msc3552")]
message: Some(MessageContent::plain(body.clone())),
#[cfg(feature = "unstable-msc3552")]
file: Some(FileContent::plain(url.clone(), Some(Box::new((&info).into())))),
#[cfg(feature = "unstable-msc3552")]
image: Some(Box::new((&info).into())),
#[cfg(feature = "unstable-msc3552")]
thumbnail: ThumbnailContent::from_room_message_content(
info.thumbnail_source.as_ref(),
info.thumbnail_info.as_deref(),
)
.map(|thumbnail| vec![thumbnail]),
#[cfg(feature = "unstable-msc3552")]
caption: None,
body,
info,
url,
}
}
}