events: Make remaining types in room::message non-exhaustive

This commit is contained in:
Jonas Platte 2021-05-16 22:36:06 +02:00
parent 7626135faf
commit 01f20b17c0
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -355,15 +355,15 @@ pub struct AudioMessageEventContent {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<MxcUri>, pub url: Option<MxcUri>,
/// Metadata for the audio clip referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<AudioInfo>>,
/// Information on the encrypted audio clip. /// Information on the encrypted audio clip.
/// ///
/// Required if the audio clip is encrypted. /// Required if the audio clip is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<Box<EncryptedFile>>, pub file: Option<Box<EncryptedFile>>,
/// Metadata for the audio clip referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<AudioInfo>>,
} }
impl AudioMessageEventContent { impl AudioMessageEventContent {
@ -456,15 +456,15 @@ pub struct FileMessageEventContent {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<MxcUri>, pub url: Option<MxcUri>,
/// Metadata about the file referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<FileInfo>>,
/// Information on the encrypted file. /// Information on the encrypted file.
/// ///
/// Required if file is encrypted. /// Required if file is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<Box<EncryptedFile>>, pub file: Option<Box<EncryptedFile>>,
/// Metadata about the file referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<FileInfo>>,
} }
impl FileMessageEventContent { impl FileMessageEventContent {
@ -481,7 +481,8 @@ impl FileMessageEventContent {
} }
/// Metadata about a file. /// Metadata about a file.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct FileInfo { pub struct FileInfo {
/// The mimetype of the file, e.g. "application/msword". /// The mimetype of the file, e.g. "application/msword".
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -508,8 +509,16 @@ pub struct FileInfo {
pub thumbnail_file: Option<Box<EncryptedFile>>, pub thumbnail_file: Option<Box<EncryptedFile>>,
} }
impl FileInfo {
/// Creates an empty `FileInfo`.
pub fn new() -> Self {
Self::default()
}
}
/// The payload for an image message. /// The payload for an image message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.image")] #[serde(tag = "msgtype", rename = "m.image")]
pub struct ImageMessageEventContent { pub struct ImageMessageEventContent {
/// A textual representation of the image. /// A textual representation of the image.
@ -518,10 +527,6 @@ pub struct ImageMessageEventContent {
/// description for accessibility e.g. "image attachment". /// description for accessibility e.g. "image attachment".
pub body: String, pub body: String,
/// Metadata about the image referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<ImageInfo>>,
/// The URL to the image. /// The URL to the image.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<MxcUri>, pub url: Option<MxcUri>,
@ -531,10 +536,28 @@ pub struct ImageMessageEventContent {
/// Required if image is encrypted. /// Required if image is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<Box<EncryptedFile>>, pub file: Option<Box<EncryptedFile>>,
/// Metadata about the image referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<ImageInfo>>,
}
impl ImageMessageEventContent {
/// Creates a new non-encrypted `ImageMessageEventContent` with the given body, url and optional
/// extra info.
pub fn plain(body: String, url: MxcUri, info: Option<Box<ImageInfo>>) -> Self {
Self { body, url: Some(url), info, file: None }
}
/// Creates a new encrypted `ImageMessageEventContent` with the given body and encrypted file.
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self { body, url: None, info: None, file: Some(Box::new(file)) }
}
} }
/// The payload for a location message. /// The payload for a location message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.location")] #[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
@ -549,13 +572,17 @@ pub struct LocationMessageEventContent {
pub info: Option<Box<LocationInfo>>, pub info: Option<Box<LocationInfo>>,
} }
/// Thumbnail info associated with a location. impl LocationMessageEventContent {
#[derive(Clone, Debug, Deserialize, Serialize)] /// Creates a new `LocationMessageEventContent` with the given body and geo URI.
pub struct LocationInfo { pub fn new(body: String, geo_uri: String) -> Self {
/// Metadata about the image referred to in `thumbnail_url` or `thumbnail_file`. Self { body, geo_uri, info: None }
#[serde(skip_serializing_if = "Option::is_none")] }
pub thumbnail_info: Option<Box<ThumbnailInfo>>, }
/// Thumbnail info associated with a location.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct LocationInfo {
/// The URL to a thumbnail of the location being represented. /// The URL to a thumbnail of the location being represented.
/// ///
/// Only present if the thumbnail is unencrypted. /// Only present if the thumbnail is unencrypted.
@ -567,6 +594,17 @@ pub struct LocationInfo {
/// Only present if the thumbnail is encrypted. /// Only present if the thumbnail is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_file: Option<Box<EncryptedFile>>, pub thumbnail_file: Option<Box<EncryptedFile>>,
/// Metadata about the image referred to in `thumbnail_url` or `thumbnail_file`.
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_info: Option<Box<ThumbnailInfo>>,
}
impl LocationInfo {
/// Creates an empty `LocationInfo`.
pub fn new() -> Self {
Self::default()
}
} }
/// The payload for a notice message. /// The payload for a notice message.
@ -596,6 +634,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)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.server_notice")] #[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.
@ -617,6 +656,13 @@ pub struct ServerNoticeMessageEventContent {
pub limit_type: Option<LimitType>, pub limit_type: Option<LimitType>,
} }
impl ServerNoticeMessageEventContent {
/// Creates a new `ServerNoticeMessageEventContent` with the given body and notice type.
pub fn new(body: String, server_notice_type: ServerNoticeType) -> Self {
Self { body, server_notice_type, admin_contact: None, limit_type: None }
}
}
/// Types of server notices. /// Types of server notices.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
pub enum ServerNoticeType { pub enum ServerNoticeType {
@ -644,9 +690,8 @@ pub enum LimitType {
/// The format for the formatted representation of a message body. /// The format for the formatted representation of a message body.
/// ///
/// This type can hold an arbitrary string. To check for events that are not /// This type can hold an arbitrary string. To check for formats that are not available as a
/// available as a documented variant here, use its string representation, /// documented variant here, use its string representation, obtained through `.as_str()`.
/// obtained through `.as_str()`.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
pub enum MessageFormat { pub enum MessageFormat {
/// HTML. /// HTML.
@ -726,16 +771,13 @@ impl TextMessageEventContent {
/// The payload for a video message. /// The payload for a video message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.video")] #[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".
pub body: String, pub body: String,
/// Metadata about the video clip referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<VideoInfo>>,
/// The URL to the video clip. /// The URL to the video clip.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<MxcUri>, pub url: Option<MxcUri>,
@ -745,10 +787,28 @@ pub struct VideoMessageEventContent {
/// Required if video clip is encrypted. /// Required if video clip is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<Box<EncryptedFile>>, pub file: Option<Box<EncryptedFile>>,
/// Metadata about the video clip referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<VideoInfo>>,
}
impl VideoMessageEventContent {
/// Creates a new non-encrypted `VideoMessageEventContent` with the given body, url and optional
/// extra info.
pub fn plain(body: String, url: MxcUri, info: Option<Box<VideoInfo>>) -> Self {
Self { body, url: Some(url), info, file: None }
}
/// Creates a new encrypted `VideoMessageEventContent` with the given body and encrypted file.
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self { body, url: None, info: None, file: Some(Box::new(file)) }
}
} }
/// Metadata about a video. /// Metadata about a video.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct VideoInfo { pub struct VideoInfo {
/// The duration of the video in milliseconds. /// The duration of the video in milliseconds.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -799,10 +859,18 @@ pub struct VideoInfo {
pub blurhash: Option<String>, pub blurhash: Option<String>,
} }
impl VideoInfo {
/// Creates an empty `VideoInfo`.
pub fn new() -> Self {
Self::default()
}
}
/// 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")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.key.verification.request")] #[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
@ -819,10 +887,24 @@ pub struct KeyVerificationRequestEventContent {
/// ///
/// Users should only respond to verification requests if they are named in this field. Users /// Users should only respond to verification requests if they are named in this field. Users
/// who are not named in this field and who did not send this event should ignore all other /// who are not named in this field and who did not send this event should ignore all other
/// events that have a m.reference relationship with this event. /// events that have a `m.reference` relationship with this event.
pub to: UserId, pub to: UserId,
} }
#[cfg(feature = "unstable-pre-spec")]
impl KeyVerificationRequestEventContent {
/// Creates a new `KeyVerificationRequestEventContent` with the given body, method, device and
/// user ID.
pub fn new(
body: String,
methods: Vec<VerificationMethod>,
from_device: DeviceIdBox,
to: UserId,
) -> Self {
Self { body, methods, from_device, to }
}
}
/// The payload for a custom message event. /// The payload for a custom message event.
#[doc(hidden)] #[doc(hidden)]
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]