Update endpoints for blurhash implementation

* Add blurhash to profile and avatar endpoints.
* Add `blurhash` fields to `GET /_matrix/federation/v1/query/profile`
  and `m.room.member`.
* Add `generate_blurhash` field to `PUT /_matrix/media/r0/upload`
This commit is contained in:
Adam 2021-07-04 17:38:06 +01:00 committed by GitHub
parent 384161d462
commit 118ea0f85a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 7 deletions

View File

@ -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,
}
}
}

View File

@ -30,7 +30,17 @@ ruma_api! {
feature = "compat",
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
)]
pub avatar_url: Option<MxcUri>
pub avatar_url: Option<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<String>,
}
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<MxcUri>) -> Self {
Self { avatar_url }
Self {
avatar_url,
#[cfg(feature = "unstable-pre-spec")]
blurhash: None,
}
}
}

View File

@ -35,6 +35,16 @@ ruma_api! {
/// The user's display name, if set.
#[serde(skip_serializing_if = "Option::is_none")]
pub displayname: Option<String>,
/// 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<String>,
}
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<MxcUri>, displayname: Option<String>) -> Self {
Self { avatar_url, displayname }
Self {
avatar_url,
displayname,
#[cfg(feature = "unstable-pre-spec")]
blurhash: None,
}
}
}

View File

@ -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"
);
}
}

View File

@ -69,6 +69,16 @@ pub struct MemberEventContent {
/// contain information about that invitation.
#[serde(skip_serializing_if = "Option::is_none")]
pub third_party_invite: Option<ThirdPartyInvite>,
/// 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<String>,
}
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))

View File

@ -41,6 +41,16 @@ ruma_api! {
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
)]
pub avatar_url: Option<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<String>,
}
}