From 4b2f032ae6bcab7647535d606df06ede8feea564 Mon Sep 17 00:00:00 2001 From: 31a05b9c Date: Wed, 24 Jun 2026 10:15:04 +0000 Subject: [PATCH] feat: `get-state-at` admin command --- src/admin/debug/commands.rs | 40 ++++++++++++++++++++++++++++++++++++- src/admin/debug/mod.rs | 8 ++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index f9a678f19..1aa9cb062 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -6,7 +6,7 @@ }; use conduwuit::{ - Err, Result, debug_error, err, info, + Err, Result, at, debug_error, err, info, matrix::{ Event, pdu::{PduEvent, PduId, RawPduId}, @@ -504,6 +504,44 @@ pub(super) async fn get_remote_pdu( .await } +#[admin_command] +pub(super) async fn get_state_at(&self, event_id: OwnedEventId) -> Result { + self.bail_restricted()?; + + let shortstatehash = self + .services + .rooms + .state_accessor + .pdu_shortstatehash(&event_id) + .await?; + + let state_ids: Vec = self + .services + .rooms + .state_accessor + .state_full_ids(shortstatehash) + .map(at!(1)) + .collect() + .await; + + let pdus: Vec = state_ids + .iter() + .try_stream() + .and_then(|id| self.services.rooms.timeline.get_pdu_json(id)) + .try_collect() + .await?; + + let json = serde_json::to_string_pretty(&pdus).map_err(|e| { + err!(Database( + "Failed to convert room state events to pretty JSON, possible invalid room state \ + events in our database {e}", + )) + })?; + + let out = format!("```json\n{json}\n```"); + self.write_str(&out).await +} + #[admin_command] pub(super) async fn get_room_state(&self, room: OwnedRoomOrAliasId) -> Result { self.bail_restricted()?; diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index a9478ce82..2e1b62e0b 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -95,6 +95,14 @@ pub enum DebugCommand { room_id: OwnedRoomOrAliasId, }, + /// Gets all the room state events at the specified event. + /// + /// State at event might not be available for some PDUs, such as rejected + /// ones. + GetStateAt { + event_id: OwnedEventId, + }, + /// Get and display signing keys from local cache or remote server. GetSigningKeys { server_name: Option,