From 47c43769d7701f0c22cf9da424b453520fe37d83 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 15 Apr 2024 20:57:42 -0400 Subject: [PATCH] improve some user admin cmd checks Signed-off-by: strawberry --- src/service/admin/user.rs | 43 +++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/service/admin/user.rs b/src/service/admin/user.rs index 5f1bbce9..11441e86 100644 --- a/src/service/admin/user.rs +++ b/src/service/admin/user.rs @@ -1,7 +1,8 @@ use std::{fmt::Write as _, sync::Arc}; use clap::Subcommand; -use ruma::{events::room::message::RoomMessageEventContent, UserId}; +use itertools::Itertools; +use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, UserId}; use tracing::{error, info, warn}; use crate::{ @@ -188,6 +189,16 @@ pub(crate) async fn process(command: UserCommand, body: Vec<&str>) -> Result) -> Result) -> Result = services() + .rooms + .state_cache + .rooms_joined(&user_id) + .filter_map(Result::ok) + .map(|room_id| get_room_info(&room_id)) + .sorted_unstable() + .dedup() + .collect(); + if rooms.is_empty() { return Ok(RoomMessageEventContent::text_plain("User is not in any rooms.")); }