diff --git a/CHANGELOG.md b/CHANGELOG.md index d811a283..fd0b93e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Improvements: * Add `r0::device` endpoints * Add `r0::room::get_room_event` (introduced in r0.4.0) * Add `r0::read_marker::set_read_marker` (introduced in r0.4.0) +* Add `r0::capabilities::get_capabilities` (introduced in r0.5.0) # 0.5.0 diff --git a/src/r0.rs b/src/r0.rs index cf8718c4..93415eb7 100644 --- a/src/r0.rs +++ b/src/r0.rs @@ -3,6 +3,7 @@ pub mod account; pub mod alias; pub mod appservice; +pub mod capabilities; pub mod config; pub mod contact; pub mod context; diff --git a/src/r0/capabilities.rs b/src/r0/capabilities.rs new file mode 100644 index 00000000..a0774dd8 --- /dev/null +++ b/src/r0/capabilities.rs @@ -0,0 +1,3 @@ +//! Endpoints for querying the server's supported feature set + +pub mod get_capabilities; diff --git a/src/r0/capabilities/get_capabilities.rs b/src/r0/capabilities/get_capabilities.rs new file mode 100644 index 00000000..b657e207 --- /dev/null +++ b/src/r0/capabilities/get_capabilities.rs @@ -0,0 +1,70 @@ +//! [GET /_matrix/client/r0/capabilities](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-capabilities) + +use ruma_api::ruma_api; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::collections::HashMap; + +ruma_api! { + metadata { + description: "Gets information about the server's supported feature set and other relevant capabilities.", + method: GET, + name: "get_capabilities", + path: "/_matrix/client/r0/capabilities", + rate_limited: true, + requires_authentication: true + } + + request {} + + response { + /// The capabilities the server supports + pub capabilities: Capabilities, + } +} + +/// Contains information about all the capabilities that the server supports. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Capabilities { + /// Capability to indicate if the user can change their password. + #[serde(rename = "m.change_password", skip_serializing_if = "Option::is_none")] + pub change_password: Option, + + /// The room versions the server supports. + #[serde(rename = "m.room_versions", skip_serializing_if = "Option::is_none")] + pub room_versions: Option, + + /// Any other custom capabilities that the server supports outside of the specification, + /// labeled using the Java package naming convention and stored as arbitrary JSON values. + #[serde(flatten)] + pub custom_capabilities: HashMap, +} + +/// Information about the m.change_password capability +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub struct ChangePasswordCapability { + /// True if the user can change their password, false otherwise. + pub enabled: bool, +} + +/// Information about the m.room_versions capability +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RoomVersionsCapability { + /// The default room version the server is using for new rooms. + pub default: String, + + /// A detailed description of the room versions the server supports. + pub available: HashMap, +} + +/// The stability of a room version +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum RoomVersionStability { + /// An unstable room version + #[serde(rename = "stable")] + Stable, + + /// A stable room version + #[serde(rename = "unstable")] + Unstable, +}