Skip to main content

tuwunel_api/client/admin/rooms/
timestamp_to_event.rs

1use axum::extract::State;
2use ruma::api::Direction;
3use synapse_admin_api::rooms::admin_timestamp_to_event::v1::{Request, Response};
4use tuwunel_core::Result;
5
6use crate::{Ruma, client::admin::require_admin};
7
8/// # `GET /_synapse/admin/v1/rooms/{room_id}/timestamp_to_event`
9///
10/// Returns the event closest to the given timestamp, skipping the visibility
11/// gates the client-server timestamp endpoint applies.
12pub(crate) async fn admin_room_timestamp_to_event_route(
13	State(services): State<crate::State>,
14	body: Ruma<Request>,
15) -> Result<Response> {
16	require_admin(&services, body.sender_user()).await?;
17
18	let dir = body.dir.unwrap_or(Direction::Forward);
19
20	let (origin_server_ts, event_id) = services
21		.timeline
22		.get_event_id_near_ts_with_fallback(&body.room_id, body.ts, dir)
23		.await?;
24
25	Ok(Response::new(event_id, origin_server_ts))
26}