ruma_client_api/account/
whoami.rs

1//! `GET /_matrix/client/*/account/whoami`
2//!
3//! Get information about the owner of a given access token.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3accountwhoami
9
10    use ruma_common::{
11        OwnedDeviceId, OwnedUserId,
12        api::{auth_scheme::AccessToken, request, response},
13        metadata,
14    };
15
16    metadata! {
17        method: GET,
18        rate_limited: true,
19        authentication: AccessToken,
20        history: {
21            1.0 => "/_matrix/client/r0/account/whoami",
22            1.1 => "/_matrix/client/v3/account/whoami",
23        }
24    }
25
26    /// Request type for the `whoami` endpoint.
27    #[request(error = crate::Error)]
28    #[derive(Default)]
29    pub struct Request {}
30
31    /// Response type for the `whoami` endpoint.
32    #[response(error = crate::Error)]
33    pub struct Response {
34        /// The id of the user that owns the access token.
35        pub user_id: OwnedUserId,
36
37        /// The device ID associated with the access token, if any.
38        #[serde(skip_serializing_if = "Option::is_none")]
39        pub device_id: Option<OwnedDeviceId>,
40
41        /// If `true`, the user is a guest user.
42        #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
43        pub is_guest: bool,
44    }
45
46    impl Request {
47        /// Creates an empty `Request`.
48        pub fn new() -> Self {
49            Self {}
50        }
51    }
52
53    impl Response {
54        /// Creates a new `Response` with the given user ID.
55        pub fn new(user_id: OwnedUserId, is_guest: bool) -> Self {
56            Self { user_id, device_id: None, is_guest }
57        }
58    }
59}