mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-16 05:36:50 +00:00
feat: get-state-at admin command
This commit is contained in:
1 parent
8a495a7d7f
commit
4b2f032ae6
2 files changed
+47
-1
No files matched your search
@@ -6,7 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug_error, err, info,
|
Err, Result, at, debug_error, err, info,
|
||||||
matrix::{
|
matrix::{
|
||||||
Event,
|
Event,
|
||||||
pdu::{PduEvent, PduId, RawPduId},
|
pdu::{PduEvent, PduId, RawPduId},
|
||||||
@@ -504,6 +504,44 @@ pub(super) async fn get_remote_pdu(
|
|||||||
.await
|
.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]
|
#[admin_command]
|
||||||
pub(super) async fn get_room_state(&self, room: OwnedRoomOrAliasId) -> Result {
|
pub(super) async fn get_room_state(&self, room: OwnedRoomOrAliasId) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|||||||
@@ -95,6 +95,14 @@ pub enum DebugCommand {
|
|||||||
room_id: OwnedRoomOrAliasId,
|
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.
|
/// Get and display signing keys from local cache or remote server.
|
||||||
GetSigningKeys {
|
GetSigningKeys {
|
||||||
server_name: Option<OwnedServerName>,
|
server_name: Option<OwnedServerName>,
|
||||||
|
|||||||
Reference in new issue
Block a user