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:
Jason Volk 2025-01-24 06:12:52 +00:00
parent 52adae7553
commit 6e7c73336c
4 changed files with 19 additions and 16 deletions

View file

@ -4,7 +4,7 @@ use either::Either;
use figment::Figment;
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)]
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(())
}

View file

@ -20,6 +20,8 @@ pub const STABLE_ROOM_VERSIONS: &[RoomVersionId] = &[
pub const UNSTABLE_ROOM_VERSIONS: &[RoomVersionId] =
&[RoomVersionId::V2, RoomVersionId::V3, RoomVersionId::V4, RoomVersionId::V5];
type RoomVersion = (RoomVersionId, RoomVersionStability);
impl crate::Server {
#[inline]
pub fn supported_room_version(&self, version: &RoomVersionId) -> bool {
@ -28,15 +30,13 @@ impl crate::Server {
#[inline]
pub fn supported_room_versions(&self) -> impl Iterator<Item = RoomVersionId> + '_ {
self.available_room_versions()
Self::available_room_versions()
.filter(|(_, stability)| self.supported_stability(stability))
.map(at!(0))
}
#[inline]
pub fn available_room_versions(
&self,
) -> impl Iterator<Item = (RoomVersionId, RoomVersionStability)> {
pub fn available_room_versions() -> impl Iterator<Item = RoomVersion> {
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
.iter()
.cloned()