events: Add emote convenience constructors

… the same ones we have for text and notice msgtypes.
This commit is contained in:
Jonas Platte 2023-07-05 10:36:37 +02:00
parent e7bd302293
commit 775484c408
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C

View File

@ -105,6 +105,22 @@ impl RoomMessageEventContent {
Self::new(MessageType::notice_markdown(body))
}
/// A constructor to create a plain text emote.
pub fn emote_plain(body: impl Into<String>) -> Self {
Self::new(MessageType::emote_plain(body))
}
/// A constructor to create an html emote.
pub fn emote_html(body: impl Into<String>, html_body: impl Into<String>) -> Self {
Self::new(MessageType::emote_html(body, html_body))
}
/// A constructor to create a markdown emote.
#[cfg(feature = "markdown")]
pub fn emote_markdown(body: impl AsRef<str> + Into<String>) -> Self {
Self::new(MessageType::emote_markdown(body))
}
/// Turns `self` into a reply to the given message.
///
/// Takes the `body` / `formatted_body` (if any) in `self` for the main text and prepends a
@ -486,6 +502,22 @@ impl MessageType {
Self::Notice(NoticeMessageEventContent::markdown(body))
}
/// A constructor to create a plain text emote.
pub fn emote_plain(body: impl Into<String>) -> Self {
Self::Emote(EmoteMessageEventContent::plain(body))
}
/// A constructor to create an html emote.
pub fn emote_html(body: impl Into<String>, html_body: impl Into<String>) -> Self {
Self::Emote(EmoteMessageEventContent::html(body, html_body))
}
/// A constructor to create a markdown emote.
#[cfg(feature = "markdown")]
pub fn emote_markdown(body: impl AsRef<str> + Into<String>) -> Self {
Self::Emote(EmoteMessageEventContent::markdown(body))
}
/// Returns a reference to the `msgtype` string.
pub fn msgtype(&self) -> &str {
match self {