Files
continuwuity/src/api/server/publicrooms.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.3 KiB
Rust
Raw Normal View History

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;
use conduwuit::{Err, Result, err};
2024-06-05 04:32:58 +00:00
use ruma::{
api::federation::directory::{get_public_rooms, get_public_rooms_filtered},
assign,
2024-06-05 04:32:58 +00:00
directory::Filter,
};
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(
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
.server
.config
.allow_public_room_directory_over_federation
2024-06-05 04:32:58 +00: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
.map_err(|_| err!(Request(Unknown("Failed to return this server's public room list."))))?;
2024-06-05 04:32:58 +00: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,
}))
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(
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()
{
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
.map_err(|_| err!(Request(Unknown("Failed to return this server's public room list."))))?;
2024-06-05 04:32:58 +00: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,
}))
2024-06-05 04:32:58 +00:00
}