Struct ruma_common::events::room::message::RoomMessageEventContent
source · [−]pub struct RoomMessageEventContent {
pub msgtype: MessageType,
pub relates_to: Option<Relation>,
}events only.Expand description
The content of an m.room.message event.
This event is used when sending messages in a room.
Messages are not limited to be text.
Fields
msgtype: MessageTypeA key which identifies the type of message being sent.
This also holds the specific content of each message.
relates_to: Option<Relation>Information about related messages for rich replies.
Implementations
sourceimpl RoomMessageEventContent
impl RoomMessageEventContent
sourcepub fn new(msgtype: MessageType) -> Self
pub fn new(msgtype: MessageType) -> Self
Create a RoomMessageEventContent with the given MessageType.
sourcepub fn text_plain(body: impl Into<String>) -> Self
pub fn text_plain(body: impl Into<String>) -> Self
A constructor to create a plain text message.
sourcepub fn text_html(body: impl Into<String>, html_body: impl Into<String>) -> Self
pub fn text_html(body: impl Into<String>, html_body: impl Into<String>) -> Self
A constructor to create an html message.
sourcepub fn text_markdown(body: impl AsRef<str> + Into<String>) -> Self
Available on crate feature markdown only.
pub fn text_markdown(body: impl AsRef<str> + Into<String>) -> Self
markdown only.A constructor to create a markdown message.
sourcepub fn notice_plain(body: impl Into<String>) -> Self
pub fn notice_plain(body: impl Into<String>) -> Self
A constructor to create a plain text notice.
sourcepub fn notice_html(body: impl Into<String>, html_body: impl Into<String>) -> Self
pub fn notice_html(body: impl Into<String>, html_body: impl Into<String>) -> Self
A constructor to create an html notice.
sourcepub fn notice_markdown(body: impl AsRef<str> + Into<String>) -> Self
Available on crate feature markdown only.
pub fn notice_markdown(body: impl AsRef<str> + Into<String>) -> Self
markdown only.A constructor to create a markdown notice.
sourcepub fn make_reply_to(self, original_message: &OriginalRoomMessageEvent) -> Self
pub fn make_reply_to(self, original_message: &OriginalRoomMessageEvent) -> Self
Turns self into a reply to the given message.
Takes the body / formatted_body (if any) in self for the main text and prepends a
quoted version of original_message. Also sets the in_reply_to field inside relates_to.
This function requires an OriginalRoomMessageEvent since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an
OriginalSyncRoomMessageEvent, you have to convert it first by calling
.into_full_event().
If the message was edited, the previous message should be the original message that was edited, with the content of its replacement, to allow the fallback to be accurate at the time it is added.
It is recommended to enable the sanitize feature when using this method as this will
clean up nested rich reply fallbacks in chains of replies. This uses sanitize_html()
internally, with RemoveReplyFallback::Yes.
Panics
Panics if self has a formatted_body with a format other than HTML.
sourcepub fn text_reply_plain(
reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
👎Deprecated: use Self::text_plain(reply).make_reply_to(original_message) instead
pub fn text_reply_plain(
reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
use Self::text_plain(reply).make_reply_to(original_message) instead
Creates a plain text reply to a message.
This function requires an OriginalRoomMessageEvent since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an
OriginalSyncRoomMessageEvent, you have to convert it first by calling
.into_full_event().
If the message was edited, the previous message should be the original message that was edited, with the content of its replacement, to allow the fallback to be accurate at the time it is added.
It is recommended to enable the sanitize feature when using this method as this will
clean up nested rich reply fallbacks in chains of replies. This uses sanitize_html()
internally, with RemoveReplyFallback::Yes.
sourcepub fn text_reply_html(
reply: impl Display,
html_reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
👎Deprecated: use Self::text_html(reply, html_reply).make_reply_to(original_message) instead
pub fn text_reply_html(
reply: impl Display,
html_reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
use Self::text_html(reply, html_reply).make_reply_to(original_message) instead
Creates a html text reply to a message.
This function requires an OriginalRoomMessageEvent since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an
OriginalSyncRoomMessageEvent, you have to convert it first by calling
.into_full_event().
If the message was edited, the previous message should be the original message that was edited, with the content of its replacement, to allow the fallback to be accurate at the time it is added.
It is recommended to enable the sanitize feature when using this method as this will
clean up nested rich reply fallbacks in chains of replies. This uses sanitize_html()
internally, with RemoveReplyFallback::Yes.
sourcepub fn notice_reply_plain(
reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
👎Deprecated: use Self::notice_plain(reply).make_reply_to(original_message) instead
pub fn notice_reply_plain(
reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
use Self::notice_plain(reply).make_reply_to(original_message) instead
Creates a plain text notice reply to a message.
This function requires an OriginalRoomMessageEvent since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an
OriginalSyncRoomMessageEvent, you have to convert it first by calling
.into_full_event().
If the message was edited, the previous message should be the original message that was edited, with the content of its replacement, to allow the fallback to be accurate at the time it is added.
It is recommended to enable the sanitize feature when using this method as this will
clean up nested rich reply fallbacks in chains of replies. This uses sanitize_html()
internally, with RemoveReplyFallback::Yes.
sourcepub fn notice_reply_html(
reply: impl Display,
html_reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
👎Deprecated: use Self::notice_html(reply, html_reply).make_reply_to(original_message) instead
pub fn notice_reply_html(
reply: impl Display,
html_reply: impl Display,
original_message: &OriginalRoomMessageEvent
) -> Self
use Self::notice_html(reply, html_reply).make_reply_to(original_message) instead
Creates a html text notice reply to a message.
This function requires an OriginalRoomMessageEvent since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an
OriginalSyncRoomMessageEvent, you have to convert it first by calling
.into_full_event().
If the message was edited, the previous message should be the original message that was edited, with the content of its replacement, to allow the fallback to be accurate at the time it is added.
It is recommended to enable the sanitize feature when using this method as this will
clean up nested rich reply fallbacks in chains of replies. This uses sanitize_html()
internally, with RemoveReplyFallback::Yes.
sourcepub fn reply(
message: MessageType,
original_message: &OriginalRoomMessageEvent,
forward_thread: ForwardThread
) -> Self
Available on crate feature unstable-msc3440 only.
pub fn reply(
message: MessageType,
original_message: &OriginalRoomMessageEvent,
forward_thread: ForwardThread
) -> Self
unstable-msc3440 only.Create a new reply with the given message and optionally forwards the Relation::Thread.
If message is a text, an emote or a notice message, it is modified to include the rich
reply fallback.
This function requires an OriginalRoomMessageEvent since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an
OriginalSyncRoomMessageEvent, you have to convert it first by calling
.into_full_event().
If the message was edited, the previous message should be the original message that was edited, with the content of its replacement, to allow the fallback to be accurate at the time it is added.
It is recommended to enable the sanitize feature when using this method as this will
clean up nested rich reply fallbacks in chains of replies. This uses sanitize_html()
internally, with RemoveReplyFallback::Yes.
sourcepub fn for_thread(
message: MessageType,
previous_message: &OriginalRoomMessageEvent,
is_reply: ReplyInThread
) -> Self
Available on crate feature unstable-msc3440 only.
pub fn for_thread(
message: MessageType,
previous_message: &OriginalRoomMessageEvent,
is_reply: ReplyInThread
) -> Self
unstable-msc3440 only.Create a new message for a thread that is optionally a reply.
Looks for a Relation::Thread in previous_message. If it exists, a message for the same
thread is created. If it doesn’t, a new thread with previous_message as the root is
created.
If message is a text, an emote or a notice message, and this is a reply in the thread, it
is modified to include the rich reply fallback.
This function requires an OriginalRoomMessageEvent since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an
OriginalSyncRoomMessageEvent, you have to convert it first by calling
.into_full_event().
If the message was edited, the previous message should be the original message that was edited, with the content of its replacement, to allow the fallback to be accurate at the time it is added.
It is recommended to enable the sanitize feature when using this method as this will
clean up nested rich reply fallbacks in chains of replies. This uses sanitize_html()
internally, with RemoveReplyFallback::Yes.
sourcepub fn msgtype(&self) -> &str
pub fn msgtype(&self) -> &str
Returns a reference to the msgtype string.
If you want to access the message type-specific data rather than the message type itself,
use the msgtype field, not this method.
sourcepub fn sanitize(
&mut self,
mode: HtmlSanitizerMode,
remove_reply_fallback: RemoveReplyFallback
)
Available on crate feature unstable-sanitize only.
pub fn sanitize(
&mut self,
mode: HtmlSanitizerMode,
remove_reply_fallback: RemoveReplyFallback
)
unstable-sanitize only.Sanitize this message.
If this message contains HTML, this removes the tags and attributes that are not listed in the Matrix specification.
It can also optionally remove the rich reply fallback from the plain text and HTML message.
This method is only effective on text, notice and emote messages.
Trait Implementations
sourceimpl Clone for RoomMessageEventContent
impl Clone for RoomMessageEventContent
sourcefn clone(&self) -> RoomMessageEventContent
fn clone(&self) -> RoomMessageEventContent
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresourceimpl Debug for RoomMessageEventContent
impl Debug for RoomMessageEventContent
sourceimpl<'de> Deserialize<'de> for RoomMessageEventContent
impl<'de> Deserialize<'de> for RoomMessageEventContent
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
sourceimpl EventContent for RoomMessageEventContent
impl EventContent for RoomMessageEventContent
type EventType = MessageLikeEventType
type EventType = MessageLikeEventType
sourcefn event_type(&self) -> Self::EventType
fn event_type(&self) -> Self::EventType
m.room.message.sourceimpl From<AudioEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc3246 only.
impl From<AudioEventContent> for RoomMessageEventContent
unstable-msc3246 only.sourcefn from(content: AudioEventContent) -> Self
fn from(content: AudioEventContent) -> Self
sourceimpl From<EmoteEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc1767 only.
impl From<EmoteEventContent> for RoomMessageEventContent
unstable-msc1767 only.sourcefn from(content: EmoteEventContent) -> Self
fn from(content: EmoteEventContent) -> Self
sourceimpl From<FileEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc3551 only.
impl From<FileEventContent> for RoomMessageEventContent
unstable-msc3551 only.sourcefn from(content: FileEventContent) -> Self
fn from(content: FileEventContent) -> Self
sourceimpl From<ImageEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc3552 only.
impl From<ImageEventContent> for RoomMessageEventContent
unstable-msc3552 only.sourcefn from(content: ImageEventContent) -> Self
fn from(content: ImageEventContent) -> Self
sourceimpl From<LocationEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc3488 only.
impl From<LocationEventContent> for RoomMessageEventContent
unstable-msc3488 only.sourcefn from(content: LocationEventContent) -> Self
fn from(content: LocationEventContent) -> Self
sourceimpl From<MessageEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc1767 only.
impl From<MessageEventContent> for RoomMessageEventContent
unstable-msc1767 only.sourcefn from(content: MessageEventContent) -> Self
fn from(content: MessageEventContent) -> Self
sourceimpl From<MessageType> for RoomMessageEventContent
impl From<MessageType> for RoomMessageEventContent
sourcefn from(msgtype: MessageType) -> Self
fn from(msgtype: MessageType) -> Self
sourceimpl From<NoticeEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc1767 only.
impl From<NoticeEventContent> for RoomMessageEventContent
unstable-msc1767 only.sourcefn from(content: NoticeEventContent) -> Self
fn from(content: NoticeEventContent) -> Self
sourceimpl From<RoomMessageEventContent> for AnyMessageLikeEventContent
impl From<RoomMessageEventContent> for AnyMessageLikeEventContent
sourcefn from(c: RoomMessageEventContent) -> Self
fn from(c: RoomMessageEventContent) -> Self
sourceimpl From<VideoEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc3553 only.
impl From<VideoEventContent> for RoomMessageEventContent
unstable-msc3553 only.sourcefn from(content: VideoEventContent) -> Self
fn from(content: VideoEventContent) -> Self
sourceimpl From<VoiceEventContent> for RoomMessageEventContent
Available on crate feature unstable-msc3245 only.
impl From<VoiceEventContent> for RoomMessageEventContent
unstable-msc3245 only.sourcefn from(content: VoiceEventContent) -> Self
fn from(content: VoiceEventContent) -> Self
sourceimpl RedactContent for RoomMessageEventContent
impl RedactContent for RoomMessageEventContent
type Redacted = RedactedRoomMessageEventContent
type Redacted = RedactedRoomMessageEventContent
sourcefn redact(self, version: &RoomVersionId) -> RedactedRoomMessageEventContent
fn redact(self, version: &RoomVersionId) -> RedactedRoomMessageEventContent
self into a redacted form (removing most or all fields) according to the spec. Read more