2024-11-22 12:25:46 +00:00
|
|
|
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
|
|
|
|
2024-10-30 07:01:50 +00:00
|
|
|
use super::AccessCheck;
|
|
|
|
|
use crate::Ruma;
|
2024-06-05 04:32:58 +00:00
|
|
|
|
|
|
|
|
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
|
|
|
|
|
///
|
2024-06-07 01:48:05 -04:00
|
|
|
/// 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-12-15 00:05:47 -05: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> {
|
2024-10-30 07:01:50 +00:00
|
|
|
AccessCheck {
|
|
|
|
|
services: &services,
|
|
|
|
|
origin: body.origin(),
|
|
|
|
|
room_id: &body.room_id,
|
|
|
|
|
event_id: None,
|
2024-06-05 04:32:58 +00:00
|
|
|
}
|
2024-10-30 07:01:50 +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
|
2024-11-22 12:25:46 +00:00
|
|
|
.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
|
|
|
|
2024-12-15 00:05:47 -05:00
|
|
|
Ok(get_room_state_ids::v1::Response { auth_chain_ids, pdu_ids })
|
2024-06-05 04:32:58 +00:00
|
|
|
}
|