various cleanup tweaks/fixes

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-10-01 02:47:39 +00:00 committed by strawberry
parent 96fcf7f94d
commit 26dcab272d
18 changed files with 86 additions and 99 deletions

View file

@ -43,8 +43,13 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Command<'_>)
room_id,
} => {
let timer = tokio::time::Instant::now();
let results = services.rooms.alias.local_aliases_for_room(&room_id);
let aliases: Vec<_> = results.collect().await;
let aliases: Vec<_> = services
.rooms
.alias
.local_aliases_for_room(&room_id)
.map(ToOwned::to_owned)
.collect()
.await;
let query_time = timer.elapsed();
Ok(RoomMessageEventContent::notice_markdown(format!(
@ -57,6 +62,7 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Command<'_>)
.rooms
.alias
.all_local_aliases()
.map(|(room_id, alias)| (room_id.to_owned(), alias.to_owned()))
.collect::<Vec<_>>()
.await;
let query_time = timer.elapsed();

View file

@ -119,12 +119,12 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Command<'_>) ->
room_id,
} => {
if let Some(room_id) = room_id {
let aliases = services
let aliases: Vec<OwnedRoomAliasId> = services
.rooms
.alias
.local_aliases_for_room(&room_id)
.map(Into::into)
.collect::<Vec<OwnedRoomAliasId>>()
.collect()
.await;
let plain_list = aliases.iter().fold(String::new(), |mut output, alias| {

View file

@ -47,22 +47,22 @@ pub(super) async fn process(command: RoomDirectoryCommand, context: &Command<'_>
} => {
// TODO: i know there's a way to do this with clap, but i can't seem to find it
let page = page.unwrap_or(1);
let mut rooms = services
let mut rooms: Vec<_> = services
.rooms
.directory
.public_rooms()
.then(|room_id| get_room_info(services, room_id))
.collect::<Vec<_>>()
.collect()
.await;
rooms.sort_by_key(|r| r.1);
rooms.reverse();
let rooms = rooms
let rooms: Vec<_> = rooms
.into_iter()
.skip(page.saturating_sub(1).saturating_mul(PAGE_SIZE))
.take(PAGE_SIZE)
.collect::<Vec<_>>();
.collect();
if rooms.is_empty() {
return Ok(RoomMessageEventContent::text_plain("No more rooms."));

View file

@ -42,14 +42,12 @@ async fn list_joined_members(&self, room_id: Box<RoomId>, local_only: bool) -> R
.state_cache
.room_members(&room_id)
.ready_filter(|user_id| {
if local_only {
self.services.globals.user_is_local(user_id)
} else {
true
}
local_only
.then(|| self.services.globals.user_is_local(user_id))
.unwrap_or(true)
})
.map(ToOwned::to_owned)
.filter_map(|user_id| async move {
let user_id = user_id.to_owned();
Some((
self.services
.users

View file

@ -555,13 +555,13 @@ async fn unban_room(&self, enable_federation: bool, room: Box<RoomOrAliasId>) ->
#[admin_command]
async fn list_banned_rooms(&self, no_details: bool) -> Result<RoomMessageEventContent> {
let room_ids = self
let room_ids: Vec<OwnedRoomId> = self
.services
.rooms
.metadata
.list_banned_rooms()
.map(Into::into)
.collect::<Vec<OwnedRoomId>>()
.collect()
.await;
if room_ids.is_empty() {