Skip to main content

tuwunel_matrix/event/
msgtype.rs

1use serde::Deserialize;
2
3use super::Event;
4
5/// The `msgtype` of an `m.room.message` event's content.
6///
7/// Each type the specification defines has a variant, and any other value,
8/// custom or unstable, reads as `Other`, so reading one never allocates.
9#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
10pub enum MsgType {
11	/// An audio message, `m.audio`.
12	#[serde(rename = "m.audio")]
13	Audio,
14
15	/// An action performed by the sender, `m.emote`.
16	#[serde(rename = "m.emote")]
17	Emote,
18
19	/// A file message, `m.file`.
20	#[serde(rename = "m.file")]
21	File,
22
23	/// An image message, `m.image`.
24	#[serde(rename = "m.image")]
25	Image,
26
27	/// An in-room key verification request, `m.key.verification.request`.
28	#[serde(rename = "m.key.verification.request")]
29	KeyVerificationRequest,
30
31	/// A location message, `m.location`.
32	#[serde(rename = "m.location")]
33	Location,
34
35	/// An automated message no client may answer automatically, `m.notice`.
36	#[serde(rename = "m.notice")]
37	Notice,
38
39	/// A notice from the server itself, `m.server_notice`.
40	#[serde(rename = "m.server_notice")]
41	ServerNotice,
42
43	/// A plain text message, `m.text`.
44	#[serde(rename = "m.text")]
45	Text,
46
47	/// A video message, `m.video`.
48	#[serde(rename = "m.video")]
49	Video,
50
51	/// Any type the specification does not define.
52	#[serde(other)]
53	Other,
54}
55
56#[derive(Deserialize)]
57struct Content {
58	msgtype: Option<MsgType>,
59}
60
61pub(super) fn content_msgtype<E: Event>(event: &E) -> Option<MsgType> {
62	event
63		.get_content()
64		.ok()
65		.and_then(|content: Content| content.msgtype)
66}