diff --git a/crates/ruma-client-api/src/r0/media/create_content.rs b/crates/ruma-client-api/src/r0/media/create_content.rs index fe0abc34..f7a86b85 100644 --- a/crates/ruma-client-api/src/r0/media/create_content.rs +++ b/crates/ruma-client-api/src/r0/media/create_content.rs @@ -26,6 +26,16 @@ ruma_api! { /// The content type of the file being uploaded. #[ruma_api(header = CONTENT_TYPE)] pub content_type: Option<&'a str>, + + /// Should the server return a blurhash or not. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). + #[ruma_api(query)] + #[cfg(feature = "unstable-pre-spec")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] + #[serde(rename = "xyz.amorgan.blurhash")] + pub generate_blurhash: bool, } response: { @@ -49,7 +59,13 @@ ruma_api! { impl<'a> Request<'a> { /// Creates a new `Request` with the given file contents. pub fn new(file: &'a [u8]) -> Self { - Self { file, filename: None, content_type: None } + Self { + file, + filename: None, + content_type: None, + #[cfg(feature = "unstable-pre-spec")] + generate_blurhash: false, + } } } diff --git a/crates/ruma-client-api/src/r0/profile/get_avatar_url.rs b/crates/ruma-client-api/src/r0/profile/get_avatar_url.rs index eceb77ed..4a21fc8e 100644 --- a/crates/ruma-client-api/src/r0/profile/get_avatar_url.rs +++ b/crates/ruma-client-api/src/r0/profile/get_avatar_url.rs @@ -30,7 +30,17 @@ ruma_api! { feature = "compat", serde(default, deserialize_with = "ruma_serde::empty_string_as_none") )] - pub avatar_url: Option + pub avatar_url: Option, + + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). + #[cfg(feature = "unstable-pre-spec")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] + #[serde(rename = "xyz.amorgan.blurhash")] + #[serde(skip_serializing_if = "Option::is_none")] + pub blurhash: Option, } error: crate::Error @@ -46,6 +56,10 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given avatar URL. pub fn new(avatar_url: Option) -> Self { - Self { avatar_url } + Self { + avatar_url, + #[cfg(feature = "unstable-pre-spec")] + blurhash: None, + } } } diff --git a/crates/ruma-client-api/src/r0/profile/get_profile.rs b/crates/ruma-client-api/src/r0/profile/get_profile.rs index 94a500a9..00ca2fbb 100644 --- a/crates/ruma-client-api/src/r0/profile/get_profile.rs +++ b/crates/ruma-client-api/src/r0/profile/get_profile.rs @@ -35,6 +35,16 @@ ruma_api! { /// The user's display name, if set. #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option, + + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). + #[cfg(feature = "unstable-pre-spec")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] + #[serde(rename = "xyz.amorgan.blurhash")] + #[serde(skip_serializing_if = "Option::is_none")] + pub blurhash: Option, } error: crate::Error @@ -50,6 +60,11 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given avatar URL and display name. pub fn new(avatar_url: Option, displayname: Option) -> Self { - Self { avatar_url, displayname } + Self { + avatar_url, + displayname, + #[cfg(feature = "unstable-pre-spec")] + blurhash: None, + } } } diff --git a/crates/ruma-client-api/src/r0/profile/set_avatar_url.rs b/crates/ruma-client-api/src/r0/profile/set_avatar_url.rs index 026f9021..6206c409 100644 --- a/crates/ruma-client-api/src/r0/profile/set_avatar_url.rs +++ b/crates/ruma-client-api/src/r0/profile/set_avatar_url.rs @@ -37,6 +37,16 @@ ruma_api! { serde(skip_serializing_if = "Option::is_none") )] pub avatar_url: Option<&'a MxcUri>, + + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). + #[cfg(feature = "unstable-pre-spec")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] + #[serde(rename = "xyz.amorgan.blurhash")] + #[serde(skip_serializing_if = "Option::is_none")] + pub blurhash: Option<&'a str>, } #[derive(Default)] @@ -48,7 +58,12 @@ ruma_api! { impl<'a> Request<'a> { /// Creates a new `Request` with the given user ID and avatar URL. pub fn new(user_id: &'a UserId, avatar_url: Option<&'a MxcUri>) -> Self { - Self { user_id, avatar_url } + Self { + user_id, + avatar_url, + #[cfg(feature = "unstable-pre-spec")] + blurhash: None, + } } } @@ -75,7 +90,7 @@ mod tests { .uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url") .body(&[] as &[u8]).unwrap(), ).unwrap(), - IncomingRequest { user_id, avatar_url: None } if user_id == "@foo:bar.org" + IncomingRequest { user_id, avatar_url: None, .. } if user_id == "@foo:bar.org" ); #[cfg(feature = "compat")] @@ -87,7 +102,7 @@ mod tests { .body(serde_json::to_vec(&serde_json::json!({ "avatar_url": "" })).unwrap()) .unwrap(), ).unwrap(), - IncomingRequest { user_id, avatar_url: None } if user_id == "@foo:bar.org" + IncomingRequest { user_id, avatar_url: None, .. } if user_id == "@foo:bar.org" ); } } diff --git a/crates/ruma-events/src/room/member.rs b/crates/ruma-events/src/room/member.rs index d07a0daa..2f8916e6 100644 --- a/crates/ruma-events/src/room/member.rs +++ b/crates/ruma-events/src/room/member.rs @@ -69,6 +69,16 @@ pub struct MemberEventContent { /// contain information about that invitation. #[serde(skip_serializing_if = "Option::is_none")] pub third_party_invite: Option, + + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). + #[cfg(feature = "unstable-pre-spec")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] + #[serde(rename = "xyz.amorgan.blurhash")] + #[serde(skip_serializing_if = "Option::is_none")] + pub blurhash: Option, } impl MemberEventContent { @@ -80,6 +90,8 @@ impl MemberEventContent { displayname: None, is_direct: None, third_party_invite: None, + #[cfg(feature = "unstable-pre-spec")] + blurhash: None, } } } @@ -227,6 +239,8 @@ fn membership_change( is_direct: None, membership: St::Leave, third_party_invite: None, + #[cfg(feature = "unstable-pre-spec")] + blurhash: None, } }; @@ -326,6 +340,7 @@ mod tests { is_direct: None, membership: MembershipState::Join, third_party_invite: None, + .. }, event_id, origin_server_ts, @@ -372,6 +387,7 @@ mod tests { is_direct: None, membership: MembershipState::Join, third_party_invite: None, + .. }, event_id, origin_server_ts, @@ -385,6 +401,7 @@ mod tests { is_direct: None, membership: MembershipState::Join, third_party_invite: None, + .. }), } if event_id == "$h29iv0s8:example.com" && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1)) @@ -439,6 +456,7 @@ mod tests { display_name: third_party_displayname, signed: SignedContent { mxid, signatures, token }, }), + .. }, event_id, origin_server_ts, @@ -510,6 +528,7 @@ mod tests { is_direct: None, membership: MembershipState::Join, third_party_invite: None, + .. }, event_id, origin_server_ts, @@ -526,6 +545,7 @@ mod tests { display_name: third_party_displayname, signed: SignedContent { mxid, signatures, token }, }), + .. }), } if event_id == "$143273582443PhrSn:example.org" && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(233)) @@ -586,6 +606,7 @@ mod tests { is_direct: None, membership: MembershipState::Join, third_party_invite: None, + .. }, event_id, origin_server_ts, @@ -602,6 +623,7 @@ mod tests { display_name: third_party_displayname, signed: SignedContent { mxid, signatures, token }, }), + .. }), } if event_id == "$143273582443PhrSn:example.org" && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(233)) diff --git a/crates/ruma-federation-api/src/query/get_profile_information/v1.rs b/crates/ruma-federation-api/src/query/get_profile_information/v1.rs index 18b9b587..9d42fb18 100644 --- a/crates/ruma-federation-api/src/query/get_profile_information/v1.rs +++ b/crates/ruma-federation-api/src/query/get_profile_information/v1.rs @@ -41,6 +41,16 @@ ruma_api! { serde(default, deserialize_with = "ruma_serde::empty_string_as_none") )] pub avatar_url: Option, + + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). + #[cfg(feature = "unstable-pre-spec")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] + #[serde(rename = "xyz.amorgan.blurhash")] + #[serde(skip_serializing_if = "Option::is_none")] + pub blurhash: Option, } }