ruma_client_api/profile/get_avatar_url.rs
1//! `GET /_matrix/client/*/profile/{userId}/avatar_url`
2//!
3//! Get the avatar URL of a user.
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv3profileuseridavatar_url
9
10 use ruma_common::{
11 OwnedMxcUri, OwnedUserId,
12 api::{auth_scheme::NoAuthentication, request, response},
13 metadata,
14 };
15
16 metadata! {
17 method: GET,
18 rate_limited: false,
19 authentication: NoAuthentication,
20 history: {
21 1.0 => "/_matrix/client/r0/profile/{user_id}/avatar_url",
22 1.1 => "/_matrix/client/v3/profile/{user_id}/avatar_url",
23 }
24 }
25
26 /// Request type for the `get_avatar_url` endpoint.
27 #[request(error = crate::Error)]
28 pub struct Request {
29 /// The user whose avatar URL will be retrieved.
30 #[ruma_api(path)]
31 pub user_id: OwnedUserId,
32 }
33
34 /// Response type for the `get_avatar_url` endpoint.
35 #[response(error = crate::Error)]
36 #[derive(Default)]
37 pub struct Response {
38 /// The user's avatar URL, if set.
39 ///
40 /// If you activate the `compat-empty-string-null` feature, this field being an empty
41 /// string in JSON will result in `None` here during deserialization.
42 #[serde(skip_serializing_if = "Option::is_none")]
43 #[cfg_attr(
44 feature = "compat-empty-string-null",
45 serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
46 )]
47 pub avatar_url: Option<OwnedMxcUri>,
48
49 /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`.
50 ///
51 /// This uses the unstable prefix in
52 /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448).
53 #[cfg(feature = "unstable-msc2448")]
54 #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")]
55 pub blurhash: Option<String>,
56 }
57
58 impl Request {
59 /// Creates a new `Request` with the given user ID.
60 #[deprecated = "Use the get_profile_field endpoint instead."]
61 pub fn new(user_id: OwnedUserId) -> Self {
62 Self { user_id }
63 }
64 }
65
66 impl Response {
67 /// Creates a new `Response` with the given avatar URL.
68 pub fn new(avatar_url: Option<OwnedMxcUri>) -> Self {
69 Self {
70 avatar_url,
71 #[cfg(feature = "unstable-msc2448")]
72 blurhash: None,
73 }
74 }
75 }
76}