From b28d216e0070f5deccaa70dcd8bbe8f328472b96 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 23 Jun 2024 03:12:12 +0000 Subject: [PATCH] improve debug get-room-state; use RoomOrAliasId Signed-off-by: Jason Volk --- src/admin/debug/commands.rs | 12 +++++------- src/admin/debug/mod.rs | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 40aa0278..c5b944bf 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -13,7 +13,7 @@ use conduit::{ use ruma::{ api::{client::error::ErrorKind, federation::event::get_room_state}, events::room::message::RoomMessageEventContent, - CanonicalJsonObject, EventId, RoomId, RoomVersionId, ServerName, + CanonicalJsonObject, EventId, OwnedRoomOrAliasId, RoomId, RoomVersionId, ServerName, }; use service::{rooms::event_handler::parse_incoming_pdu, sending::resolve::resolve_actual_dest, services, PduEvent}; use tokio::sync::RwLock; @@ -236,7 +236,8 @@ pub(super) async fn get_remote_pdu( } } -pub(super) async fn get_room_state(_body: Vec<&str>, room_id: Box) -> Result { +pub(super) async fn get_room_state(_body: Vec<&str>, room: OwnedRoomOrAliasId) -> Result { + let room_id = services().rooms.alias.resolve(&room).await?; let room_state = services() .rooms .state_accessor @@ -252,17 +253,14 @@ pub(super) async fn get_room_state(_body: Vec<&str>, room_id: Box) -> Re )); } - let json_text = serde_json::to_string_pretty(&room_state).map_err(|e| { + let json = serde_json::to_string_pretty(&room_state).map_err(|e| { warn!("Failed converting room state vector in our database to pretty JSON: {e}"); Error::bad_database( "Failed to convert room state events to pretty JSON, possible invalid room state events in our database", ) })?; - Ok(RoomMessageEventContent::notice_markdown(format!( - "{}\n```json\n{}\n```", - "Found full room state", json_text - ))) + Ok(RoomMessageEventContent::notice_markdown(format!("```json\n{json}\n```"))) } pub(super) async fn ping(_body: Vec<&str>, server: Box) -> Result { diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 19d3712a..27e36a73 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -2,7 +2,7 @@ mod commands; use clap::Subcommand; use conduit::Result; -use ruma::{events::room::message::RoomMessageEventContent, EventId, RoomId, ServerName}; +use ruma::{events::room::message::RoomMessageEventContent, EventId, OwnedRoomOrAliasId, RoomId, ServerName}; use self::commands::*; @@ -71,7 +71,7 @@ pub(super) enum DebugCommand { /// Of course the check is still done on the actual client API. GetRoomState { /// Room ID - room_id: Box, + room_id: OwnedRoomOrAliasId, }, /// - Sends a federation request to the remote server's