feat: get-state-at admin command

This commit is contained in:
31a05b9c
2026-06-27 01:05:48 +01:00
committed by Jade Ellis
parent 8a495a7d7f
commit 4b2f032ae6
2 changed files with 47 additions and 1 deletions
+39 -1
View File
@@ -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<OwnedEventId> = self
.services
.rooms
.state_accessor
.state_full_ids(shortstatehash)
.map(at!(1))
.collect()
.await;
let pdus: Vec<CanonicalJsonObject> = 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()?;
+8
View File
@@ -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<OwnedServerName>,