Skip to main content

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