events: Add convenience c'tors to RoomMessageEventContentWithoutRelation

This commit is contained in:
Jonas Platte 2023-10-09 16:01:27 +02:00
parent 0f023c5222
commit 533beb600f
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
2 changed files with 50 additions and 0 deletions

View File

@ -4,6 +4,8 @@ Improvements:
- Calling `make_reply_to` or `make_reply_to_raw` with `AddMentions::Yes` no longer adds people - 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) 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 # 0.27.0

View File

@ -26,6 +26,54 @@ impl RoomMessageEventContentWithoutRelation {
Self { msgtype, mentions: None } Self { msgtype, mentions: None }
} }
/// A constructor to create a plain text message.
pub fn text_plain(body: impl Into<String>) -> Self {
Self::new(MessageType::text_plain(body))
}
/// A constructor to create an html message.
pub fn text_html(body: impl Into<String>, html_body: impl Into<String>) -> 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<str> + Into<String>) -> Self {
Self::new(MessageType::text_markdown(body))
}
/// A constructor to create a plain text notice.
pub fn notice_plain(body: impl Into<String>) -> Self {
Self::new(MessageType::notice_plain(body))
}
/// A constructor to create an html notice.
pub fn notice_html(body: impl Into<String>, html_body: impl Into<String>) -> 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<str> + Into<String>) -> Self {
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))
}
/// Transform `self` into a `RoomMessageEventContent` with the given relation. /// Transform `self` into a `RoomMessageEventContent` with the given relation.
pub fn with_relation( pub fn with_relation(
self, self,