Skip to main content

ruma_client_api/profile/
set_display_name.rs

1//! `PUT /_matrix/client/*/profile/{userId}/displayname`
2//!
3//! Set the display name of the user.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/v1.15/client-server-api/#put_matrixclientv3profileuseriddisplayname
9
10    use ruma_common::{
11        OwnedUserId,
12        api::{auth_scheme::AccessToken, request, response},
13        metadata,
14    };
15
16    #[cfg(feature = "unstable-msc4466")]
17    use crate::profile::PropagateTo;
18
19    metadata! {
20        method: PUT,
21        rate_limited: true,
22        authentication: AccessToken,
23        history: {
24            1.0 => "/_matrix/client/r0/profile/{user_id}/displayname",
25            1.1 => "/_matrix/client/v3/profile/{user_id}/displayname",
26        }
27    }
28
29    /// Request type for the `set_display_name` endpoint.
30    #[request]
31    pub struct Request {
32        /// The user whose display name will be set.
33        #[ruma_api(path)]
34        pub user_id: OwnedUserId,
35
36        /// The new display name for the user.
37        #[serde(skip_serializing_if = "Option::is_none")]
38        pub displayname: Option<String>,
39
40        /// The propagation mode to use for this profile update.
41        #[cfg(feature = "unstable-msc4466")]
42        #[ruma_api(query)]
43        #[serde(rename = "computer.gingershaped.msc4466.propagate_to")]
44        #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
45        pub propagate_to: PropagateTo,
46    }
47
48    /// Response type for the `set_display_name` endpoint.
49    #[response]
50    #[derive(Default)]
51    pub struct Response {}
52
53    impl Request {
54        /// Creates a new `Request` with the given user ID and display name.
55        #[deprecated = "Use the set_profile_field endpoint instead."]
56        pub fn new(user_id: OwnedUserId, displayname: Option<String>) -> Self {
57            Self {
58                user_id,
59                displayname,
60                #[cfg(feature = "unstable-msc4466")]
61                propagate_to: PropagateTo::default(),
62            }
63        }
64    }
65
66    impl Response {
67        /// Creates an empty `Response`.
68        pub fn new() -> Self {
69            Self {}
70        }
71    }
72}