From aa3e7416a90500dbbc14a96d68ff36a0bb1466ec Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 11 Aug 2020 01:54:23 +0200 Subject: [PATCH] Update constructors in ruma_events::room::message --- ruma-events/src/room/message.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/ruma-events/src/room/message.rs b/ruma-events/src/room/message.rs index 0cb6364b..9f8baeb4 100644 --- a/ruma-events/src/room/message.rs +++ b/ruma-events/src/room/message.rs @@ -225,6 +225,13 @@ pub struct NoticeMessageEventContent { pub relates_to: Option, } +impl NoticeMessageEventContent { + /// A convenience constructor to create a plain text notices. + pub fn plain(body: impl Into) -> Self { + Self { body: body.into(), formatted: None, relates_to: None } + } +} + /// The payload for a server notice message. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ServerNoticeMessageEventContent { @@ -315,6 +322,19 @@ pub struct TextMessageEventContent { pub relates_to: Option, } +impl TextMessageEventContent { + /// A convenience constructor to create a plain text message. + pub fn plain(body: impl Into) -> Self { + Self { body: body.into(), formatted: None, relates_to: None } + } + + /// A convenience constructor to create a plain text message. + #[deprecated = "Renamed to plain"] + pub fn new_plain(body: impl Into) -> Self { + Self::plain(body) + } +} + /// The payload for a video message. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct VideoMessageEventContent { @@ -391,19 +411,6 @@ pub struct InReplyTo { pub event_id: EventId, } -impl TextMessageEventContent { - /// A convenience constructor to create a plain text message - pub fn plain(body: impl Into) -> Self { - Self { body: body.into(), formatted: None, relates_to: None } - } - - /// A convenience constructor to create a plain text message - #[deprecated = "Renamed to plain"] - pub fn new_plain(body: impl Into) -> Self { - Self::plain(body) - } -} - #[cfg(test)] mod tests { use std::time::{Duration, UNIX_EPOCH};