events: Replace serde(tag) by serde(untagged) for MessageEventContent

in preparation for adding a variant for custom `msgtype`s.
This commit is contained in:
Akshay 2021-02-12 13:51:28 +01:00 committed by Jonas Platte
parent 526542c246
commit 704e5f89f5
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -32,47 +32,37 @@ pub type MessageEvent = OuterMessageEvent<MessageEventContent>;
#[derive(Clone, Debug, Serialize, MessageEventContent)] #[derive(Clone, Debug, Serialize, MessageEventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.room.message")] #[ruma_event(type = "m.room.message")]
#[serde(tag = "msgtype")] #[serde(untagged)]
pub enum MessageEventContent { pub enum MessageEventContent {
/// An audio message. /// An audio message.
#[serde(rename = "m.audio")]
Audio(AudioMessageEventContent), Audio(AudioMessageEventContent),
/// An emote message. /// An emote message.
#[serde(rename = "m.emote")]
Emote(EmoteMessageEventContent), Emote(EmoteMessageEventContent),
/// A file message. /// A file message.
#[serde(rename = "m.file")]
File(FileMessageEventContent), File(FileMessageEventContent),
/// An image message. /// An image message.
#[serde(rename = "m.image")]
Image(ImageMessageEventContent), Image(ImageMessageEventContent),
/// A location message. /// A location message.
#[serde(rename = "m.location")]
Location(LocationMessageEventContent), Location(LocationMessageEventContent),
/// A notice message. /// A notice message.
#[serde(rename = "m.notice")]
Notice(NoticeMessageEventContent), Notice(NoticeMessageEventContent),
/// A server notice message. /// A server notice message.
#[serde(rename = "m.server_notice")]
ServerNotice(ServerNoticeMessageEventContent), ServerNotice(ServerNoticeMessageEventContent),
/// A text message. /// A text message.
#[serde(rename = "m.text")]
Text(TextMessageEventContent), Text(TextMessageEventContent),
/// A video message. /// A video message.
#[serde(rename = "m.video")]
Video(VideoMessageEventContent), Video(VideoMessageEventContent),
/// A request to initiate a key verification. /// A request to initiate a key verification.
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
#[serde(rename = "m.key.verification.request")]
VerificationRequest(KeyVerificationRequestEventContent), VerificationRequest(KeyVerificationRequestEventContent),
} }
@ -160,6 +150,7 @@ impl MessageEventContent {
/// The payload for an audio message. /// The payload for an audio message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.audio")]
pub struct AudioMessageEventContent { pub struct AudioMessageEventContent {
/// The textual representation of this message. /// The textual representation of this message.
pub body: String, pub body: String,
@ -196,6 +187,7 @@ pub struct AudioInfo {
/// The payload for an emote message. /// The payload for an emote message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.emote")]
pub struct EmoteMessageEventContent { pub struct EmoteMessageEventContent {
/// The emote action to perform. /// The emote action to perform.
pub body: String, pub body: String,
@ -207,6 +199,7 @@ pub struct EmoteMessageEventContent {
/// The payload for a file message. /// The payload for a file message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.file")]
pub struct FileMessageEventContent { pub struct FileMessageEventContent {
/// A human-readable description of the file. This is recommended to be the filename of the /// A human-readable description of the file. This is recommended to be the filename of the
/// original upload. /// original upload.
@ -256,6 +249,7 @@ pub struct FileInfo {
/// The payload for an image message. /// The payload for an image message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.image")]
pub struct ImageMessageEventContent { pub struct ImageMessageEventContent {
/// A textual representation of the image. This could be the alt text of the image, the /// A textual representation of the image. This could be the alt text of the image, the
/// filename of the image, or some kind of content description for accessibility e.g. /// filename of the image, or some kind of content description for accessibility e.g.
@ -278,6 +272,7 @@ pub struct ImageMessageEventContent {
/// The payload for a location message. /// The payload for a location message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.location")]
pub struct LocationMessageEventContent { pub struct LocationMessageEventContent {
/// A description of the location e.g. "Big Ben, London, UK,"or some kind of content /// A description of the location e.g. "Big Ben, London, UK,"or some kind of content
/// description for accessibility, e.g. "location attachment." /// description for accessibility, e.g. "location attachment."
@ -312,6 +307,7 @@ pub struct LocationInfo {
/// The payload for a notice message. /// The payload for a notice message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.notice")]
pub struct NoticeMessageEventContent { pub struct NoticeMessageEventContent {
/// The notice text. /// The notice text.
pub body: String, pub body: String,
@ -353,6 +349,7 @@ impl NoticeMessageEventContent {
/// The payload for a server notice message. /// The payload for a server notice message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.server_notice")]
pub struct ServerNoticeMessageEventContent { pub struct ServerNoticeMessageEventContent {
/// A human-readable description of the notice. /// A human-readable description of the notice.
pub body: String, pub body: String,
@ -442,6 +439,7 @@ impl FormattedBody {
/// The payload for a text message. /// The payload for a text message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.text")]
pub struct TextMessageEventContent { pub struct TextMessageEventContent {
/// The body of the message. /// The body of the message.
pub body: String, pub body: String,
@ -498,6 +496,7 @@ impl TextMessageEventContent {
/// The payload for a video message. /// The payload for a video message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "msgtype", rename = "m.video")]
pub struct VideoMessageEventContent { pub struct VideoMessageEventContent {
/// A description of the video, e.g. "Gangnam Style," or some kind of content description for /// A description of the video, e.g. "Gangnam Style," or some kind of content description for
/// accessibility, e.g. "video attachment." /// accessibility, e.g. "video attachment."
@ -568,6 +567,7 @@ pub struct VideoInfo {
/// The payload for a key verification request message. /// The payload for a key verification request message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
#[serde(tag = "msgtype", rename = "m.key.verification.request")]
pub struct KeyVerificationRequestEventContent { pub struct KeyVerificationRequestEventContent {
/// A fallback message to alert users that their client does not support the key verification /// A fallback message to alert users that their client does not support the key verification
/// framework. /// framework.