2024-07-16 08:05:25 +00:00
|
|
|
use axum::extract::State;
|
2024-06-10 21:04:51 -04:00
|
|
|
use axum_client_ip::InsecureClientIp;
|
2025-04-04 03:30:13 +00:00
|
|
|
use conduwuit::{Error, Result};
|
2024-06-05 04:32:58 +00:00
|
|
|
use ruma::{
|
|
|
|
api::{
|
|
|
|
client::error::ErrorKind,
|
|
|
|
federation::directory::{get_public_rooms, get_public_rooms_filtered},
|
|
|
|
},
|
|
|
|
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>,
|
|
|
|
InsecureClientIp(client): InsecureClientIp,
|
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
|
|
|
{
|
|
|
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "Room directory is not public"));
|
|
|
|
}
|
|
|
|
|
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
|
2024-12-15 00:05:47 -05:00
|
|
|
.map_err(|_| {
|
|
|
|
Error::BadRequest(ErrorKind::Unknown, "Failed to return this server's public room list.")
|
|
|
|
})?;
|
2024-06-05 04:32:58 +00:00
|
|
|
|
|
|
|
Ok(get_public_rooms_filtered::v1::Response {
|
|
|
|
chunk: response.chunk,
|
|
|
|
prev_batch: response.prev_batch,
|
|
|
|
next_batch: response.next_batch,
|
|
|
|
total_room_count_estimate: response.total_room_count_estimate,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// # `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>,
|
|
|
|
InsecureClientIp(client): InsecureClientIp,
|
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()
|
|
|
|
{
|
|
|
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "Room directory is not public"));
|
|
|
|
}
|
|
|
|
|
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
|
2024-12-15 00:05:47 -05:00
|
|
|
.map_err(|_| {
|
|
|
|
Error::BadRequest(ErrorKind::Unknown, "Failed to return this server's public room list.")
|
|
|
|
})?;
|
2024-06-05 04:32:58 +00:00
|
|
|
|
|
|
|
Ok(get_public_rooms::v1::Response {
|
|
|
|
chunk: response.chunk,
|
|
|
|
prev_batch: response.prev_batch,
|
|
|
|
next_batch: response.next_batch,
|
|
|
|
total_room_count_estimate: response.total_room_count_estimate,
|
|
|
|
})
|
|
|
|
}
|