Enum ruma_events::room::message::MessageType
source · #[non_exhaustive]pub enum MessageType {
Audio(AudioMessageEventContent),
Emote(EmoteMessageEventContent),
File(FileMessageEventContent),
Image(ImageMessageEventContent),
Location(LocationMessageEventContent),
Notice(NoticeMessageEventContent),
ServerNotice(ServerNoticeMessageEventContent),
Text(TextMessageEventContent),
Video(VideoMessageEventContent),
VerificationRequest(KeyVerificationRequestEventContent),
}
Expand description
The content that is specific to each message type variant.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Audio(AudioMessageEventContent)
An audio message.
Emote(EmoteMessageEventContent)
An emote message.
File(FileMessageEventContent)
A file message.
Image(ImageMessageEventContent)
An image message.
Location(LocationMessageEventContent)
A location message.
Notice(NoticeMessageEventContent)
A notice message.
ServerNotice(ServerNoticeMessageEventContent)
A server notice message.
Text(TextMessageEventContent)
A text message.
Video(VideoMessageEventContent)
A video message.
VerificationRequest(KeyVerificationRequestEventContent)
A request to initiate a key verification.
Implementations§
source§impl MessageType
impl MessageType
sourcepub fn new(msgtype: &str, body: String, data: JsonObject) -> Result<Self>
pub fn new(msgtype: &str, body: String, data: JsonObject) -> Result<Self>
Creates a new MessageType
.
The msgtype
and body
are required fields as defined by the m.room.message
spec.
Additionally it’s possible to add arbitrary key/value pairs to the event content for custom
events through the data
map.
Prefer to use the public variants of MessageType
where possible; this constructor is meant
be used for unsupported message types only and does not allow setting arbitrary data for
supported ones.
§Errors
Returns an error if the msgtype
is known and serialization of data
to the corresponding
MessageType
variant fails.
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
pub fn text_markdown(body: impl AsRef<str> + Into<String>) -> Self
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
pub fn notice_markdown(body: impl AsRef<str> + Into<String>) -> Self
A constructor to create a markdown notice.
sourcepub fn emote_plain(body: impl Into<String>) -> Self
pub fn emote_plain(body: impl Into<String>) -> Self
A constructor to create a plain text emote.
sourcepub fn emote_html(body: impl Into<String>, html_body: impl Into<String>) -> Self
pub fn emote_html(body: impl Into<String>, html_body: impl Into<String>) -> Self
A constructor to create an html emote.
sourcepub fn emote_markdown(body: impl AsRef<str> + Into<String>) -> Self
pub fn emote_markdown(body: impl AsRef<str> + Into<String>) -> Self
A constructor to create a markdown emote.
sourcepub fn data(&self) -> Cow<'_, JsonObject>
pub fn data(&self) -> Cow<'_, JsonObject>
Returns the associated data.
The returned JSON object won’t contain the msgtype
and body
fields, use
.msgtype()
/ .body()
to access those.
Prefer to use the public variants of MessageType
where possible; this method is meant to
be used for custom message types only.
sourcepub fn sanitize(
&mut self,
mode: HtmlSanitizerMode,
remove_reply_fallback: RemoveReplyFallback,
)
pub fn sanitize( &mut self, mode: HtmlSanitizerMode, remove_reply_fallback: RemoveReplyFallback, )
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. Note that you should be sure that the message is a reply, as there is no way to differentiate plain text reply fallbacks and markdown quotes.
This method is only effective on text, notice and emote messages.
Trait Implementations§
source§impl Clone for MessageType
impl Clone for MessageType
source§fn clone(&self) -> MessageType
fn clone(&self) -> MessageType
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MessageType
impl Debug for MessageType
source§impl<'de> Deserialize<'de> for MessageType
impl<'de> Deserialize<'de> for MessageType
source§fn 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>,
source§impl From<MessageType> for RoomMessageEventContent
impl From<MessageType> for RoomMessageEventContent
source§fn from(msgtype: MessageType) -> Self
fn from(msgtype: MessageType) -> Self
source§impl From<MessageType> for RoomMessageEventContentWithoutRelation
impl From<MessageType> for RoomMessageEventContentWithoutRelation
source§fn from(msgtype: MessageType) -> Self
fn from(msgtype: MessageType) -> Self
source§impl From<RoomMessageEventContent> for MessageType
impl From<RoomMessageEventContent> for MessageType
source§fn from(content: RoomMessageEventContent) -> Self
fn from(content: RoomMessageEventContent) -> Self
Auto Trait Implementations§
impl Freeze for MessageType
impl RefUnwindSafe for MessageType
impl Send for MessageType
impl Sync for MessageType
impl Unpin for MessageType
impl UnwindSafe for MessageType
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)