Implement MSC2448: BlurHashes for media

This exposes the pre-FCP unstable prefixed fields in MSC2448.
This commit is contained in:
David Vo 2020-12-07 23:01:15 +11:00 committed by GitHub
parent 018adf0819
commit 1a4e9aa20a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 1 deletions

View File

@ -30,6 +30,15 @@ ruma_api! {
response: { response: {
/// The MXC URI for the uploaded content. /// The MXC URI for the uploaded content.
pub content_uri: String, pub content_uri: String,
/// The [BlurHash](https://blurha.sh) for the uploaded content.
///
/// This uses the unstable prefix in
/// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448).
#[cfg(feature = "unstable-pre-spec")]
#[serde(rename = "xyz.amorgan.blurhash")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blurhash: Option<String>,
} }
error: crate::Error error: crate::Error
@ -45,6 +54,10 @@ impl<'a> Request<'a> {
impl Response { impl Response {
/// Creates a new `Response` with the given MXC URI. /// Creates a new `Response` with the given MXC URI.
pub fn new(content_uri: String) -> Self { pub fn new(content_uri: String) -> Self {
Self { content_uri } Self {
content_uri,
#[cfg(feature = "unstable-pre-spec")]
blurhash: None,
}
} }
} }

View File

@ -58,6 +58,15 @@ pub struct ImageInfo {
/// Information on the encrypted thumbnail image. Only present if the thumbnail is encrypted. /// Information on the encrypted thumbnail image. 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>>,
/// The [BlurHash](https://blurha.sh) for this image.
///
/// This uses the unstable prefix in
/// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448).
#[cfg(feature = "unstable-pre-spec")]
#[serde(rename = "xyz.amorgan.blurhash")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blurhash: Option<String>,
} }
/// Metadata about a thumbnail. /// Metadata about a thumbnail.

View File

@ -544,6 +544,15 @@ pub struct VideoInfo {
/// Information on the encrypted thumbnail file. Only present if the thumbnail is encrypted. /// Information on the encrypted thumbnail file. 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>>,
/// The [BlurHash](https://blurha.sh) for this video.
///
/// This uses the unstable prefix in
/// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448).
#[cfg(feature = "unstable-pre-spec")]
#[serde(rename = "xyz.amorgan.blurhash")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blurhash: Option<String>,
} }
/// The payload for a key verification request message. /// The payload for a key verification request message.

View File

@ -84,6 +84,8 @@ fn serialize_message_event() {
})), })),
thumbnail_url: Some("mxc://matrix.org".into()), thumbnail_url: Some("mxc://matrix.org".into()),
thumbnail_file: None, thumbnail_file: None,
#[cfg(feature = "unstable-pre-spec")]
blurhash: None,
}, },
url: "http://www.matrix.org".into(), url: "http://www.matrix.org".into(),
}, },

View File

@ -30,6 +30,8 @@ fn message_serialize_sticker() {
})), })),
thumbnail_url: Some("mxc://matrix.org".into()), thumbnail_url: Some("mxc://matrix.org".into()),
thumbnail_file: None, thumbnail_file: None,
#[cfg(feature = "unstable-pre-spec")]
blurhash: None,
}, },
url: "http://www.matrix.org".into(), url: "http://www.matrix.org".into(),
}), }),
@ -189,6 +191,8 @@ fn deserialize_message_sticker() {
thumbnail_info: Some(thumbnail_info), thumbnail_info: Some(thumbnail_info),
thumbnail_url: Some(thumbnail_url), thumbnail_url: Some(thumbnail_url),
thumbnail_file: None, thumbnail_file: None,
#[cfg(feature = "unstable-pre-spec")]
blurhash: None,
}, },
url, url,
}), }),

View File

@ -220,6 +220,8 @@ fn deserialize_avatar_without_prev_content() {
thumbnail_info: Some(thumbnail_info), thumbnail_info: Some(thumbnail_info),
thumbnail_url: Some(thumbnail_url), thumbnail_url: Some(thumbnail_url),
thumbnail_file: None, thumbnail_file: None,
#[cfg(feature = "unstable-pre-spec")]
blurhash: None,
} if *height == UInt::new(423) } if *height == UInt::new(423)
&& *width == UInt::new(1011) && *width == UInt::new(1011)
&& *mimetype == "image/png" && *mimetype == "image/png"