1//! `GET /_matrix/client/*/admin/whois/{userId}`
2//!
3//! Get information about a particular user.
45pub mod v3 {
6//! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3adminwhoisuserid
910use std::collections::BTreeMap;
1112use ruma_common::{
13 api::{request, response, Metadata},
14 metadata, MilliSecondsSinceUnixEpoch, OwnedUserId,
15 };
16use serde::{Deserialize, Serialize};
1718const METADATA: Metadata = metadata! {
19 method: GET,
20 rate_limited: false,
21 authentication: AccessToken,
22 history: {
231.0 => "/_matrix/client/r0/admin/whois/:user_id",
241.1 => "/_matrix/client/v3/admin/whois/:user_id",
25 }
26 };
2728/// Request type for the `get_user_info` endpoint.
29#[request(error = crate::Error)]
30pub struct Request {
31/// The user to look up.
32#[ruma_api(path)]
33pub user_id: OwnedUserId,
34 }
3536/// Response type for the `get_user_info` endpoint.
37#[response(error = crate::Error)]
38 #[derive(Default)]
39pub struct Response {
40/// The Matrix user ID of the user.
41#[serde(skip_serializing_if = "Option::is_none")]
42pub user_id: Option<OwnedUserId>,
4344/// A map of the user's device identifiers to information about that device.
45#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
46pub devices: BTreeMap<String, DeviceInfo>,
47 }
4849impl Request {
50/// Creates a new `Request` with the given user id.
51pub fn new(user_id: OwnedUserId) -> Self {
52Self { user_id }
53 }
54 }
5556impl Response {
57/// Creates an empty `Response`.
58pub fn new() -> Self {
59 Default::default()
60 }
61 }
6263/// Information about a user's device.
64#[derive(Clone, Debug, Default, Deserialize, Serialize)]
65 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
66pub struct DeviceInfo {
67/// A list of user sessions on this device.
68#[serde(default, skip_serializing_if = "Vec::is_empty")]
69pub sessions: Vec<SessionInfo>,
70 }
7172impl DeviceInfo {
73/// Create a new `DeviceInfo` with no sessions.
74pub fn new() -> Self {
75Self::default()
76 }
77 }
7879/// Information about a user session.
80#[derive(Clone, Debug, Default, Deserialize, Serialize)]
81 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
82pub struct SessionInfo {
83/// A list of connections in this session.
84#[serde(default, skip_serializing_if = "Vec::is_empty")]
85pub connections: Vec<ConnectionInfo>,
86 }
8788impl SessionInfo {
89/// Create a new `SessionInfo` with no connections.
90pub fn new() -> Self {
91Self::default()
92 }
93 }
9495/// 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)]
98pub struct ConnectionInfo {
99/// Most recently seen IP address of the session.
100pub ip: Option<String>,
101102/// Time when that the session was last active.
103pub last_seen: Option<MilliSecondsSinceUnixEpoch>,
104105/// User agent string last seen in the session.
106pub user_agent: Option<String>,
107 }
108109impl ConnectionInfo {
110/// Create a new `ConnectionInfo` with all fields set to `None`.
111pub fn new() -> Self {
112Self::default()
113 }
114 }
115}