From f4ee8bc433d3a18596f6edf4eda015cbe2c851df Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 27 Dec 2025 05:24:49 +0000 Subject: [PATCH] Simplify spaces related syntax. Signed-off-by: Jason Volk --- src/service/rooms/spaces/mod.rs | 79 +++++++++++---------------------- 1 file changed, 26 insertions(+), 53 deletions(-) diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 0cfebf3b..8a2d705c 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -91,6 +91,29 @@ impl crate::Service for Service { fn name(&self) -> &str { crate::service::make_name(std::module_path!()) } } +/// Gets the summary of a space using either local or remote (federation) +/// sources +#[implement(Service)] +pub async fn get_summary_and_children_client( + &self, + current_room: &RoomId, + suggested_only: bool, + user_id: &UserId, + via: &[OwnedServerName], +) -> Result> { + let identifier = Identifier::UserId(user_id); + + if let Ok(Some(response)) = self + .get_summary_and_children_local(current_room, &identifier) + .await + { + return Ok(Some(response)); + } + + self.get_summary_and_children_federation(current_room, suggested_only, user_id, via) + .await +} + /// Gets the summary of a space using solely local information #[implement(Service)] pub async fn get_summary_and_children_local( @@ -225,29 +248,6 @@ async fn get_summary_and_children_federation( Ok(Some(accessibility)) } -/// Gets the summary of a space using either local or remote (federation) -/// sources -#[implement(Service)] -pub async fn get_summary_and_children_client( - &self, - current_room: &RoomId, - suggested_only: bool, - user_id: &UserId, - via: &[OwnedServerName], -) -> Result> { - let identifier = Identifier::UserId(user_id); - - if let Ok(Some(response)) = self - .get_summary_and_children_local(current_room, &identifier) - .await - { - return Ok(Some(response)); - } - - self.get_summary_and_children_federation(current_room, suggested_only, user_id, via) - .await -} - #[implement(Service)] async fn get_room_summary( &self, @@ -468,41 +468,14 @@ async fn cache_insert( current_room: &RoomId, child: RoomSummary, ) { - let RoomSummary { - canonical_alias, - name, - num_joined_members, - room_id, - topic, - world_readable, - guest_can_join, - avatar_url, - join_rule, - room_type, - encryption, - room_version, - } = child; - let summary = SpaceHierarchyParentSummary { - summary: RoomSummary { - canonical_alias, - name, - num_joined_members, - topic, - world_readable, - guest_can_join, - avatar_url, - join_rule, - room_type, - room_id: room_id.clone(), - encryption, - room_version, - }, children_state: self - .get_space_child_events(&room_id) + .get_space_child_events(&child.room_id) .map(Event::into_format) .collect() .await, + + summary: child, }; cache.insert(current_room.to_owned(), Some(CachedSpaceHierarchySummary { summary }));