use std::collections::BTreeMap;
use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::UserId;
use serde::{Deserialize, Serialize};
ruma_api! {
metadata: {
description: "Get information about a particular user.",
method: GET,
name: "get_user_info",
path: "/_matrix/client/r0/admin/whois/:user_id",
rate_limited: false,
authentication: AccessToken,
}
request: {
#[ruma_api(path)]
pub user_id: &'a UserId,
}
#[derive(Default)]
response: {
#[serde(skip_serializing_if = "Option::is_none")]
pub user_id: Option<UserId>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub devices: BTreeMap<String, DeviceInfo>,
}
error: crate::Error
}
impl<'a> Request<'a> {
pub fn new(user_id: &'a UserId) -> Self {
Self { user_id }
}
}
impl Response {
pub fn new() -> Self {
Default::default()
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct DeviceInfo {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub sessions: Vec<SessionInfo>,
}
impl DeviceInfo {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct SessionInfo {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub connections: Vec<ConnectionInfo>,
}
impl SessionInfo {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct ConnectionInfo {
pub ip: Option<String>,
pub last_seen: Option<MilliSecondsSinceUnixEpoch>,
pub user_agent: Option<String>,
}
impl ConnectionInfo {
pub fn new() -> Self {
Self::default()
}
}