diff --git a/crates/ruma-events/CHANGELOG.md b/crates/ruma-events/CHANGELOG.md index 5147a7c5..1b1c449c 100644 --- a/crates/ruma-events/CHANGELOG.md +++ b/crates/ruma-events/CHANGELOG.md @@ -4,6 +4,8 @@ Improvements: - Calling `make_reply_to` or `make_reply_to_raw` with `AddMentions::Yes` no longer adds people mentioned in the original message to mentions (only the sender of the original message) +- Add convenience constructors like `text_plain` to `RoomMessageEventContentWithoutRelation` + - These are the same that are already available on `RoomMessageEventContent` # 0.27.0 diff --git a/crates/ruma-events/src/room/message/without_relation.rs b/crates/ruma-events/src/room/message/without_relation.rs index 9f15a4ea..fea70429 100644 --- a/crates/ruma-events/src/room/message/without_relation.rs +++ b/crates/ruma-events/src/room/message/without_relation.rs @@ -26,6 +26,54 @@ impl RoomMessageEventContentWithoutRelation { Self { msgtype, mentions: None } } + /// A constructor to create a plain text message. + pub fn text_plain(body: impl Into) -> Self { + Self::new(MessageType::text_plain(body)) + } + + /// A constructor to create an html message. + pub fn text_html(body: impl Into, html_body: impl Into) -> Self { + Self::new(MessageType::text_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_markdown(body)) + } + + /// A constructor to create a plain text notice. + pub fn notice_plain(body: impl Into) -> Self { + Self::new(MessageType::notice_plain(body)) + } + + /// A constructor to create an html notice. + pub fn notice_html(body: impl Into, html_body: impl Into) -> Self { + Self::new(MessageType::notice_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_markdown(body)) + } + + /// A constructor to create a plain text emote. + pub fn emote_plain(body: impl Into) -> Self { + Self::new(MessageType::emote_plain(body)) + } + + /// A constructor to create an html emote. + pub fn emote_html(body: impl Into, html_body: impl Into) -> 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 + Into) -> Self { + Self::new(MessageType::emote_markdown(body)) + } + /// Transform `self` into a `RoomMessageEventContent` with the given relation. pub fn with_relation( self,