don't automatically wrap in RumaResponse

This allows us to use the `ruma_route` convenience function even when we
need to add our own hacks into the responses, thus making us less
reliant on Ruma.
This commit is contained in:
Charles Hall 2024-05-18 18:31:36 -07:00
parent 87ac0e2a38
commit 230ebd3884
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
35 changed files with 438 additions and 405 deletions

View file

@ -29,7 +29,7 @@ use ruma::{
};
use tracing::{error, info, warn};
use crate::{services, Error, Result, Ruma};
use crate::{services, Error, Result, Ruma, RumaResponse};
/// # `POST /_matrix/client/r0/publicRooms`
///
@ -38,7 +38,7 @@ use crate::{services, Error, Result, Ruma};
/// - Rooms are ordered by the number of joined members
pub(crate) async fn get_public_rooms_filtered_route(
body: Ruma<get_public_rooms_filtered::v3::Request>,
) -> Result<get_public_rooms_filtered::v3::Response> {
) -> Result<RumaResponse<get_public_rooms_filtered::v3::Response>> {
get_public_rooms_filtered_helper(
body.server.as_deref(),
body.limit,
@ -47,6 +47,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
&body.room_network,
)
.await
.map(RumaResponse)
}
/// # `GET /_matrix/client/r0/publicRooms`
@ -56,7 +57,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
/// - Rooms are ordered by the number of joined members
pub(crate) async fn get_public_rooms_route(
body: Ruma<get_public_rooms::v3::Request>,
) -> Result<get_public_rooms::v3::Response> {
) -> Result<RumaResponse<get_public_rooms::v3::Response>> {
let response = get_public_rooms_filtered_helper(
body.server.as_deref(),
body.limit,
@ -66,12 +67,12 @@ pub(crate) async fn get_public_rooms_route(
)
.await?;
Ok(get_public_rooms::v3::Response {
Ok(RumaResponse(get_public_rooms::v3::Response {
chunk: response.chunk,
prev_batch: response.prev_batch,
next_batch: response.next_batch,
total_room_count_estimate: response.total_room_count_estimate,
})
}))
}
/// # `PUT /_matrix/client/r0/directory/list/room/{roomId}`
@ -81,7 +82,7 @@ pub(crate) async fn get_public_rooms_route(
/// - TODO: Access control checks
pub(crate) async fn set_room_visibility_route(
body: Ruma<set_room_visibility::v3::Request>,
) -> Result<set_room_visibility::v3::Response> {
) -> Result<RumaResponse<set_room_visibility::v3::Response>> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if !services().rooms.metadata.exists(&body.room_id)? {
@ -105,7 +106,7 @@ pub(crate) async fn set_room_visibility_route(
}
}
Ok(set_room_visibility::v3::Response {})
Ok(RumaResponse(set_room_visibility::v3::Response {}))
}
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
@ -113,13 +114,13 @@ pub(crate) async fn set_room_visibility_route(
/// Gets the visibility of a given room in the room directory.
pub(crate) async fn get_room_visibility_route(
body: Ruma<get_room_visibility::v3::Request>,
) -> Result<get_room_visibility::v3::Response> {
) -> Result<RumaResponse<get_room_visibility::v3::Response>> {
if !services().rooms.metadata.exists(&body.room_id)? {
// Return 404 if the room doesn't exist
return Err(Error::BadRequest(ErrorKind::NotFound, "Room not found"));
}
Ok(get_room_visibility::v3::Response {
Ok(RumaResponse(get_room_visibility::v3::Response {
visibility: if services()
.rooms
.directory
@ -129,7 +130,7 @@ pub(crate) async fn get_room_visibility_route(
} else {
room::Visibility::Private
},
})
}))
}
#[allow(clippy::too_many_lines)]