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.

58 lines
1.3 KiB
Rust
Raw Normal View History

2024-09-25 03:52:28 +00:00
use std::borrow::Borrow;
2024-06-05 04:32:58 +00:00
2024-07-16 08:05:25 +00:00
use axum::extract::State;
use conduit::{err, Result};
2024-08-08 17:18:30 +00:00
use futures::StreamExt;
use ruma::api::federation::event::get_room_state_ids;
2024-06-05 04:32:58 +00:00
use super::AccessCheck;
use crate::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> {
AccessCheck {
services: &services,
origin: body.origin(),
room_id: &body.room_id,
event_id: None,
2024-06-05 04:32:58 +00:00
}
.check()
.await?;
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
2024-09-25 03:52:28 +00:00
.event_ids_iter(&body.room_id, &[body.event_id.borrow()])
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,
})
}