mirror of
https://forgejo.ellis.link/continuwuation/continuwuity/
synced 2026-08-14 09:49:45 +00:00
feat: get-state-at admin command
This commit is contained in:
@@ -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()?;
|
||||
|
||||
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user