Skip to main content

tuwunel_admin/debug/
latest_pdu_in_room.rs

1use ruma::OwnedRoomId;
2use tuwunel_core::{Err, Result, err};
3
4use crate::admin_command;
5
6#[admin_command]
7#[tracing::instrument(level = "debug", skip(self))]
8pub(super) async fn latest_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
9	if !self
10		.services
11		.state_cache
12		.server_in_room(&self.services.server.name, &room_id)
13		.await
14	{
15		return Err!("We are not participating in the room / we don't know about the room ID.");
16	}
17
18	let latest_pdu = self
19		.services
20		.timeline
21		.latest_pdu_in_room(&room_id)
22		.await
23		.map_err(|_| err!(Database("Failed to find the latest PDU in database")))?;
24
25	let out = format!("{latest_pdu:?}");
26	self.write_str(&out).await
27}