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        api::{request, response},
12        metadata, OwnedUserId,
13    };
14
15    metadata! {
16        method: GET,
17        rate_limited: false,
18        authentication: NoAuthentication,
19        history: {
20            1.0 => "/_matrix/client/r0/profile/{user_id}/displayname",
21            1.1 => "/_matrix/client/v3/profile/{user_id}/displayname",
22        }
23    }
24
25    /// Request type for the `get_display_name` endpoint.
26    #[request(error = crate::Error)]
27    pub struct Request {
28        /// The user whose display name will be retrieved.
29        #[ruma_api(path)]
30        pub user_id: OwnedUserId,
31    }
32
33    /// Response type for the `get_display_name` endpoint.
34    #[response(error = crate::Error)]
35    #[derive(Default)]
36    pub struct Response {
37        /// The user's display name, if set.
38        #[serde(skip_serializing_if = "Option::is_none")]
39        pub displayname: Option<String>,
40    }
41
42    impl Request {
43        /// Creates a new `Request` with the given user ID.
44        #[deprecated = "Use the get_profile_field endpoint instead."]
45        pub fn new(user_id: OwnedUserId) -> Self {
46            Self { user_id }
47        }
48    }
49
50    impl Response {
51        /// Creates a new `Response` with the given display name.
52        pub fn new(displayname: Option<String>) -> Self {
53            Self { displayname }
54        }
55    }
56}