Add endpoint for getting server capabilities

This commit is contained in:
Karlinde 2020-01-02 11:37:14 +01:00 committed by Jonas Platte
parent b3a26c499a
commit c0e8e3a84c
4 changed files with 75 additions and 0 deletions

View File

@ -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

View File

@ -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;

3
src/r0/capabilities.rs Normal file
View File

@ -0,0 +1,3 @@
//! Endpoints for querying the server's supported feature set
pub mod get_capabilities;

View File

@ -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<ChangePasswordCapability>,
/// The room versions the server supports.
#[serde(rename = "m.room_versions", skip_serializing_if = "Option::is_none")]
pub room_versions: Option<RoomVersionsCapability>,
/// 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<String, Value>,
}
/// 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<String, RoomVersionStability>,
}
/// 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,
}