de-global services for services

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-18 06:37:47 +00:00
parent 992c0a1e58
commit 010e4ee35a
85 changed files with 2480 additions and 1887 deletions

View file

@ -4,7 +4,6 @@ use ruma::{
api::{client::error::ErrorKind, federation::backfill::get_backfill},
uint, user_id, MilliSecondsSinceUnixEpoch,
};
use service::sending::convert_to_outgoing_federation_event;
use crate::Ruma;
@ -67,7 +66,7 @@ pub(crate) async fn get_backfill_route(
})
.map(|(_, pdu)| services.rooms.timeline.get_pdu_json(&pdu.event_id))
.filter_map(|r| r.ok().flatten())
.map(convert_to_outgoing_federation_event)
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect();
Ok(get_backfill::v1::Response {

View file

@ -4,7 +4,6 @@ use ruma::{
api::{client::error::ErrorKind, federation::event::get_event},
MilliSecondsSinceUnixEpoch, RoomId,
};
use service::sending::convert_to_outgoing_federation_event;
use crate::Ruma;
@ -50,6 +49,6 @@ pub(crate) async fn get_event_route(
Ok(get_event::v1::Response {
origin: services.globals.server_name().to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
pdu: convert_to_outgoing_federation_event(event),
pdu: services.sending.convert_to_outgoing_federation_event(event),
})
}

View file

@ -6,7 +6,6 @@ use ruma::{
api::{client::error::ErrorKind, federation::authorization::get_event_authorization},
RoomId,
};
use service::sending::convert_to_outgoing_federation_event;
use crate::Ruma;
@ -60,7 +59,7 @@ pub(crate) async fn get_event_authorization_route(
Ok(get_event_authorization::v1::Response {
auth_chain: auth_chain_ids
.filter_map(|id| services.rooms.timeline.get_pdu_json(&id).ok()?)
.map(convert_to_outgoing_federation_event)
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect(),
})
}

View file

@ -4,7 +4,6 @@ use ruma::{
api::{client::error::ErrorKind, federation::event::get_missing_events},
OwnedEventId, RoomId,
};
use service::sending::convert_to_outgoing_federation_event;
use crate::Ruma;
@ -82,7 +81,7 @@ pub(crate) async fn get_missing_events_route(
)
.map_err(|_| Error::bad_database("Invalid prev_events in event in database."))?,
);
events.push(convert_to_outgoing_federation_event(pdu));
events.push(services.sending.convert_to_outgoing_federation_event(pdu));
}
i = i.saturating_add(1);
}

View file

@ -7,7 +7,7 @@ use ruma::{
serde::JsonObject,
CanonicalJsonValue, EventId, OwnedUserId,
};
use service::{sending::convert_to_outgoing_federation_event, server_is_ours};
use service::server_is_ours;
use crate::Ruma;
@ -174,6 +174,8 @@ pub(crate) async fn create_invite_route(
}
Ok(create_invite::v2::Response {
event: convert_to_outgoing_federation_event(signed_event),
event: services
.sending
.convert_to_outgoing_federation_event(signed_event),
})
}

View file

@ -21,7 +21,6 @@ use ruma::{
use tokio::sync::RwLock;
use crate::{
service::rooms::event_handler::parse_incoming_pdu,
services::Services,
utils::{self},
Error, Result, Ruma,
@ -89,7 +88,7 @@ async fn handle_pdus(
) -> Result<ResolvedMap> {
let mut parsed_pdus = Vec::with_capacity(body.pdus.len());
for pdu in &body.pdus {
parsed_pdus.push(match parse_incoming_pdu(pdu) {
parsed_pdus.push(match services.rooms.event_handler.parse_incoming_pdu(pdu) {
Ok(t) => t,
Err(e) => {
debug_warn!("Could not parse PDU: {e}");

View file

@ -13,9 +13,7 @@ use ruma::{
CanonicalJsonValue, OwnedServerName, OwnedUserId, RoomId, ServerName,
};
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use service::{
pdu::gen_event_id_canonical_json, sending::convert_to_outgoing_federation_event, user_is_local, Services,
};
use service::{pdu::gen_event_id_canonical_json, user_is_local, Services};
use tokio::sync::RwLock;
use tracing::warn;
@ -186,12 +184,12 @@ async fn create_join_event(
Ok(create_join_event::v1::RoomState {
auth_chain: auth_chain_ids
.filter_map(|id| services.rooms.timeline.get_pdu_json(&id).ok().flatten())
.map(convert_to_outgoing_federation_event)
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect(),
state: state_ids
.iter()
.filter_map(|(_, id)| services.rooms.timeline.get_pdu_json(id).ok().flatten())
.map(convert_to_outgoing_federation_event)
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect(),
// Event field is required if the room version supports restricted join rules.
event: Some(

View file

@ -3,7 +3,6 @@ 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;
use crate::Ruma;
@ -44,7 +43,11 @@ pub(crate) async fn get_room_state_route(
.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| {
services
.sending
.convert_to_outgoing_federation_event(services.rooms.timeline.get_pdu_json(&id).unwrap().unwrap())
})
.collect();
let auth_chain_ids = services
@ -61,7 +64,7 @@ pub(crate) async fn get_room_state_route(
.timeline
.get_pdu_json(&id)
.ok()?
.map(convert_to_outgoing_federation_event)
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
})
.collect(),
pdus,