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