split out room info into its own function

This commit is contained in:
tezlm 2023-10-14 07:12:15 -07:00 committed by strawberry
parent c2b103514b
commit 19d1b484e0

View file

@ -24,7 +24,7 @@ use ruma::{
}, },
TimelineEventType, TimelineEventType,
}, },
EventId, OwnedRoomAliasId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, EventId, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;
use tokio::sync::{mpsc, Mutex, MutexGuard}; use tokio::sync::{mpsc, Mutex, MutexGuard};
@ -773,25 +773,7 @@ impl Service {
.metadata .metadata
.iter_ids() .iter_ids()
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.map(|id| { .map(Self::get_room_info)
(
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()),
)
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
rooms.sort_by_key(|r| r.1); rooms.sort_by_key(|r| r.1);
rooms.reverse(); rooms.reverse();
@ -1012,25 +994,7 @@ impl Service {
.directory .directory
.public_rooms() .public_rooms()
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.map(|id| { .map(Self::get_room_info)
(
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()),
)
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
rooms.sort_by_key(|r| r.1); rooms.sort_by_key(|r| r.1);
rooms.reverse(); rooms.reverse();
@ -1296,6 +1260,26 @@ impl Service {
Ok(reply_message_content) 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. // Utility to turn clap's `--help` text to HTML.
fn usage_to_html(&self, text: &str, server_name: &ServerName) -> String { fn usage_to_html(&self, text: &str, server_name: &ServerName) -> String {
// Replace `@conduit:servername:-subcmdname` with `@conduit:servername: subcmdname` // Replace `@conduit:servername:-subcmdname` with `@conduit:servername: subcmdname`