2022-01-13 12:06:20 +01:00
|
|
|
use std::{collections::BTreeMap, iter::FromIterator};
|
|
|
|
|
2023-07-06 10:32:25 +02:00
|
|
|
use axum::{response::IntoResponse, Json};
|
|
|
|
use ruma::api::client::{discovery::get_supported_versions, error::ErrorKind};
|
2022-04-06 21:31:29 +02:00
|
|
|
|
2023-07-06 10:32:25 +02:00
|
|
|
use crate::{services, Error, Result, Ruma};
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2020-07-31 14:40:28 +02:00
|
|
|
/// # `GET /_matrix/client/versions`
|
|
|
|
///
|
|
|
|
/// Get the versions of the specification and unstable features supported by this server.
|
|
|
|
///
|
|
|
|
/// - Versions take the form MAJOR.MINOR.PATCH
|
|
|
|
/// - Only the latest PATCH release will be reported for each MAJOR.MINOR value
|
2021-08-31 19:14:37 +02:00
|
|
|
/// - Unstable features are namespaced and may include version information in their name
|
2020-07-31 14:40:28 +02:00
|
|
|
///
|
|
|
|
/// Note: Unstable features are used while developing new features. Clients should avoid using
|
|
|
|
/// unstable features in their stable releases
|
2022-01-20 11:51:31 +01:00
|
|
|
pub async fn get_supported_versions_route(
|
2022-12-14 13:09:10 +01:00
|
|
|
_body: Ruma<get_supported_versions::Request>,
|
2022-01-22 16:58:32 +01:00
|
|
|
) -> Result<get_supported_versions::Response> {
|
2022-01-13 11:48:18 +01:00
|
|
|
let resp = get_supported_versions::Response {
|
2022-05-30 12:58:43 +02:00
|
|
|
versions: vec![
|
|
|
|
"r0.5.0".to_owned(),
|
|
|
|
"r0.6.0".to_owned(),
|
|
|
|
"v1.1".to_owned(),
|
|
|
|
"v1.2".to_owned(),
|
2023-06-25 19:31:40 +02:00
|
|
|
"v1.3".to_owned(),
|
|
|
|
"v1.4".to_owned(),
|
2022-05-30 12:58:43 +02:00
|
|
|
],
|
2022-01-13 12:06:20 +01:00
|
|
|
unstable_features: BTreeMap::from_iter([("org.matrix.e2e_cross_signing".to_owned(), true)]),
|
2022-01-13 11:48:18 +01:00
|
|
|
};
|
2020-07-30 18:14:47 +02:00
|
|
|
|
2022-01-22 16:58:32 +01:00
|
|
|
Ok(resp)
|
2020-07-30 18:14:47 +02:00
|
|
|
}
|
2023-07-06 10:32:25 +02:00
|
|
|
|
|
|
|
/// # `GET /.well-known/matrix/client`
|
|
|
|
pub async fn well_known_client_route(
|
|
|
|
_body: Ruma<get_supported_versions::Request>,
|
|
|
|
) -> Result<impl IntoResponse> {
|
|
|
|
let client_url = match services().globals.well_known_client() {
|
|
|
|
Some(url) => url.clone(),
|
|
|
|
None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Json(serde_json::json!({
|
|
|
|
"m.homeserver": {"base_url": client_url},
|
|
|
|
"org.matrix.msc3575.proxy": {"url": client_url}
|
|
|
|
})))
|
|
|
|
}
|