2024-07-16 08:05:25 +00:00
|
|
|
use axum::extract::State;
|
2026-04-23 20:02:48 +01:00
|
|
|
use axum_client_ip::ClientIp;
|
2026-04-13 12:13:13 -04:00
|
|
|
use conduwuit::{Err, Result, err};
|
2024-06-05 04:32:58 +00:00
|
|
|
use ruma::{
|
2026-04-13 12:13:13 -04:00
|
|
|
api::federation::directory::{get_public_rooms, get_public_rooms_filtered},
|
|
|
|
|
assign,
|
2024-06-05 04:32:58 +00:00
|
|
|
directory::Filter,
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-04 03:30:13 +00:00
|
|
|
use crate::Ruma;
|
2024-06-05 04:32:58 +00:00
|
|
|
|
|
|
|
|
/// # `POST /_matrix/federation/v1/publicRooms`
|
|
|
|
|
///
|
|
|
|
|
/// Lists the public rooms on this server.
|
2025-01-26 04:46:10 +00:00
|
|
|
#[tracing::instrument(name = "publicrooms", level = "debug", skip_all, fields(%client))]
|
2024-06-05 04:32:58 +00:00
|
|
|
pub(crate) async fn get_public_rooms_filtered_route(
|
2024-12-15 00:05:47 -05:00
|
|
|
State(services): State<crate::State>,
|
2026-04-23 20:02:48 +01:00
|
|
|
ClientIp(client): ClientIp,
|
2024-07-16 08:05:25 +00:00
|
|
|
body: Ruma<get_public_rooms_filtered::v1::Request>,
|
2024-06-05 04:32:58 +00:00
|
|
|
) -> Result<get_public_rooms_filtered::v1::Response> {
|
2024-07-16 08:05:25 +00:00
|
|
|
if !services
|
2025-01-24 07:02:56 +00:00
|
|
|
.server
|
2024-10-27 12:37:44 -04:00
|
|
|
.config
|
|
|
|
|
.allow_public_room_directory_over_federation
|
2024-06-05 04:32:58 +00:00
|
|
|
{
|
2026-04-13 12:13:13 -04:00
|
|
|
return Err!(Request(Forbidden("Room directory is not public")));
|
2024-06-05 04:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-06 18:21:02 +00:00
|
|
|
let response = crate::client::get_public_rooms_filtered_helper(
|
2024-07-27 07:17:07 +00:00
|
|
|
&services,
|
2024-06-05 04:32:58 +00:00
|
|
|
None,
|
|
|
|
|
body.limit,
|
|
|
|
|
body.since.as_deref(),
|
|
|
|
|
&body.filter,
|
|
|
|
|
&body.room_network,
|
|
|
|
|
)
|
|
|
|
|
.await
|
2026-04-13 12:13:13 -04:00
|
|
|
.map_err(|_| err!(Request(Unknown("Failed to return this server's public room list."))))?;
|
2024-06-05 04:32:58 +00:00
|
|
|
|
2026-04-13 12:13:13 -04:00
|
|
|
Ok(assign!(get_public_rooms_filtered::v1::Response::new(), {
|
2024-06-05 04:32:58 +00:00
|
|
|
chunk: response.chunk,
|
|
|
|
|
prev_batch: response.prev_batch,
|
|
|
|
|
next_batch: response.next_batch,
|
|
|
|
|
total_room_count_estimate: response.total_room_count_estimate,
|
2026-04-13 12:13:13 -04:00
|
|
|
}))
|
2024-06-05 04:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// # `GET /_matrix/federation/v1/publicRooms`
|
|
|
|
|
///
|
|
|
|
|
/// Lists the public rooms on this server.
|
2025-01-26 04:46:10 +00:00
|
|
|
#[tracing::instrument(name = "publicrooms", level = "debug", skip_all, fields(%client))]
|
2024-06-05 04:32:58 +00:00
|
|
|
pub(crate) async fn get_public_rooms_route(
|
2024-12-15 00:05:47 -05:00
|
|
|
State(services): State<crate::State>,
|
2026-04-23 20:02:48 +01:00
|
|
|
ClientIp(client): ClientIp,
|
2024-07-16 08:05:25 +00:00
|
|
|
body: Ruma<get_public_rooms::v1::Request>,
|
2024-06-05 04:32:58 +00:00
|
|
|
) -> Result<get_public_rooms::v1::Response> {
|
2024-07-16 08:05:25 +00:00
|
|
|
if !services
|
2024-06-05 04:32:58 +00:00
|
|
|
.globals
|
|
|
|
|
.allow_public_room_directory_over_federation()
|
|
|
|
|
{
|
2026-04-13 12:13:13 -04:00
|
|
|
return Err!(Request(Forbidden("Room directory is not public")));
|
2024-06-05 04:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-06 18:21:02 +00:00
|
|
|
let response = crate::client::get_public_rooms_filtered_helper(
|
2024-07-27 07:17:07 +00:00
|
|
|
&services,
|
2024-06-05 04:32:58 +00:00
|
|
|
None,
|
|
|
|
|
body.limit,
|
|
|
|
|
body.since.as_deref(),
|
|
|
|
|
&Filter::default(),
|
|
|
|
|
&body.room_network,
|
|
|
|
|
)
|
|
|
|
|
.await
|
2026-04-13 12:13:13 -04:00
|
|
|
.map_err(|_| err!(Request(Unknown("Failed to return this server's public room list."))))?;
|
2024-06-05 04:32:58 +00:00
|
|
|
|
2026-04-13 12:13:13 -04:00
|
|
|
Ok(assign!(get_public_rooms::v1::Response::new(), {
|
2024-06-05 04:32:58 +00:00
|
|
|
chunk: response.chunk,
|
|
|
|
|
prev_batch: response.prev_batch,
|
|
|
|
|
next_batch: response.next_batch,
|
|
|
|
|
total_room_count_estimate: response.total_room_count_estimate,
|
2026-04-13 12:13:13 -04:00
|
|
|
}))
|
2024-06-05 04:32:58 +00:00
|
|
|
}
|