diff --git a/src/core/matrix/state_res/benches.rs b/src/core/matrix/state_res/benches.rs index ba899f3f1..f46f6c8d3 100644 --- a/src/core/matrix/state_res/benches.rs +++ b/src/core/matrix/state_res/benches.rs @@ -16,6 +16,7 @@ use ruma::{ room::{ join_rules::{JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, + power_levels::UserPowerLevel, }, }, int, room_id, uint, user_id, @@ -46,7 +47,7 @@ fn lexico_topo_sort(c: &mut test::Bencher) { c.iter(|| { let _ = state_res::lexicographical_topological_sort(&graph, &|_| { - future::ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0)))) + future::ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(uint!(0)))) }); }); } diff --git a/src/core/matrix/state_res/mod.rs b/src/core/matrix/state_res/mod.rs index 573e1e052..8161a098c 100644 --- a/src/core/matrix/state_res/mod.rs +++ b/src/core/matrix/state_res/mod.rs @@ -442,29 +442,27 @@ where /// `key_fn` is used as to obtain the power level and age of an event for /// breaking ties (together with the event ID). #[tracing::instrument(level = "debug", skip_all)] -pub async fn lexicographical_topological_sort( +pub async fn lexicographical_topological_sort( graph: &HashMap, S>, key_fn: &F, ) -> Result> where F: Fn(Id) -> Fut + Sync, - Fut: Future> + Send, + Fut: Future> + Send, Id: Borrow + Clone + Eq + Hash + Ord + Send + Sync, - P: Ord + Send, Hasher: BuildHasher + Default + Clone + Send + Sync, S: BuildHasher + Clone + Send + Sync, { #[derive(PartialEq, Eq)] - struct TieBreaker<'a, Id, P> { - power_level: P, + struct TieBreaker<'a, Id> { + power_level: UserPowerLevel, origin_server_ts: MilliSecondsSinceUnixEpoch, event_id: &'a Id, } - impl Ord for TieBreaker<'_, Id, P> + impl Ord for TieBreaker<'_, Id> where Id: Ord, - P: Ord, { fn cmp(&self, other: &Self) -> Ordering { // NOTE: the power level comparison is "backwards" intentionally. @@ -482,10 +480,9 @@ where } } - impl PartialOrd for TieBreaker<'_, Id, P> + impl PartialOrd for TieBreaker<'_, Id> where Id: Ord, - P: Ord, { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } @@ -2078,7 +2075,7 @@ mod tests { }; let res = super::lexicographical_topological_sort(&graph, &|_id| async { - Ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0)))) + Ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(uint!(0)))) }) .await .unwrap(); diff --git a/src/core/matrix/state_res/test_utils.rs b/src/core/matrix/state_res/test_utils.rs index 0d4110a0d..4a7898daf 100644 --- a/src/core/matrix/state_res/test_utils.rs +++ b/src/core/matrix/state_res/test_utils.rs @@ -13,6 +13,7 @@ use ruma::{ room::{ join_rules::{JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, + power_levels::UserPowerLevel, }, }, int, room_id, @@ -89,7 +90,7 @@ pub(crate) async fn do_check( // Resolve the current state and add it to the state_at_event map then // continue on in "time" for node in super::lexicographical_topological_sort(&graph, &|_id| async { - Ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0)))) + Ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(uint!(0)))) }) .await .unwrap() diff --git a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs index 24ef24f54..4a37fad16 100644 --- a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs +++ b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs @@ -20,6 +20,7 @@ use ruma::{ CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, RoomId, ServerName, UInt, api::federation::event::{get_event, get_missing_events}, + events::room::power_levels::UserPowerLevel, int, room_version_rules::RoomVersionRules, }; @@ -100,7 +101,7 @@ pub async fn build_local_dag( // order events correctly for processing, however ultimately that // should be the sender's job. let ts = id_origin_ts.get(&node_id).copied().unwrap_or_default(); - Ok((int!(0), MilliSecondsSinceUnixEpoch(ts))) + Ok((UserPowerLevel::Int(int!(0)), MilliSecondsSinceUnixEpoch(ts))) }) .await .inspect(|sorted| {