Skip to main content

tuwunel_api_admin/rooms/
messages.rs

1use axum::extract::State;
2use ruma::api::{Direction, client::filter::RoomEventFilter};
3use synapse_admin_api::rooms::admin_messages::v1::{Request, Response};
4use tuwunel_api_client::{MessagesArgs, get_messages};
5use tuwunel_core::Result;
6
7use crate::{Ruma, require_admin};
8
9/// # `GET /_synapse/admin/v1/rooms/{room_id}/messages`
10///
11/// Paginates a room's timeline with admin privilege, skipping the membership
12/// gate and the per-event visibility and ignore filters the client-server
13/// endpoint applies.
14pub(crate) async fn admin_room_messages_route(
15	State(services): State<crate::State>,
16	body: Ruma<Request>,
17) -> Result<Response> {
18	require_admin(&services, body.sender_user()).await?;
19
20	let filter: RoomEventFilter = body
21		.filter
22		.as_deref()
23		.map(serde_json::from_str)
24		.transpose()?
25		.unwrap_or_default();
26
27	let response = get_messages(&services, MessagesArgs {
28		room_id: &body.room_id,
29		sender_user: body.sender_user(),
30		sender_device: body.sender_device.as_deref(),
31		from: body.from.as_deref(),
32		to: body.to.as_deref(),
33		dir: body.dir.unwrap_or(Direction::Forward),
34		limit: body.limit,
35		filter: &filter,
36		bypass_visibility: true,
37	})
38	.await?;
39
40	Ok(Response {
41		start: response.start,
42		end: response.end,
43		chunk: response.chunk,
44		state: response.state,
45	})
46}