api: Get the default room version for a Matrix version

This commit is contained in:
Kévin Commaille 2022-06-20 19:03:21 +02:00 committed by Kévin Commaille
parent 3deae8eac7
commit 9a8d7bf475

View File

@ -6,6 +6,7 @@ use std::{
use http::Method;
use super::{error::UnknownVersionError, AuthScheme};
use crate::RoomVersionId;
/// Metadata about an API endpoint.
#[derive(Clone, Debug)]
@ -228,6 +229,20 @@ impl MatrixVersion {
_ => Err(UnknownVersionError),
}
}
/// Get the default [`RoomVersionId`] for this `MatrixVersion`.
pub fn default_room_version(&self) -> RoomVersionId {
match self {
// <https://matrix.org/docs/spec/index.html#complete-list-of-room-versions>
MatrixVersion::V1_0
// <https://spec.matrix.org/v1.1/rooms/#complete-list-of-room-versions>
| MatrixVersion::V1_1
// <https://spec.matrix.org/v1.2/rooms/#complete-list-of-room-versions>
| MatrixVersion::V1_2 => RoomVersionId::V6,
// <https://spec.matrix.org/v1.3/rooms/#complete-list-of-room-versions>
MatrixVersion::V1_3 => RoomVersionId::V9,
}
}
}
impl Display for MatrixVersion {