ruma_client_api/server/
get_user_info.rs1pub mod v3 {
6 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(error = crate::Error)]
31 pub struct Request {
32 #[ruma_api(path)]
34 pub user_id: OwnedUserId,
35 }
36
37 #[response(error = crate::Error)]
39 #[derive(Default)]
40 pub struct Response {
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub user_id: Option<OwnedUserId>,
44
45 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
47 pub devices: BTreeMap<String, DeviceInfo>,
48 }
49
50 impl Request {
51 pub fn new(user_id: OwnedUserId) -> Self {
53 Self { user_id }
54 }
55 }
56
57 impl Response {
58 pub fn new() -> Self {
60 Default::default()
61 }
62 }
63
64 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
66 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
67 pub struct DeviceInfo {
68 #[serde(default, skip_serializing_if = "Vec::is_empty")]
70 pub sessions: Vec<SessionInfo>,
71 }
72
73 impl DeviceInfo {
74 pub fn new() -> Self {
76 Self::default()
77 }
78 }
79
80 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
82 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
83 pub struct SessionInfo {
84 #[serde(default, skip_serializing_if = "Vec::is_empty")]
86 pub connections: Vec<ConnectionInfo>,
87 }
88
89 impl SessionInfo {
90 pub fn new() -> Self {
92 Self::default()
93 }
94 }
95
96 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
98 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
99 pub struct ConnectionInfo {
100 pub ip: Option<String>,
102
103 pub last_seen: Option<MilliSecondsSinceUnixEpoch>,
105
106 pub user_agent: Option<String>,
108 }
109
110 impl ConnectionInfo {
111 pub fn new() -> Self {
113 Self::default()
114 }
115 }
116}