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