From d36b68b7d12d19551c4eab5afcbcd114e54581d9 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 22 Oct 2025 11:28:23 +0300 Subject: [PATCH] fix(spaces): have space children with an `order` field set come before the others in room lists --- crates/matrix-sdk-ui/src/spaces/room_list.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-ui/src/spaces/room_list.rs b/crates/matrix-sdk-ui/src/spaces/room_list.rs index 0ff471088..0f00c93eb 100644 --- a/crates/matrix-sdk-ui/src/spaces/room_list.rs +++ b/crates/matrix-sdk-ui/src/spaces/room_list.rs @@ -371,8 +371,8 @@ impl SpaceRoomList { .cmp(b_order) .then(a_state.origin_server_ts.cmp(&b_state.origin_server_ts)) .then(a.room_id.cmp(&b.room_id)), - (Some(_), None) => Ordering::Greater, - (None, Some(_)) => Ordering::Less, + (Some(_), None) => Ordering::Less, + (None, Some(_)) => Ordering::Greater, (None, None) => a_state .origin_server_ts .cmp(&b_state.origin_server_ts) @@ -850,8 +850,8 @@ mod tests { Ordering::Less ); - // Finally, when one of the rooms is missing `children_state` data the - // other one should take precedence + // When one of the rooms is missing `children_state` data the other one + // should take precedence assert_eq!( SpaceRoomList::compare_rooms( &make_space_room(owned_room_id!("!Viola:a.b"), None, None, &mut children_state), @@ -866,6 +866,8 @@ mod tests { Ordering::Greater ); + // If the `order` is missing from one of the rooms but `children_state` + // is present then the other one should come first assert_eq!( SpaceRoomList::compare_rooms( &make_space_room( @@ -882,7 +884,7 @@ mod tests { ), &children_state, ), - Ordering::Less + Ordering::Greater ); } @@ -923,9 +925,8 @@ mod tests { order: Option<&str>, origin_server_ts: u32, ) -> HierarchySpaceChildEvent { - let json = json!({ + let mut json = json!({ "content": { - "order": order.unwrap_or(""), "via": [] }, "origin_server_ts": origin_server_ts, @@ -934,6 +935,10 @@ mod tests { "type": "m.space.child" }); + if let Some(order) = order { + json["content"]["order"] = json!(order); + } + from_value::(json).unwrap() } }