ruma_federation_api/device/
get_devices.rs

1//! `GET /_matrix/federation/*/user/devices/{userId}`
2//!
3//! Get information about a user's devices.
4
5pub mod v1 {
6    //! `/v1/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixfederationv1userdevicesuserid
9
10    use js_int::UInt;
11    use ruma_common::{
12        api::{request, response, Metadata},
13        encryption::{CrossSigningKey, DeviceKeys},
14        metadata,
15        serde::Raw,
16        OwnedDeviceId, OwnedUserId,
17    };
18    use serde::{Deserialize, Serialize};
19
20    const METADATA: Metadata = metadata! {
21        method: GET,
22        rate_limited: false,
23        authentication: ServerSignatures,
24        history: {
25            1.0 => "/_matrix/federation/v1/user/devices/:user_id",
26        }
27    };
28
29    /// Request type for the `get_devices` endpoint.
30    #[request]
31    pub struct Request {
32        /// The user ID to retrieve devices for.
33        ///
34        /// Must be a user local to the receiving homeserver.
35        #[ruma_api(path)]
36        pub user_id: OwnedUserId,
37    }
38
39    /// Response type for the `get_devices` endpoint.
40    #[response]
41    pub struct Response {
42        /// The user ID devices were requested for.
43        pub user_id: OwnedUserId,
44
45        /// A unique ID for a given user_id which describes the version of the returned device
46        /// list.
47        ///
48        /// This is matched with the `stream_id` field in `m.device_list_update` EDUs in order to
49        /// incrementally update the returned device_list.
50        pub stream_id: UInt,
51
52        /// The user's devices.
53        pub devices: Vec<UserDevice>,
54
55        /// The user's master key.
56        #[serde(skip_serializing_if = "Option::is_none")]
57        pub master_key: Option<Raw<CrossSigningKey>>,
58
59        /// The users's self-signing key.
60        #[serde(skip_serializing_if = "Option::is_none")]
61        pub self_signing_key: Option<Raw<CrossSigningKey>>,
62    }
63
64    impl Request {
65        /// Creates a new `Request` with the given user id.
66        pub fn new(user_id: OwnedUserId) -> Self {
67            Self { user_id }
68        }
69    }
70
71    impl Response {
72        /// Creates a new `Response` with the given user id and stream id.
73        ///
74        /// The device list will be empty.
75        pub fn new(user_id: OwnedUserId, stream_id: UInt) -> Self {
76            Self {
77                user_id,
78                stream_id,
79                devices: Vec::new(),
80                master_key: None,
81                self_signing_key: None,
82            }
83        }
84    }
85
86    /// Information about a user's device.
87    #[derive(Clone, Debug, Serialize, Deserialize)]
88    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
89    pub struct UserDevice {
90        /// The device ID.
91        pub device_id: OwnedDeviceId,
92
93        /// Identity keys for the device.
94        pub keys: Raw<DeviceKeys>,
95
96        /// Optional display name for the device
97        #[serde(skip_serializing_if = "Option::is_none")]
98        pub device_display_name: Option<String>,
99    }
100
101    impl UserDevice {
102        /// Creates a new `UserDevice` with the given device id and keys.
103        pub fn new(device_id: OwnedDeviceId, keys: Raw<DeviceKeys>) -> Self {
104            Self { device_id, keys, device_display_name: None }
105        }
106    }
107}