Skip to main content

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