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.

49 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;
use futures::{FutureExt, StreamExt, TryStreamExt, future::try_join};
use ruma::{OwnedEventId, api::federation::event::get_room_state_ids};
2025-04-22 01:41:02 +00:00
use tuwunel_core::{Result, at, err};
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,
}
.check()
.await?;
2024-07-16 08:05:25 +00:00
let shortstatehash = services
2024-06-05 04:32:58 +00:00
.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 auth_chain_ids = services
2024-06-05 04:32:58 +00:00
.auth_chain
.event_ids_iter(&body.room_id, once(body.event_id.borrow()))
.try_collect();
let pdu_ids = services
.state_accessor
.state_full_ids(shortstatehash)
.map(at!(1))
.collect::<Vec<OwnedEventId>>()
.map(Ok);
let (auth_chain_ids, pdu_ids) = try_join(auth_chain_ids, pdu_ids).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
}