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
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::{
message::MessageContent,
room::message::{MessageType, NoticeMessageEventContent, Relation, RoomMessageEventContent},
};
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.notice", kind = MessageLike)]
pub struct NoticeEventContent {
#[serde(flatten)]
pub message: MessageContent,
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub relates_to: Option<Relation>,
}
impl NoticeEventContent {
pub fn plain(body: impl Into<String>) -> Self {
Self { message: MessageContent::plain(body), relates_to: None }
}
pub fn html(body: impl Into<String>, html_body: impl Into<String>) -> Self {
Self { message: MessageContent::html(body, html_body), relates_to: None }
}
#[cfg(feature = "markdown")]
pub fn markdown(body: impl AsRef<str> + Into<String>) -> Self {
Self { message: MessageContent::markdown(body), relates_to: None }
}
pub fn from_notice_room_message(
content: NoticeMessageEventContent,
relates_to: Option<Relation>,
) -> Self {
let NoticeMessageEventContent { body, formatted, message, .. } = content;
if let Some(message) = message {
Self { message, relates_to }
} else {
Self { message: MessageContent::from_room_message_content(body, formatted), relates_to }
}
}
}
impl From<NoticeEventContent> for RoomMessageEventContent {
fn from(content: NoticeEventContent) -> Self {
let NoticeEventContent { message, relates_to, .. } = content;
Self { msgtype: MessageType::Notice(message.into()), relates_to }
}
}