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.

55 lines
1.3 KiB
Rust
Raw Normal View History

use std::{borrow::Borrow, iter::once};
2024-06-05 04:32:58 +00:00
2024-07-16 08:05:25 +00:00
use axum::extract::State;
2024-12-14 21:58:01 -05:00
use conduwuit::{err, Result};
2024-08-08 17:18:30 +00:00
use futures::StreamExt;
2024-11-30 08:09:51 +00:00
use ruma::{api::federation::event::get_room_state_ids, OwnedEventId};
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(
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-11-30 08:09:51 +00:00
let pdu_ids: Vec<OwnedEventId> = 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()
.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, once(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 { auth_chain_ids, pdu_ids })
2024-06-05 04:32:58 +00:00
}