events: Move RoomMessageEventContentWithoutRelation into separate module
This commit is contained in:
parent
25d0b3ce59
commit
0f023c5222
@ -38,6 +38,7 @@ pub mod sanitize;
|
|||||||
mod server_notice;
|
mod server_notice;
|
||||||
mod text;
|
mod text;
|
||||||
mod video;
|
mod video;
|
||||||
|
mod without_relation;
|
||||||
|
|
||||||
#[cfg(feature = "unstable-msc3245-v1-compat")]
|
#[cfg(feature = "unstable-msc3245-v1-compat")]
|
||||||
pub use self::audio::{UnstableAudioDetailsContentBlock, UnstableVoiceContentBlock};
|
pub use self::audio::{UnstableAudioDetailsContentBlock, UnstableVoiceContentBlock};
|
||||||
@ -54,6 +55,7 @@ pub use self::{
|
|||||||
server_notice::{LimitType, ServerNoticeMessageEventContent, ServerNoticeType},
|
server_notice::{LimitType, ServerNoticeMessageEventContent, ServerNoticeType},
|
||||||
text::TextMessageEventContent,
|
text::TextMessageEventContent,
|
||||||
video::{VideoInfo, VideoMessageEventContent},
|
video::{VideoInfo, VideoMessageEventContent},
|
||||||
|
without_relation::RoomMessageEventContentWithoutRelation,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The content of an `m.room.message` event.
|
/// 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<Mentions>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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<Relation<RoomMessageEventContentWithoutRelation>>,
|
|
||||||
) -> RoomMessageEventContent {
|
|
||||||
let Self { msgtype, mentions } = self;
|
|
||||||
RoomMessageEventContent { msgtype, relates_to, mentions }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<MessageType> for RoomMessageEventContentWithoutRelation {
|
|
||||||
fn from(msgtype: MessageType) -> Self {
|
|
||||||
Self::new(msgtype)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<RoomMessageEventContent> 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.
|
/// Whether or not to forward a [`Relation::Thread`] when sending a reply.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
#[allow(clippy::exhaustive_enums)]
|
#[allow(clippy::exhaustive_enums)]
|
||||||
|
50
crates/ruma-events/src/room/message/without_relation.rs
Normal file
50
crates/ruma-events/src/room/message/without_relation.rs
Normal file
@ -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<Mentions>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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<Relation<RoomMessageEventContentWithoutRelation>>,
|
||||||
|
) -> RoomMessageEventContent {
|
||||||
|
let Self { msgtype, mentions } = self;
|
||||||
|
RoomMessageEventContent { msgtype, relates_to, mentions }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MessageType> for RoomMessageEventContentWithoutRelation {
|
||||||
|
fn from(msgtype: MessageType) -> Self {
|
||||||
|
Self::new(msgtype)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RoomMessageEventContent> for RoomMessageEventContentWithoutRelation {
|
||||||
|
fn from(value: RoomMessageEventContent) -> Self {
|
||||||
|
let RoomMessageEventContent { msgtype, mentions, .. } = value;
|
||||||
|
Self { msgtype, mentions }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user