#[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: Map<String, Value>,
) -> Result<MessageType, Error>
pub fn new( msgtype: &str, body: String, data: Map<String, Value>, ) -> Result<MessageType, Error>
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>) -> MessageType
pub fn text_plain(body: impl Into<String>) -> MessageType
A constructor to create a plain text message.
Sourcepub fn text_html(
body: impl Into<String>,
html_body: impl Into<String>,
) -> MessageType
pub fn text_html( body: impl Into<String>, html_body: impl Into<String>, ) -> MessageType
A constructor to create an html message.
Sourcepub fn text_markdown(body: impl AsRef<str> + Into<String>) -> MessageType
Available on crate feature markdown
only.
pub fn text_markdown(body: impl AsRef<str> + Into<String>) -> MessageType
markdown
only.A constructor to create a markdown message.
Sourcepub fn notice_plain(body: impl Into<String>) -> MessageType
pub fn notice_plain(body: impl Into<String>) -> MessageType
A constructor to create a plain text notice.
Sourcepub fn notice_html(
body: impl Into<String>,
html_body: impl Into<String>,
) -> MessageType
pub fn notice_html( body: impl Into<String>, html_body: impl Into<String>, ) -> MessageType
A constructor to create an html notice.
Sourcepub fn notice_markdown(body: impl AsRef<str> + Into<String>) -> MessageType
Available on crate feature markdown
only.
pub fn notice_markdown(body: impl AsRef<str> + Into<String>) -> MessageType
markdown
only.A constructor to create a markdown notice.
Sourcepub fn emote_plain(body: impl Into<String>) -> MessageType
pub fn emote_plain(body: impl Into<String>) -> MessageType
A constructor to create a plain text emote.
Sourcepub fn emote_html(
body: impl Into<String>,
html_body: impl Into<String>,
) -> MessageType
pub fn emote_html( body: impl Into<String>, html_body: impl Into<String>, ) -> MessageType
A constructor to create an html emote.
Sourcepub fn emote_markdown(body: impl AsRef<str> + Into<String>) -> MessageType
Available on crate feature markdown
only.
pub fn emote_markdown(body: impl AsRef<str> + Into<String>) -> MessageType
markdown
only.A constructor to create a markdown emote.
Sourcepub fn data(&self) -> Cow<'_, Map<String, Value>>
pub fn data(&self) -> Cow<'_, Map<String, Value>>
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,
)
Available on crate feature html
only.
pub fn sanitize( &mut self, mode: HtmlSanitizerMode, remove_reply_fallback: RemoveReplyFallback, )
html
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. 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<MessageType, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<MessageType, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<MessageType> for RoomMessageEventContent
impl From<MessageType> for RoomMessageEventContent
Source§fn from(msgtype: MessageType) -> RoomMessageEventContent
fn from(msgtype: MessageType) -> RoomMessageEventContent
Source§impl From<MessageType> for RoomMessageEventContentWithoutRelation
impl From<MessageType> for RoomMessageEventContentWithoutRelation
Source§fn from(msgtype: MessageType) -> RoomMessageEventContentWithoutRelation
fn from(msgtype: MessageType) -> RoomMessageEventContentWithoutRelation
Source§impl From<RoomMessageEventContent> for MessageType
impl From<RoomMessageEventContent> for MessageType
Source§fn from(content: RoomMessageEventContent) -> MessageType
fn from(content: RoomMessageEventContent) -> MessageType
Source§impl Serialize for MessageType
impl Serialize for MessageType
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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,
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more