diff --git a/CHANGELOG.md b/CHANGELOG.md index 4748c444..190392f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,3 +19,4 @@ Improvements: * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 * Add optional `auth` field +* Add `r0::device` endpoints diff --git a/src/r0.rs b/src/r0.rs index 2bd7ab9d..1a57c5f9 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -6,6 +6,7 @@ pub mod appservice; pub mod config; pub mod contact; pub mod context; +pub mod device; pub mod directory; pub mod filter; pub mod media; diff --git a/src/r0/account/register.rs b/src/r0/account/register.rs index 7c06297b..3ab0a9c5 100644 --- a/src/r0/account/register.rs +++ b/src/r0/account/register.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register) use ruma_api::ruma_api; -use ruma_identifiers::UserId; +use ruma_identifiers::{DeviceId, UserId}; use serde::{Deserialize, Serialize}; use super::AuthenticationData; @@ -37,7 +37,7 @@ ruma_api! { /// If this does not correspond to a known client device, a new device will be created. /// The server will auto-generate a device_id if this is not specified. #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, + pub device_id: Option, /// A display name to assign to the newly-created device. /// /// Ignored if `device_id` corresponds to a known device. @@ -71,7 +71,7 @@ ruma_api! { /// ID of the registered device. /// /// Will be the same as the corresponding parameter in the request, if one was specified. - pub device_id: String, + pub device_id: DeviceId, } } diff --git a/src/r0/device.rs b/src/r0/device.rs new file mode 100644 index 00000000..11c27344 --- /dev/null +++ b/src/r0/device.rs @@ -0,0 +1,24 @@ +//! Endpoints for managing devices. + +use js_int::UInt; +use ruma_identifiers::DeviceId; +use serde::{Deserialize, Serialize}; + +pub mod delete_device; +pub mod delete_devices; +pub mod get_device; +pub mod get_devices; +pub mod update_device; + +/// Information about a registered device. +#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)] +pub struct Device { + /// Device ID + pub device_id: DeviceId, + /// Public display name of the device. + pub display_name: Option, + /// Most recently seen IP address of the session. + pub ip: Option, + /// Unix timestamp that the session was last active. + pub last_seen: Option, +} diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs new file mode 100644 index 00000000..bea045e4 --- /dev/null +++ b/src/r0/device/delete_device.rs @@ -0,0 +1,25 @@ +//! [DELETE /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-devices-deviceid) + +use crate::r0::account::AuthenticationData; +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; + +ruma_api! { + metadata { + description: "Delete a device for authenticated user.", + method: DELETE, + name: "delete_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + #[serde(skip_serializing_if = "Option::is_none")] + auth: Option, + } + + response {} +} diff --git a/src/r0/device/delete_devices.rs b/src/r0/device/delete_devices.rs new file mode 100644 index 00000000..2adf8ea5 --- /dev/null +++ b/src/r0/device/delete_devices.rs @@ -0,0 +1,27 @@ +//! [POST /_matrix/client/r0/delete_devices](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-delete-devices) + +use crate::r0::account::AuthenticationData; +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; + +ruma_api! { + metadata { + description: "Delete specified devices.", + method: POST, + path: "/_matrix/client/r0/delete_devices", + name: "delete_devices", + rate_limited: false, + requires_authentication: true, + } + + request { + /// List of devices to delete. + devices: Vec, + + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + auth: Option, + } + + response {} +} diff --git a/src/r0/device/get_device.rs b/src/r0/device/get_device.rs new file mode 100644 index 00000000..8f064083 --- /dev/null +++ b/src/r0/device/get_device.rs @@ -0,0 +1,25 @@ +//! [GET /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices-deviceid) + +use super::Device; +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; + +ruma_api! { + metadata { + description: "Get a device for authenticated user.", + method: GET, + name: "get_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + } + + response { + device: Device, + } +} diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs new file mode 100644 index 00000000..4419d369 --- /dev/null +++ b/src/r0/device/get_devices.rs @@ -0,0 +1,21 @@ +//! [GET /_matrix/client/r0/devices](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices) + +use super::Device; +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "Get registered devices for authenticated user.", + method: GET, + name: "get_devices", + path: "/_matrix/client/r0/devices", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + devices: Vec, + } +} diff --git a/src/r0/device/update_device.rs b/src/r0/device/update_device.rs new file mode 100644 index 00000000..2d3db701 --- /dev/null +++ b/src/r0/device/update_device.rs @@ -0,0 +1,24 @@ +//! [PUT /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-devices-deviceid) + +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; + +ruma_api! { + metadata { + description: "Update metadata for a device.", + method: PUT, + name: "update_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + #[serde(skip_serializing_if = "Option::is_none")] + display_name: Option, + } + + response {} +} diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index 720ad1a5..01dea6ed 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login) use ruma_api::ruma_api; -use ruma_identifiers::UserId; +use ruma_identifiers::{DeviceId, UserId}; use serde::{Deserialize, Serialize}; ruma_api! { @@ -30,7 +30,7 @@ ruma_api! { pub address: Option, /// ID of the client device #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, + pub device_id: Option, } response {