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

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

69 lines
1.5 KiB
Rust
Raw Normal View History

2024-06-05 04:32:58 +00:00
use std::sync::Arc;
2024-07-16 08:05:25 +00:00
use axum::extract::State;
2024-08-08 17:18:30 +00:00
use conduit::{err, Err};
use futures::StreamExt;
use ruma::api::federation::event::get_room_state_ids;
2024-06-05 04:32:58 +00:00
2024-08-08 17:18:30 +00:00
use crate::{Result, Ruma};
2024-06-05 04:32:58 +00:00
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
///
/// Retrieves a snapshot of a room's state at a given event, in the form of
/// event IDs.
2024-06-05 04:32:58 +00:00
pub(crate) async fn get_room_state_ids_route(
2024-07-16 08:05:25 +00:00
State(services): State<crate::State>, body: Ruma<get_room_state_ids::v1::Request>,
2024-06-05 04:32:58 +00:00
) -> Result<get_room_state_ids::v1::Response> {
let origin = body.origin.as_ref().expect("server is authenticated");
2024-07-16 08:05:25 +00:00
services
.rooms
.event_handler
2024-08-08 17:18:30 +00:00
.acl_check(origin, &body.room_id)
.await?;
2024-07-16 08:05:25 +00:00
if !services
2024-06-05 04:32:58 +00:00
.rooms
.state_accessor
2024-08-08 17:18:30 +00:00
.is_world_readable(&body.room_id)
.await && !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)
.await
2024-06-05 04:32:58 +00:00
{
2024-08-08 17:18:30 +00:00
return Err!(Request(Forbidden("Server is not in room.")));
2024-06-05 04:32:58 +00:00
}
2024-07-16 08:05:25 +00:00
let shortstatehash = services
2024-06-05 04:32:58 +00:00
.rooms
.state_accessor
2024-08-08 17:18:30 +00:00
.pdu_shortstatehash(&body.event_id)
.await
.map_err(|_| err!(Request(NotFound("Pdu state not found."))))?;
2024-06-05 04:32:58 +00:00
2024-07-16 08:05:25 +00:00
let pdu_ids = services
2024-06-05 04:32:58 +00:00
.rooms
.state_accessor
.state_full_ids(shortstatehash)
2024-08-08 17:18:30 +00:00
.await
.map_err(|_| err!(Request(NotFound("State ids not found"))))?
2024-06-05 04:32:58 +00:00
.into_values()
.map(|id| (*id).to_owned())
.collect();
2024-07-16 08:05:25 +00:00
let auth_chain_ids = services
2024-06-05 04:32:58 +00:00
.rooms
.auth_chain
.event_ids_iter(&body.room_id, vec![Arc::from(&*body.event_id)])
2024-08-08 17:18:30 +00:00
.await?
.map(|id| (*id).to_owned())
.collect()
.await;
2024-06-05 04:32:58 +00:00
Ok(get_room_state_ids::v1::Response {
2024-08-08 17:18:30 +00:00
auth_chain_ids,
2024-06-05 04:32:58 +00:00
pdu_ids,
})
}