de-global services() from api

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-16 08:05:25 +00:00
parent 463f1a1287
commit 8b6018d77d
61 changed files with 1485 additions and 1320 deletions

View file

@ -1,8 +1,9 @@
use std::sync::Arc;
use axum::extract::State;
use conduit::{Error, Result};
use ruma::api::{client::error::ErrorKind, federation::event::get_room_state};
use service::{sending::convert_to_outgoing_federation_event, services};
use service::sending::convert_to_outgoing_federation_event;
use crate::Ruma;
@ -10,20 +11,20 @@ use crate::Ruma;
///
/// Retrieves a snapshot of a room's state at a given event.
pub(crate) async fn get_room_state_route(
body: Ruma<get_room_state::v1::Request>,
State(services): State<crate::State>, body: Ruma<get_room_state::v1::Request>,
) -> Result<get_room_state::v1::Response> {
let origin = body.origin.as_ref().expect("server is authenticated");
services()
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
if !services()
if !services
.rooms
.state_accessor
.is_world_readable(&body.room_id)?
&& !services()
&& !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)?
@ -31,31 +32,22 @@ pub(crate) async fn get_room_state_route(
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not in room."));
}
let shortstatehash = services()
let shortstatehash = services
.rooms
.state_accessor
.pdu_shortstatehash(&body.event_id)?
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Pdu state not found."))?;
let pdus = services()
let pdus = services
.rooms
.state_accessor
.state_full_ids(shortstatehash)
.await?
.into_values()
.map(|id| {
convert_to_outgoing_federation_event(
services()
.rooms
.timeline
.get_pdu_json(&id)
.unwrap()
.unwrap(),
)
})
.map(|id| convert_to_outgoing_federation_event(services.rooms.timeline.get_pdu_json(&id).unwrap().unwrap()))
.collect();
let auth_chain_ids = services()
let auth_chain_ids = services
.rooms
.auth_chain
.event_ids_iter(&body.room_id, vec![Arc::from(&*body.event_id)])
@ -64,7 +56,7 @@ pub(crate) async fn get_room_state_route(
Ok(get_room_state::v1::Response {
auth_chain: auth_chain_ids
.filter_map(|id| {
services()
services
.rooms
.timeline
.get_pdu_json(&id)