move room version config check out of services.globals
make available_room_versions() non-member associated Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
52adae7553
commit
6e7c73336c
4 changed files with 19 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use conduwuit::{Result, Server};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::discovery::get_capabilities::{
|
api::client::discovery::get_capabilities::{
|
||||||
self, Capabilities, GetLoginTokenCapability, RoomVersionStability,
|
self, Capabilities, GetLoginTokenCapability, RoomVersionStability,
|
||||||
|
@ -10,7 +11,7 @@ use ruma::{
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{Result, Ruma};
|
use crate::Ruma;
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v3/capabilities`
|
/// # `GET /_matrix/client/v3/capabilities`
|
||||||
///
|
///
|
||||||
|
@ -21,7 +22,7 @@ pub(crate) async fn get_capabilities_route(
|
||||||
_body: Ruma<get_capabilities::v3::Request>,
|
_body: Ruma<get_capabilities::v3::Request>,
|
||||||
) -> Result<get_capabilities::v3::Response> {
|
) -> Result<get_capabilities::v3::Response> {
|
||||||
let available: BTreeMap<RoomVersionId, RoomVersionStability> =
|
let available: BTreeMap<RoomVersionId, RoomVersionStability> =
|
||||||
services.server.available_room_versions().collect();
|
Server::available_room_versions().collect();
|
||||||
|
|
||||||
let mut capabilities = Capabilities::default();
|
let mut capabilities = Capabilities::default();
|
||||||
capabilities.room_versions = RoomVersionsCapability {
|
capabilities.room_versions = RoomVersionsCapability {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use either::Either;
|
||||||
use figment::Figment;
|
use figment::Figment;
|
||||||
|
|
||||||
use super::DEPRECATED_KEYS;
|
use super::DEPRECATED_KEYS;
|
||||||
use crate::{debug, debug_info, debug_warn, error, warn, Config, Err, Result};
|
use crate::{debug, debug_info, debug_warn, error, warn, Config, Err, Result, Server};
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
pub fn check(config: &Config) -> Result<()> {
|
pub fn check(config: &Config) -> Result<()> {
|
||||||
|
@ -233,6 +233,16 @@ pub fn check(config: &Config) -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !Server::available_room_versions()
|
||||||
|
.any(|(version, _)| version == config.default_room_version)
|
||||||
|
{
|
||||||
|
return Err!(Config(
|
||||||
|
"default_room_version",
|
||||||
|
"Room version {:?} is not available",
|
||||||
|
config.default_room_version
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ pub const STABLE_ROOM_VERSIONS: &[RoomVersionId] = &[
|
||||||
pub const UNSTABLE_ROOM_VERSIONS: &[RoomVersionId] =
|
pub const UNSTABLE_ROOM_VERSIONS: &[RoomVersionId] =
|
||||||
&[RoomVersionId::V2, RoomVersionId::V3, RoomVersionId::V4, RoomVersionId::V5];
|
&[RoomVersionId::V2, RoomVersionId::V3, RoomVersionId::V4, RoomVersionId::V5];
|
||||||
|
|
||||||
|
type RoomVersion = (RoomVersionId, RoomVersionStability);
|
||||||
|
|
||||||
impl crate::Server {
|
impl crate::Server {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn supported_room_version(&self, version: &RoomVersionId) -> bool {
|
pub fn supported_room_version(&self, version: &RoomVersionId) -> bool {
|
||||||
|
@ -28,15 +30,13 @@ impl crate::Server {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn supported_room_versions(&self) -> impl Iterator<Item = RoomVersionId> + '_ {
|
pub fn supported_room_versions(&self) -> impl Iterator<Item = RoomVersionId> + '_ {
|
||||||
self.available_room_versions()
|
Self::available_room_versions()
|
||||||
.filter(|(_, stability)| self.supported_stability(stability))
|
.filter(|(_, stability)| self.supported_stability(stability))
|
||||||
.map(at!(0))
|
.map(at!(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn available_room_versions(
|
pub fn available_room_versions() -> impl Iterator<Item = RoomVersion> {
|
||||||
&self,
|
|
||||||
) -> impl Iterator<Item = (RoomVersionId, RoomVersionStability)> {
|
|
||||||
available_room_versions()
|
available_room_versions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ impl crate::Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn available_room_versions() -> impl Iterator<Item = (RoomVersionId, RoomVersionStability)> {
|
pub fn available_room_versions() -> impl Iterator<Item = RoomVersion> {
|
||||||
let unstable_room_versions = UNSTABLE_ROOM_VERSIONS
|
let unstable_room_versions = UNSTABLE_ROOM_VERSIONS
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
|
@ -72,14 +72,6 @@ impl crate::Service for Service {
|
||||||
registration_token,
|
registration_token,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !args
|
|
||||||
.server
|
|
||||||
.supported_room_version(&config.default_room_version)
|
|
||||||
{
|
|
||||||
error!(config=?s.config.default_room_version, fallback=?conduwuit::config::default_default_room_version(), "Room version in config isn't supported, falling back to default version");
|
|
||||||
s.config.default_room_version = conduwuit::config::default_default_room_version();
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Arc::new(s))
|
Ok(Arc::new(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue