ruma_events/room/message/
emote.rs1use serde::{Deserialize, Serialize};
2
3use super::FormattedBody;
4
5#[derive(Clone, Debug, Deserialize, Serialize)]
7#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
8#[serde(tag = "msgtype", rename = "m.emote")]
9pub struct EmoteMessageEventContent {
10 pub body: String,
12
13 #[serde(flatten)]
15 pub formatted: Option<FormattedBody>,
16}
17
18impl EmoteMessageEventContent {
19 pub fn plain(body: impl Into<String>) -> Self {
21 let body = body.into();
22 Self { body, formatted: None }
23 }
24
25 pub fn html(body: impl Into<String>, html_body: impl Into<String>) -> Self {
27 let body = body.into();
28 Self { body, formatted: Some(FormattedBody::html(html_body)) }
29 }
30
31 #[cfg(feature = "markdown")]
36 pub fn markdown(body: impl AsRef<str> + Into<String>) -> Self {
37 if let Some(formatted) = FormattedBody::markdown(&body) {
38 Self::html(body, formatted.body)
39 } else {
40 Self::plain(body)
41 }
42 }
43}