diff --git a/crates/ruma-events/src/room/message.rs b/crates/ruma-events/src/room/message.rs index aa539204..89651700 100644 --- a/crates/ruma-events/src/room/message.rs +++ b/crates/ruma-events/src/room/message.rs @@ -38,6 +38,7 @@ pub mod sanitize; mod server_notice; mod text; mod video; +mod without_relation; #[cfg(feature = "unstable-msc3245-v1-compat")] pub use self::audio::{UnstableAudioDetailsContentBlock, UnstableVoiceContentBlock}; @@ -54,6 +55,7 @@ pub use self::{ server_notice::{LimitType, ServerNoticeMessageEventContent, ServerNoticeType}, text::TextMessageEventContent, video::{VideoInfo, VideoMessageEventContent}, + without_relation::RoomMessageEventContentWithoutRelation, }; /// The content of an `m.room.message` event. @@ -485,52 +487,6 @@ impl RoomMessageEventContent { } } -/// Form of [`RoomMessageEventContent`] without relation. -#[derive(Clone, Debug, Serialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct RoomMessageEventContentWithoutRelation { - /// A key which identifies the type of message being sent. - /// - /// This also holds the specific content of each message. - #[serde(flatten)] - pub msgtype: MessageType, - - /// The [mentions] of this event. - /// - /// [mentions]: https://spec.matrix.org/latest/client-server-api/#user-and-room-mentions - #[serde(rename = "m.mentions", skip_serializing_if = "Option::is_none")] - pub mentions: Option, -} - -impl RoomMessageEventContentWithoutRelation { - /// Creates a new `RoomMessageEventContentWithoutRelation` with the given `MessageType`. - pub fn new(msgtype: MessageType) -> Self { - Self { msgtype, mentions: None } - } - - /// Transform `self` into a `RoomMessageEventContent` with the given relation. - pub fn with_relation( - self, - relates_to: Option>, - ) -> RoomMessageEventContent { - let Self { msgtype, mentions } = self; - RoomMessageEventContent { msgtype, relates_to, mentions } - } -} - -impl From for RoomMessageEventContentWithoutRelation { - fn from(msgtype: MessageType) -> Self { - Self::new(msgtype) - } -} - -impl From for RoomMessageEventContentWithoutRelation { - fn from(value: RoomMessageEventContent) -> Self { - let RoomMessageEventContent { msgtype, mentions, .. } = value; - Self { msgtype, mentions } - } -} - /// Whether or not to forward a [`Relation::Thread`] when sending a reply. #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[allow(clippy::exhaustive_enums)] diff --git a/crates/ruma-events/src/room/message/without_relation.rs b/crates/ruma-events/src/room/message/without_relation.rs new file mode 100644 index 00000000..9f15a4ea --- /dev/null +++ b/crates/ruma-events/src/room/message/without_relation.rs @@ -0,0 +1,50 @@ +use serde::Serialize; + +use super::{MessageType, Relation, RoomMessageEventContent}; +use crate::Mentions; + +/// Form of [`RoomMessageEventContent`] without relation. +#[derive(Clone, Debug, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] +pub struct RoomMessageEventContentWithoutRelation { + /// A key which identifies the type of message being sent. + /// + /// This also holds the specific content of each message. + #[serde(flatten)] + pub msgtype: MessageType, + + /// The [mentions] of this event. + /// + /// [mentions]: https://spec.matrix.org/latest/client-server-api/#user-and-room-mentions + #[serde(rename = "m.mentions", skip_serializing_if = "Option::is_none")] + pub mentions: Option, +} + +impl RoomMessageEventContentWithoutRelation { + /// Creates a new `RoomMessageEventContentWithoutRelation` with the given `MessageType`. + pub fn new(msgtype: MessageType) -> Self { + Self { msgtype, mentions: None } + } + + /// Transform `self` into a `RoomMessageEventContent` with the given relation. + pub fn with_relation( + self, + relates_to: Option>, + ) -> RoomMessageEventContent { + let Self { msgtype, mentions } = self; + RoomMessageEventContent { msgtype, relates_to, mentions } + } +} + +impl From for RoomMessageEventContentWithoutRelation { + fn from(msgtype: MessageType) -> Self { + Self::new(msgtype) + } +} + +impl From for RoomMessageEventContentWithoutRelation { + fn from(value: RoomMessageEventContent) -> Self { + let RoomMessageEventContent { msgtype, mentions, .. } = value; + Self { msgtype, mentions } + } +}