state-res: Change most RoomVersion constructor functions to constants

This commit is contained in:
Devin Ragotzy 2021-11-15 23:01:16 +01:00 committed by Jonas Platte
parent 746e0a026d
commit 44db63657f
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 70 additions and 159 deletions

View File

@ -675,7 +675,7 @@ mod tests {
.unwrap(); .unwrap();
let resolved_power = crate::iterative_auth_check( let resolved_power = crate::iterative_auth_check(
&RoomVersion::version_6(), &RoomVersion::VERSION6,
&sorted_power_events, &sorted_power_events,
HashMap::new(), // unconflicted events HashMap::new(), // unconflicted events
|id| events.get(id).map(Arc::clone), |id| events.get(id).map(Arc::clone),

View File

@ -68,26 +68,7 @@ pub struct RoomVersion {
} }
impl RoomVersion { impl RoomVersion {
pub fn new(version: &RoomVersionId) -> Result<Self> { pub const VERSION1: Self = Self {
Ok(match version {
RoomVersionId::Version1 => Self::version_1(),
RoomVersionId::Version2 => Self::version_2(),
RoomVersionId::Version3 => Self::version_3(),
RoomVersionId::Version4 => Self::version_4(),
RoomVersionId::Version5 => Self::version_5(),
RoomVersionId::Version6 => Self::version_6(),
#[cfg(feature = "unstable-pre-spec")]
RoomVersionId::Version7 => Self::version_7(),
#[cfg(feature = "unstable-pre-spec")]
RoomVersionId::Version8 => Self::version_8(),
#[cfg(feature = "unstable-pre-spec")]
RoomVersionId::Version9 => Self::version_9(),
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
})
}
pub fn version_1() -> Self {
Self {
version: RoomVersionId::Version1, version: RoomVersionId::Version1,
disposition: RoomDisposition::Stable, disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V1, event_format: EventFormatVersion::V1,
@ -99,139 +80,69 @@ impl RoomVersion {
extra_redaction_checks: false, extra_redaction_checks: false,
allow_knocking: false, allow_knocking: false,
restricted_join_rules: false, restricted_join_rules: false,
} };
}
pub fn version_2() -> Self { pub const VERSION2: Self = Self {
Self {
version: RoomVersionId::Version2, version: RoomVersionId::Version2,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V1,
state_res: StateResolutionVersion::V2, state_res: StateResolutionVersion::V2,
enforce_key_validity: false, ..Self::VERSION1
special_case_aliases_auth: true, };
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: false,
allow_knocking: false,
restricted_join_rules: false,
}
}
pub fn version_3() -> Self { pub const VERSION3: Self = Self {
Self {
version: RoomVersionId::Version3, version: RoomVersionId::Version3,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V2, event_format: EventFormatVersion::V2,
state_res: StateResolutionVersion::V2,
enforce_key_validity: false,
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: true, extra_redaction_checks: true,
allow_knocking: false, ..Self::VERSION2
restricted_join_rules: false, };
}
}
pub fn version_4() -> Self { pub const VERSION4: Self = Self {
Self {
version: RoomVersionId::Version4, version: RoomVersionId::Version4,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V3, event_format: EventFormatVersion::V3,
state_res: StateResolutionVersion::V2, ..Self::VERSION3
enforce_key_validity: false, };
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: true,
allow_knocking: false,
restricted_join_rules: false,
}
}
pub fn version_5() -> Self { pub const VERSION5: Self =
Self { Self { version: RoomVersionId::Version5, enforce_key_validity: true, ..Self::VERSION4 };
pub const VERSION6: Self = Self {
version: RoomVersionId::Version5, version: RoomVersionId::Version5,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V3,
state_res: StateResolutionVersion::V2,
enforce_key_validity: true,
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: true,
allow_knocking: false,
restricted_join_rules: false,
}
}
pub fn version_6() -> Self {
Self {
version: RoomVersionId::Version6,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V3,
state_res: StateResolutionVersion::V2,
enforce_key_validity: true,
special_case_aliases_auth: false, special_case_aliases_auth: false,
strict_canonicaljson: true, strict_canonicaljson: true,
limit_notifications_power_levels: true, limit_notifications_power_levels: true,
extra_redaction_checks: true, ..Self::VERSION5
allow_knocking: false, };
restricted_join_rules: false,
}
}
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
pub fn version_7() -> Self { pub const VERSION7: Self = Self {
Self {
version: RoomVersionId::Version7, version: RoomVersionId::Version7,
disposition: RoomDisposition::Stable, // FIXME: once room version 7 is stabilized move this to version 8
event_format: EventFormatVersion::V3, disposition: RoomDisposition::Unstable,
state_res: StateResolutionVersion::V2,
enforce_key_validity: true,
special_case_aliases_auth: false,
strict_canonicaljson: true,
limit_notifications_power_levels: true,
extra_redaction_checks: true,
allow_knocking: true, allow_knocking: true,
restricted_join_rules: false, ..Self::VERSION6
} };
}
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
pub fn version_8() -> Self { pub const VERSION8: Self =
Self { Self { version: RoomVersionId::Version8, restricted_join_rules: true, ..Self::VERSION7 };
version: RoomVersionId::Version8,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V3,
state_res: StateResolutionVersion::V2,
enforce_key_validity: true,
special_case_aliases_auth: false,
strict_canonicaljson: true,
limit_notifications_power_levels: true,
extra_redaction_checks: true,
// Wait so should this be false?
// because: https://github.com/matrix-org/matrix-doc/pull/3289#issuecomment-884165177
allow_knocking: false,
restricted_join_rules: true,
}
}
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
pub fn version_9() -> Self { pub const VERSION9: Self = Self { version: RoomVersionId::Version9, ..Self::VERSION8 };
Self {
version: RoomVersionId::Version9, pub fn new(version: &RoomVersionId) -> Result<Self> {
disposition: RoomDisposition::Stable, Ok(match version {
event_format: EventFormatVersion::V3, RoomVersionId::Version1 => Self::VERSION1,
state_res: StateResolutionVersion::V2, RoomVersionId::Version2 => Self::VERSION2,
enforce_key_validity: true, RoomVersionId::Version3 => Self::VERSION3,
special_case_aliases_auth: false, RoomVersionId::Version4 => Self::VERSION4,
strict_canonicaljson: true, RoomVersionId::Version5 => Self::VERSION5,
limit_notifications_power_levels: true, RoomVersionId::Version6 => Self::VERSION6,
extra_redaction_checks: true, #[cfg(feature = "unstable-pre-spec")]
allow_knocking: true, RoomVersionId::Version7 => Self::VERSION7,
restricted_join_rules: true, #[cfg(feature = "unstable-pre-spec")]
} RoomVersionId::Version8 => Self::VERSION8,
#[cfg(feature = "unstable-pre-spec")]
RoomVersionId::Version9 => Self::VERSION9,
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
})
} }
} }