diff --git a/Cargo.toml b/Cargo.toml index 861076c38..e1e4ec9bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -375,6 +375,7 @@ features = [ "unstable-msc4121", "unstable-msc4125", "unstable-msc4186", + "unstable-msc4195", "unstable-msc4203", # sending to-device events to appservices "unstable-msc4310", "unstable-msc4380", diff --git a/src/api/client/well_known.rs b/src/api/client/well_known.rs index 85a4e5037..698aa4e31 100644 --- a/src/api/client/well_known.rs +++ b/src/api/client/well_known.rs @@ -1,11 +1,11 @@ -use axum::{Json, extract::State, response::IntoResponse}; -use conduwuit::{Error, Result}; -use ruma::api::client::{ - discovery::{ - discover_homeserver::{self, HomeserverInfo}, - discover_support::{self, Contact}, +use axum::extract::State; +use conduwuit::{Err, Result}; +use ruma::{ + api::client::discovery::{ + discover_homeserver::{self, HomeserverInfo, RtcFocusInfo}, + discover_support::{self, Contact, ContactRole}, }, - error::ErrorKind, + assign, }; use crate::Ruma; @@ -19,20 +19,23 @@ pub(crate) async fn well_known_client( ) -> Result { let client_url = match services.config.well_known.client.as_ref() { | Some(url) => url.to_string(), - | None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")), + | None => + return Err!(Request(NotFound( + "This server is not configured to serve well-known client information." + ))), }; - Ok(discover_homeserver::Response { - homeserver: HomeserverInfo { base_url: client_url }, + Ok(assign!(discover_homeserver::Response::new(HomeserverInfo::new(client_url)), { identity_server: None, - sliding_sync_proxy: None, tile_server: None, rtc_foci: services .config .matrix_rtc .effective_foci(&services.config.well_known.rtc_focus_server_urls) - .to_vec(), - }) + .into_iter() + .map(|focus| RtcFocusInfo::new(focus.transport_type(), focus.data().into_owned()).unwrap()) + .collect() + })) } /// # `GET /_matrix/client/v1/rtc/transports` @@ -42,14 +45,13 @@ pub(crate) async fn well_known_client( /// homeserver, implementing MSC4143. pub(crate) async fn get_rtc_transports( State(services): State, - _body: Ruma, -) -> Result { - Ok(ruma::api::client::discovery::get_rtc_transports::Response::new( + _body: Ruma, +) -> Result { + Ok(ruma::api::client::rtc::transports::v1::Response::new( services .config .matrix_rtc - .effective_foci(&services.config.well_known.rtc_focus_server_urls) - .to_vec(), + .effective_foci(&services.config.well_known.rtc_focus_server_urls), )) } @@ -76,21 +78,25 @@ pub(crate) async fn well_known_support( // TODO: support defining multiple contacts in the config let mut contacts: Vec = vec![]; - let role_value = services + let role = services .config .well_known .support_role .clone() - .unwrap_or_else(|| "m.role.admin".to_owned().into()); + .unwrap_or(ContactRole::Admin); // Add configured contact if at least one contact method is specified - if email_address.is_some() || matrix_id.is_some() { - contacts.push(Contact { - role: role_value.clone(), - email_address: email_address.clone(), - matrix_id: matrix_id.clone(), - pgp_key: pgp_key.clone(), - }); + let configured_contact = match (matrix_id, email_address) { + | (Some(matrix_id), email_address) => + Some(assign!(Contact::with_matrix_id(role, matrix_id), { email_address })), + | (None, Some(email_address)) => Some(Contact::with_email_address(role, email_address)), + | (None, None) => None, + }; + + if let Some(mut configured_contact) = configured_contact { + configured_contact.pgp_key = pgp_key; + + contacts.push(configured_contact); } // Try to add admin users as contacts if no contacts are configured @@ -102,40 +108,14 @@ pub(crate) async fn well_known_support( continue; } - contacts.push(Contact { - role: role_value.clone(), - email_address: None, - matrix_id: Some(user_id.to_owned()), - pgp_key: None, - }); + contacts.push(Contact::with_matrix_id(ContactRole::Admin, user_id.to_owned())); } } if contacts.is_empty() && support_page.is_none() { // No admin room, no configured contacts, and no support page - return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")); + return Err!(Request(NotFound("No support information is available."))); } - Ok(discover_support::Response { contacts, support_page }) -} - -/// # `GET /client/server.json` -/// -/// Endpoint provided by sliding sync proxy used by some clients such as Element -/// Web as a non-standard health check. -pub(crate) async fn syncv3_client_server_json( - State(services): State, -) -> Result { - let server_url = match services.config.well_known.client.as_ref() { - | Some(url) => url.to_string(), - | None => match services.config.well_known.server.as_ref() { - | Some(url) => url.to_string(), - | None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")), - }, - }; - - Ok(Json(serde_json::json!({ - "server": server_url, - "version": conduwuit::version(), - }))) + Ok(assign!(discover_support::Response::with_contacts(contacts), { support_page })) } diff --git a/src/api/router.rs b/src/api/router.rs index 09e835f80..6183147f6 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -188,7 +188,6 @@ pub fn build(router: Router, server: &Server) -> Router { .ruma_route(&client::room_initial_sync_route) .route("/_conduwuit/server_version", get(client::conduwuit_server_version)) .route("/_continuwuity/server_version", get(client::conduwuit_server_version)) - .route("/client/server.json", get(client::syncv3_client_server_json)) .ruma_route(&admin::rooms::ban::ban_room) .ruma_route(&admin::rooms::list::list_rooms); diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index e0858d1d9..c419093f1 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -20,7 +20,10 @@ use regex::RegexSet; use ruma::{ OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomVersionId, - api::client::discovery::{discover_homeserver::RtcFocusInfo, discover_support::ContactRole}, + api::client::{ + discovery::{discover_homeserver::RtcFocusInfo, discover_support::ContactRole}, + rtc::transports::v1::RtcTransport, + }, }; use serde::{Deserialize, Serialize, de::IgnoredAny}; use url::Url; @@ -2281,21 +2284,24 @@ pub struct MatrixRtcConfig { /// /// default: [] #[serde(default)] - pub foci: Vec, + pub foci: Vec, } impl MatrixRtcConfig { /// Returns the effective foci, falling back to the deprecated /// `rtc_focus_server_urls` if the new config is empty. #[must_use] - pub fn effective_foci<'a>( - &'a self, - deprecated_foci: &'a [RtcFocusInfo], - ) -> &'a [RtcFocusInfo] { + pub fn effective_foci(&self, deprecated_foci: &[RtcFocusInfo]) -> Vec { if !self.foci.is_empty() { - &self.foci + self.foci.clone() } else { deprecated_foci + .iter() + .map(|focus| { + RtcTransport::new(focus.focus_type().to_owned(), focus.data().into_owned()) + .unwrap() + }) + .collect() } } }