ruma_federation_api/query/
get_profile_information.rs

1//! `GET /_matrix/federation/*/query/profile`
2//!
3//! Get profile information, such as a display name or avatar, for a given user.
4
5pub mod v1 {
6    //! `/v1/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixfederationv1queryprofile
9
10    use ruma_common::{
11        api::{request, response},
12        metadata,
13        serde::StringEnum,
14        OwnedMxcUri, OwnedUserId,
15    };
16
17    use crate::{authentication::ServerSignatures, PrivOwnedStr};
18
19    metadata! {
20        method: GET,
21        rate_limited: false,
22        authentication: ServerSignatures,
23        path: "/_matrix/federation/v1/query/profile",
24    }
25
26    /// Request type for the `get_profile_information` endpoint.
27    #[request]
28    pub struct Request {
29        /// User ID to query.
30        #[ruma_api(query)]
31        pub user_id: OwnedUserId,
32
33        /// Profile field to query.
34        #[serde(skip_serializing_if = "Option::is_none")]
35        #[ruma_api(query)]
36        pub field: Option<ProfileField>,
37    }
38
39    /// Response type for the `get_profile_information` endpoint.
40    #[response]
41    #[derive(Default)]
42    pub struct Response {
43        /// Display name of the user.
44        #[serde(skip_serializing_if = "Option::is_none")]
45        pub displayname: Option<String>,
46
47        /// Avatar URL for the user's avatar.
48        ///
49        /// If you activate the `compat-empty-string-null` feature, this field being an empty
50        /// string in JSON will result in `None` here during deserialization.
51        #[serde(skip_serializing_if = "Option::is_none")]
52        #[cfg_attr(
53            feature = "compat-empty-string-null",
54            serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
55        )]
56        pub avatar_url: Option<OwnedMxcUri>,
57
58        /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`.
59        ///
60        /// This uses the unstable prefix in
61        /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448).
62        #[cfg(feature = "unstable-msc2448")]
63        #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")]
64        pub blurhash: Option<String>,
65    }
66
67    impl Request {
68        /// Creates a new `Request` with the given user id.
69        pub fn new(user_id: OwnedUserId) -> Self {
70            Self { user_id, field: None }
71        }
72    }
73
74    impl Response {
75        /// Creates an empty `Response`.
76        pub fn new() -> Self {
77            Default::default()
78        }
79    }
80
81    /// Profile fields to specify in query.
82    ///
83    /// This type can hold an arbitrary string. To build this with a custom value, convert it from a
84    /// string with `::from()` / `.into()`. To check for values that are not available as a
85    /// documented variant here, use its string representation, obtained through
86    /// [`.as_str()`](Self::as_str()).
87    #[derive(Clone, StringEnum)]
88    #[non_exhaustive]
89    pub enum ProfileField {
90        /// Display name of the user.
91        #[ruma_enum(rename = "displayname")]
92        DisplayName,
93
94        /// Avatar URL for the user's avatar.
95        #[ruma_enum(rename = "avatar_url")]
96        AvatarUrl,
97
98        #[doc(hidden)]
99        _Custom(PrivOwnedStr),
100    }
101}