From 8fcd58c8de7706266ed09cd6988e4793e10d33d4 Mon Sep 17 00:00:00 2001 From: Tilo Spannagel Date: Mon, 11 Oct 2021 09:31:30 +0200 Subject: [PATCH] events: Add markdown constructors to RoomMessageEventContent --- crates/ruma-events/src/room/message.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/ruma-events/src/room/message.rs b/crates/ruma-events/src/room/message.rs index dfaee6fb..18b8b017 100644 --- a/crates/ruma-events/src/room/message.rs +++ b/crates/ruma-events/src/room/message.rs @@ -58,6 +58,12 @@ impl RoomMessageEventContent { Self::new(MessageType::Text(TextMessageEventContent::html(body, html_body))) } + /// A constructor to create a markdown message. + #[cfg(feature = "markdown")] + pub fn text_markdown(body: impl AsRef + Into) -> Self { + Self::new(MessageType::Text(TextMessageEventContent::markdown(body))) + } + /// A constructor to create a plain text notice. pub fn notice_plain(body: impl Into) -> Self { Self::new(MessageType::Notice(NoticeMessageEventContent::plain(body))) @@ -68,6 +74,12 @@ impl RoomMessageEventContent { Self::new(MessageType::Notice(NoticeMessageEventContent::html(body, html_body))) } + /// A constructor to create a markdown notice. + #[cfg(feature = "markdown")] + pub fn notice_markdown(body: impl AsRef + Into) -> Self { + Self::new(MessageType::Notice(NoticeMessageEventContent::markdown(body))) + } + /// Creates a plain text reply to a message. pub fn text_reply_plain(reply: impl Into, original_message: &RoomMessageEvent) -> Self { let quoted = get_plain_quote_fallback(original_message);