ruma_client_api/server/
get_user_info.rs

1//! `GET /_matrix/client/*/admin/whois/{userId}`
2//!
3//! Get information about a particular user.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3adminwhoisuserid
9
10    use std::collections::BTreeMap;
11
12    use ruma_common::{
13        MilliSecondsSinceUnixEpoch, OwnedUserId,
14        api::{auth_scheme::AccessToken, request, response},
15        metadata,
16    };
17    use serde::{Deserialize, Serialize};
18
19    metadata! {
20        method: GET,
21        rate_limited: false,
22        authentication: AccessToken,
23        history: {
24            1.0 => "/_matrix/client/r0/admin/whois/{user_id}",
25            1.1 => "/_matrix/client/v3/admin/whois/{user_id}",
26        }
27    }
28
29    /// Request type for the `get_user_info` endpoint.
30    #[request(error = crate::Error)]
31    pub struct Request {
32        /// The user to look up.
33        #[ruma_api(path)]
34        pub user_id: OwnedUserId,
35    }
36
37    /// Response type for the `get_user_info` endpoint.
38    #[response(error = crate::Error)]
39    #[derive(Default)]
40    pub struct Response {
41        /// The Matrix user ID of the user.
42        #[serde(skip_serializing_if = "Option::is_none")]
43        pub user_id: Option<OwnedUserId>,
44
45        /// A map of the user's device identifiers to information about that device.
46        #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
47        pub devices: BTreeMap<String, DeviceInfo>,
48    }
49
50    impl Request {
51        /// Creates a new `Request` with the given user id.
52        pub fn new(user_id: OwnedUserId) -> Self {
53            Self { user_id }
54        }
55    }
56
57    impl Response {
58        /// Creates an empty `Response`.
59        pub fn new() -> Self {
60            Default::default()
61        }
62    }
63
64    /// Information about a user's device.
65    #[derive(Clone, Debug, Default, Deserialize, Serialize)]
66    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
67    pub struct DeviceInfo {
68        /// A list of user sessions on this device.
69        #[serde(default, skip_serializing_if = "Vec::is_empty")]
70        pub sessions: Vec<SessionInfo>,
71    }
72
73    impl DeviceInfo {
74        /// Create a new `DeviceInfo` with no sessions.
75        pub fn new() -> Self {
76            Self::default()
77        }
78    }
79
80    /// Information about a user session.
81    #[derive(Clone, Debug, Default, Deserialize, Serialize)]
82    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
83    pub struct SessionInfo {
84        /// A list of connections in this session.
85        #[serde(default, skip_serializing_if = "Vec::is_empty")]
86        pub connections: Vec<ConnectionInfo>,
87    }
88
89    impl SessionInfo {
90        /// Create a new `SessionInfo` with no connections.
91        pub fn new() -> Self {
92            Self::default()
93        }
94    }
95
96    /// Information about a connection in a user session.
97    #[derive(Clone, Debug, Default, Deserialize, Serialize)]
98    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
99    pub struct ConnectionInfo {
100        /// Most recently seen IP address of the session.
101        pub ip: Option<String>,
102
103        /// Time when that the session was last active.
104        pub last_seen: Option<MilliSecondsSinceUnixEpoch>,
105
106        /// User agent string last seen in the session.
107        pub user_agent: Option<String>,
108    }
109
110    impl ConnectionInfo {
111        /// Create a new `ConnectionInfo` with all fields set to `None`.
112        pub fn new() -> Self {
113            Self::default()
114        }
115    }
116}