diff --git a/src/lib.rs b/src/lib.rs index 69883e53..cacd03a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -226,6 +226,8 @@ impl StateResolution { _room_id: &RoomId, auth_event_ids: &[Vec], ) -> Result> { + use itertools::Itertools; + let mut chains = vec![]; for ids in auth_event_ids { @@ -235,17 +237,15 @@ impl StateResolution { chains.push(chain); } - if let Some(chain) = chains.first() { + if let Some(chain) = chains.first().cloned() { let rest = chains.iter().skip(1).flatten().cloned().collect(); let common = chain.intersection(&rest).collect::>(); Ok(chains - .iter() + .into_iter() .flatten() .filter(|id| !common.contains(&id)) - .cloned() - .collect::>() - .into_iter() + .dedup() .collect()) } else { Ok(vec![]) diff --git a/src/room_version.rs b/src/room_version.rs index 10e64639..a4c27087 100644 --- a/src/room_version.rs +++ b/src/room_version.rs @@ -38,18 +38,19 @@ pub struct RoomVersion { /// not sure pub enforce_key_validity: bool, - // bool: before MSC2261/MSC2432, /// `m.room.aliases` had special auth rules and redaction rules /// before room version 6. + /// + /// before MSC2261/MSC2432, pub special_case_aliases_auth: bool, /// Strictly enforce canonicaljson, do not allow: /// * Integers outside the range of [-2 ^ 53 + 1, 2 ^ 53 - 1] /// * Floats /// * NaN, Infinity, -Infinity pub strict_canonicaljson: bool, - // bool: MSC2209: Check 'notifications' key while verifying - // m.room.power_levels auth rules. /// Verify notifications key while checking m.room.power_levels. + /// + /// bool: MSC2209: Check 'notifications' pub limit_notifications_power_levels: bool, /// Extra rules when verifying redaction events. pub extra_redaction_checks: bool, @@ -73,7 +74,7 @@ impl RoomVersion { }) } - fn version_1() -> Self { + pub fn version_1() -> Self { Self { version: RoomVersionId::Version1, disposition: RoomDisposition::Stable, @@ -87,7 +88,7 @@ impl RoomVersion { } } - fn version_2() -> Self { + pub fn version_2() -> Self { Self { version: RoomVersionId::Version2, disposition: RoomDisposition::Stable, @@ -101,7 +102,7 @@ impl RoomVersion { } } - fn version_3() -> Self { + pub fn version_3() -> Self { Self { version: RoomVersionId::Version3, disposition: RoomDisposition::Stable, @@ -115,7 +116,7 @@ impl RoomVersion { } } - fn version_4() -> Self { + pub fn version_4() -> Self { Self { version: RoomVersionId::Version4, disposition: RoomDisposition::Stable, @@ -129,7 +130,7 @@ impl RoomVersion { } } - fn version_5() -> Self { + pub fn version_5() -> Self { Self { version: RoomVersionId::Version5, disposition: RoomDisposition::Stable, @@ -143,7 +144,7 @@ impl RoomVersion { } } - fn version_6() -> Self { + pub fn version_6() -> Self { Self { version: RoomVersionId::Version6, disposition: RoomDisposition::Stable, diff --git a/tests/event_sorting.rs b/tests/event_sorting.rs index 88a79140..67270e52 100644 --- a/tests/event_sorting.rs +++ b/tests/event_sorting.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use ruma::{events::EventType, EventId, RoomVersionId}; +use ruma::{events::EventType, EventId}; use state_res::{is_power_event, room_version::RoomVersion, StateMap}; mod utils; @@ -46,7 +46,7 @@ fn test_event_sort() { // TODO we may be able to skip this since they are resolved according to spec let resolved_power = state_res::StateResolution::iterative_auth_check( &room_id(), - &RoomVersion::new(&RoomVersionId::Version6).unwrap(), + &RoomVersion::version_6(), &sorted_power_events, &BTreeMap::new(), // unconflicted events &mut events, diff --git a/tests/utils.rs b/tests/utils.rs index 499a23fb..d487749e 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -260,6 +260,7 @@ impl TestStore { room_id: &RoomId, event_ids: Vec>, ) -> Result> { + use itertools::Itertools; let mut chains = vec![]; for ids in event_ids { // TODO state store `auth_event_ids` returns self in the event ids list @@ -271,17 +272,15 @@ impl TestStore { chains.push(chain); } - if let Some(chain) = chains.first() { + if let Some(chain) = chains.first().cloned() { let rest = chains.iter().skip(1).flatten().cloned().collect(); let common = chain.intersection(&rest).collect::>(); Ok(chains - .iter() + .into_iter() .flatten() .filter(|id| !common.contains(&id)) - .cloned() - .collect::>() - .into_iter() + .dedup() .collect()) } else { Ok(vec![])