From 19d1b484e0b02770ff17307bc3e7cb071c65fdec Mon Sep 17 00:00:00 2001 From: tezlm Date: Sat, 14 Oct 2023 07:12:15 -0700 Subject: [PATCH] split out room info into its own function --- src/service/admin/mod.rs | 62 +++++++++++++++------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index f3b63b4b..70a4e646 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -24,7 +24,7 @@ use ruma::{ }, TimelineEventType, }, - EventId, OwnedRoomAliasId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, + EventId, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, }; use serde_json::value::to_raw_value; use tokio::sync::{mpsc, Mutex, MutexGuard}; @@ -773,25 +773,7 @@ impl Service { .metadata .iter_ids() .filter_map(|r| r.ok()) - .map(|id| { - ( - id.clone(), - services() - .rooms - .state_cache - .room_joined_count(&id) - .ok() - .flatten() - .unwrap_or(0), - services() - .rooms - .state_accessor - .get_name(&id) - .ok() - .flatten() - .unwrap_or(id.to_string()), - ) - }) + .map(Self::get_room_info) .collect::>(); rooms.sort_by_key(|r| r.1); rooms.reverse(); @@ -1012,25 +994,7 @@ impl Service { .directory .public_rooms() .filter_map(|r| r.ok()) - .map(|id| { - ( - id.clone(), - services() - .rooms - .state_cache - .room_joined_count(&id) - .ok() - .flatten() - .unwrap_or(0), - services() - .rooms - .state_accessor - .get_name(&id) - .ok() - .flatten() - .unwrap_or(id.to_string()), - ) - }) + .map(Self::get_room_info) .collect::>(); rooms.sort_by_key(|r| r.1); rooms.reverse(); @@ -1296,6 +1260,26 @@ impl Service { Ok(reply_message_content) } + fn get_room_info(id: OwnedRoomId) -> (OwnedRoomId, u64, String) { + ( + id.clone(), + services() + .rooms + .state_cache + .room_joined_count(&id) + .ok() + .flatten() + .unwrap_or(0), + services() + .rooms + .state_accessor + .get_name(&id) + .ok() + .flatten() + .unwrap_or(id.to_string()), + ) + } + // Utility to turn clap's `--help` text to HTML. fn usage_to_html(&self, text: &str, server_name: &ServerName) -> String { // Replace `@conduit:servername:-subcmdname` with `@conduit:servername: subcmdname`