ruma_client_api/profile/
get_display_name.rs

1//! `GET /_matrix/client/*/profile/{userId}/displayname`
2//!
3//! Get the display name of a user.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv3profileuseriddisplayname
9
10    use ruma_common::{
11        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}/displayname",
22            1.1 => "/_matrix/client/v3/profile/{user_id}/displayname",
23        }
24    }
25
26    /// Request type for the `get_display_name` endpoint.
27    #[request(error = crate::Error)]
28    pub struct Request {
29        /// The user whose display name will be retrieved.
30        #[ruma_api(path)]
31        pub user_id: OwnedUserId,
32    }
33
34    /// Response type for the `get_display_name` endpoint.
35    #[response(error = crate::Error)]
36    #[derive(Default)]
37    pub struct Response {
38        /// The user's display name, if set.
39        #[serde(skip_serializing_if = "Option::is_none")]
40        pub displayname: Option<String>,
41    }
42
43    impl Request {
44        /// Creates a new `Request` with the given user ID.
45        #[deprecated = "Use the get_profile_field endpoint instead."]
46        pub fn new(user_id: OwnedUserId) -> Self {
47            Self { user_id }
48        }
49    }
50
51    impl Response {
52        /// Creates a new `Response` with the given display name.
53        pub fn new(displayname: Option<String>) -> Self {
54            Self { displayname }
55        }
56    }
57}