use std::collections::BTreeMap;
use ruma_common::{
api::{SupportedVersions, auth_scheme::AccessTokenOptional, request, response},
metadata,
};
#[cfg(feature = "unstable-msc4383")]
use serde::{Deserialize, Serialize};
metadata! {
method: GET,
rate_limited: false,
authentication: AccessTokenOptional,
path: "/_matrix/client/versions",
}
#[request]
#[derive(Default)]
pub struct Request {}
#[response]
pub struct Response {
pub versions: Vec<String>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub unstable_features: BTreeMap<String, bool>,
#[cfg(feature = "unstable-msc4383")]
#[serde(rename = "net.zemos.msc4383.server", default, skip_serializing_if = "Option::is_none")]
pub server: Option<Server>,
}
#[cfg(feature = "unstable-msc4383")]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct Server {
pub name: String,
pub version: String,
}
#[cfg(feature = "unstable-msc4383")]
impl Server {
pub fn new(name: String, version: String) -> Self {
Self { name, version }
}
}
impl Request {
pub fn new() -> Self {
Self {}
}
}
impl Response {
pub fn new(versions: Vec<String>) -> Self {
Self {
versions,
unstable_features: BTreeMap::new(),
#[cfg(feature = "unstable-msc4383")]
server: None,
}
}
pub fn as_supported_versions(&self) -> SupportedVersions {
SupportedVersions::from_parts(&self.versions, &self.unstable_features)
}
}