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
116
117
118
119
120
121
122
123
124
125
126
use std::time::Duration;
use js_int::UInt;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::{
file::FileContent, image::ThumbnailContent, message::MessageContent, room::message::Relation,
};
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.video", kind = MessageLike, without_relation)]
pub struct VideoEventContent {
#[serde(flatten)]
pub message: MessageContent,
#[serde(rename = "m.file")]
pub file: FileContent,
#[serde(rename = "m.video")]
pub video: Box<VideoContent>,
#[serde(rename = "m.thumbnail", default, skip_serializing_if = "Vec::is_empty")]
pub thumbnail: Vec<ThumbnailContent>,
#[serde(
rename = "m.caption",
with = "super::message::content_serde::as_vec",
default,
skip_serializing_if = "Option::is_none"
)]
pub caption: Option<MessageContent>,
#[serde(
flatten,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation"
)]
pub relates_to: Option<Relation<VideoEventContentWithoutRelation>>,
}
impl VideoEventContent {
pub fn plain(message: impl Into<String>, file: FileContent) -> Self {
Self {
message: MessageContent::plain(message),
file,
video: Default::default(),
thumbnail: Default::default(),
caption: Default::default(),
relates_to: None,
}
}
pub fn with_message(message: MessageContent, file: FileContent) -> Self {
Self {
message,
file,
video: Default::default(),
thumbnail: Default::default(),
caption: Default::default(),
relates_to: None,
}
}
}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct VideoContent {
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<UInt>,
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<UInt>,
#[serde(
with = "crate::serde::duration::opt_ms",
default,
skip_serializing_if = "Option::is_none"
)]
pub duration: Option<Duration>,
}
impl VideoContent {
pub fn new() -> Self {
Self::default()
}
pub(crate) fn from_room_message_content(
height: Option<UInt>,
width: Option<UInt>,
duration: Option<Duration>,
) -> Self {
Self { height, width, duration }
}
pub fn is_empty(&self) -> bool {
self.height.is_none() && self.width.is_none() && self.duration.is_none()
}
}