mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
refactor: Fix errors in api/client/well_known.rs
This commit is contained in:
@@ -375,6 +375,7 @@ features = [
|
|||||||
"unstable-msc4121",
|
"unstable-msc4121",
|
||||||
"unstable-msc4125",
|
"unstable-msc4125",
|
||||||
"unstable-msc4186",
|
"unstable-msc4186",
|
||||||
|
"unstable-msc4195",
|
||||||
"unstable-msc4203", # sending to-device events to appservices
|
"unstable-msc4203", # sending to-device events to appservices
|
||||||
"unstable-msc4310",
|
"unstable-msc4310",
|
||||||
"unstable-msc4380",
|
"unstable-msc4380",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use axum::{Json, extract::State, response::IntoResponse};
|
use axum::extract::State;
|
||||||
use conduwuit::{Error, Result};
|
use conduwuit::{Err, Result};
|
||||||
use ruma::api::client::{
|
use ruma::{
|
||||||
discovery::{
|
api::client::discovery::{
|
||||||
discover_homeserver::{self, HomeserverInfo},
|
discover_homeserver::{self, HomeserverInfo, RtcFocusInfo},
|
||||||
discover_support::{self, Contact},
|
discover_support::{self, Contact, ContactRole},
|
||||||
},
|
},
|
||||||
error::ErrorKind,
|
assign,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
@@ -19,20 +19,23 @@ pub(crate) async fn well_known_client(
|
|||||||
) -> Result<discover_homeserver::Response> {
|
) -> Result<discover_homeserver::Response> {
|
||||||
let client_url = match services.config.well_known.client.as_ref() {
|
let client_url = match services.config.well_known.client.as_ref() {
|
||||||
| Some(url) => url.to_string(),
|
| 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 {
|
Ok(assign!(discover_homeserver::Response::new(HomeserverInfo::new(client_url)), {
|
||||||
homeserver: HomeserverInfo { base_url: client_url },
|
|
||||||
identity_server: None,
|
identity_server: None,
|
||||||
sliding_sync_proxy: None,
|
|
||||||
tile_server: None,
|
tile_server: None,
|
||||||
rtc_foci: services
|
rtc_foci: services
|
||||||
.config
|
.config
|
||||||
.matrix_rtc
|
.matrix_rtc
|
||||||
.effective_foci(&services.config.well_known.rtc_focus_server_urls)
|
.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`
|
/// # `GET /_matrix/client/v1/rtc/transports`
|
||||||
@@ -42,14 +45,13 @@ pub(crate) async fn well_known_client(
|
|||||||
/// homeserver, implementing MSC4143.
|
/// homeserver, implementing MSC4143.
|
||||||
pub(crate) async fn get_rtc_transports(
|
pub(crate) async fn get_rtc_transports(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
_body: Ruma<ruma::api::client::discovery::get_rtc_transports::Request>,
|
_body: Ruma<ruma::api::client::rtc::transports::v1::Request>,
|
||||||
) -> Result<ruma::api::client::discovery::get_rtc_transports::Response> {
|
) -> Result<ruma::api::client::rtc::transports::v1::Response> {
|
||||||
Ok(ruma::api::client::discovery::get_rtc_transports::Response::new(
|
Ok(ruma::api::client::rtc::transports::v1::Response::new(
|
||||||
services
|
services
|
||||||
.config
|
.config
|
||||||
.matrix_rtc
|
.matrix_rtc
|
||||||
.effective_foci(&services.config.well_known.rtc_focus_server_urls)
|
.effective_foci(&services.config.well_known.rtc_focus_server_urls),
|
||||||
.to_vec(),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,21 +78,25 @@ pub(crate) async fn well_known_support(
|
|||||||
// TODO: support defining multiple contacts in the config
|
// TODO: support defining multiple contacts in the config
|
||||||
let mut contacts: Vec<Contact> = vec![];
|
let mut contacts: Vec<Contact> = vec![];
|
||||||
|
|
||||||
let role_value = services
|
let role = services
|
||||||
.config
|
.config
|
||||||
.well_known
|
.well_known
|
||||||
.support_role
|
.support_role
|
||||||
.clone()
|
.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
|
// Add configured contact if at least one contact method is specified
|
||||||
if email_address.is_some() || matrix_id.is_some() {
|
let configured_contact = match (matrix_id, email_address) {
|
||||||
contacts.push(Contact {
|
| (Some(matrix_id), email_address) =>
|
||||||
role: role_value.clone(),
|
Some(assign!(Contact::with_matrix_id(role, matrix_id), { email_address })),
|
||||||
email_address: email_address.clone(),
|
| (None, Some(email_address)) => Some(Contact::with_email_address(role, email_address)),
|
||||||
matrix_id: matrix_id.clone(),
|
| (None, None) => None,
|
||||||
pgp_key: pgp_key.clone(),
|
};
|
||||||
});
|
|
||||||
|
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
|
// Try to add admin users as contacts if no contacts are configured
|
||||||
@@ -102,40 +108,14 @@ pub(crate) async fn well_known_support(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
contacts.push(Contact {
|
contacts.push(Contact::with_matrix_id(ContactRole::Admin, user_id.to_owned()));
|
||||||
role: role_value.clone(),
|
|
||||||
email_address: None,
|
|
||||||
matrix_id: Some(user_id.to_owned()),
|
|
||||||
pgp_key: None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if contacts.is_empty() && support_page.is_none() {
|
if contacts.is_empty() && support_page.is_none() {
|
||||||
// No admin room, no configured contacts, and no support page
|
// 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 })
|
Ok(assign!(discover_support::Response::with_contacts(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<crate::State>,
|
|
||||||
) -> Result<impl IntoResponse> {
|
|
||||||
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(),
|
|
||||||
})))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ pub fn build(router: Router<State>, server: &Server) -> Router<State> {
|
|||||||
.ruma_route(&client::room_initial_sync_route)
|
.ruma_route(&client::room_initial_sync_route)
|
||||||
.route("/_conduwuit/server_version", get(client::conduwuit_server_version))
|
.route("/_conduwuit/server_version", get(client::conduwuit_server_version))
|
||||||
.route("/_continuwuity/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::ban::ban_room)
|
||||||
.ruma_route(&admin::rooms::list::list_rooms);
|
.ruma_route(&admin::rooms::list::list_rooms);
|
||||||
|
|
||||||
|
|||||||
+13
-7
@@ -20,7 +20,10 @@ use lettre::message::Mailbox;
|
|||||||
use regex::RegexSet;
|
use regex::RegexSet;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomVersionId,
|
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 serde::{Deserialize, Serialize, de::IgnoredAny};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -2281,21 +2284,24 @@ pub struct MatrixRtcConfig {
|
|||||||
///
|
///
|
||||||
/// default: []
|
/// default: []
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub foci: Vec<RtcFocusInfo>,
|
pub foci: Vec<RtcTransport>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MatrixRtcConfig {
|
impl MatrixRtcConfig {
|
||||||
/// Returns the effective foci, falling back to the deprecated
|
/// Returns the effective foci, falling back to the deprecated
|
||||||
/// `rtc_focus_server_urls` if the new config is empty.
|
/// `rtc_focus_server_urls` if the new config is empty.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn effective_foci<'a>(
|
pub fn effective_foci(&self, deprecated_foci: &[RtcFocusInfo]) -> Vec<RtcTransport> {
|
||||||
&'a self,
|
|
||||||
deprecated_foci: &'a [RtcFocusInfo],
|
|
||||||
) -> &'a [RtcFocusInfo] {
|
|
||||||
if !self.foci.is_empty() {
|
if !self.foci.is_empty() {
|
||||||
&self.foci
|
self.foci.clone()
|
||||||
} else {
|
} else {
|
||||||
deprecated_foci
|
deprecated_foci
|
||||||
|
.iter()
|
||||||
|
.map(|focus| {
|
||||||
|
RtcTransport::new(focus.focus_type().to_owned(), focus.data().into_owned())
|
||||||
|
.unwrap()
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user