From c6832372c280b4ca6d425e38639012c418bcb3eb Mon Sep 17 00:00:00 2001 From: timedout Date: Tue, 13 Oct 2026 20:01:18 +0100 Subject: [PATCH] feat: Add command to enumerate extremities --- src/admin/debug/commands.rs | 42 ++++++++++++++++++++++++++++++++++++- src/admin/debug/mod.rs | 4 ++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 9fc69aae9..7b5e82dc6 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -14,7 +14,7 @@ use conduwuit::{ state_res::EventTypeExt, trace, utils, utils::{ - stream::{IterStream, ReadyExt}, + stream::{BroadbandExt, IterStream, ReadyExt}, string::EMPTY, to_canonical_object, }, @@ -1207,6 +1207,46 @@ impl crate::Context<'_> { .await } + pub(super) async fn room_extremities(&self, room_id: OwnedRoomId) -> Result { + let mut extremities = self + .services + .rooms + .state + .get_forward_extremities(&room_id) + .broad_filter_map(|event_id| async move { + self.services.rooms.timeline.get_pdu(&event_id).await.ok() + }) + .collect::>() + .await; + extremities.sort_by_key(|pdu| (pdu.depth, pdu.origin_server_ts)); + if extremities.is_empty() { + return Err!("No room extremities."); + } + self.write_str("| Event ID | Kind | Sender | Timestamp | Depth |\n") + .await?; + self.write_str("| -------- | ---- | ------ | --------- | ----- |\n") + .await?; + for pdu in extremities { + let url = format!( + "https://matrix.to/#/{}/{}?via={}", + room_id, + pdu.event_id(), + self.services.server.name + ); + self.write_str(&format!( + "| [`{}`]({url}) | `{}` | `{}` | `{}` | `{}` |\n", + pdu.event_id(), + pdu.kind(), + pdu.sender(), + pdu.origin_server_ts, + pdu.depth + )) + .await?; + } + + Ok(()) + } + pub(super) async fn servers_in_backoff( &self, room_id: Option, diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index f544637ab..9bf3647b3 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -234,6 +234,10 @@ pub enum DebugCommand { page: Option, }, + RoomExtremities { + room_id: OwnedRoomId, + }, + /// Lists remote servers that are currently in a "backoff" state. /// /// Servers in this list will not be contacted until the retry time elapses,