split out room info into its own function

This commit is contained in:
tezlm 2024-08-22 15:14:19 -07:00
parent fbd8780600
commit 7e07d246df
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA

View file

@ -763,25 +763,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::<Vec<_>>();
rooms.sort_by_key(|r| r.1);
rooms.reverse();
@ -1004,25 +986,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::<Vec<_>>();
rooms.sort_by_key(|r| r.1);
rooms.reverse();
@ -1311,6 +1275,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`