split out room info into its own function

This commit is contained in:
tezlm 2023-10-14 07:12:15 -07:00
parent 816bba25cf
commit 046acc37bf
No known key found for this signature in database
GPG key ID: 649733FCD94AFBBA

View file

@ -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};
@ -785,25 +785,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();
@ -1023,25 +1005,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();
@ -1307,6 +1271,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`