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

@ -22,7 +22,11 @@ pub(crate) async fn create_alias_route(
) -> Result<create_alias::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
service::rooms::alias::appservice_checks(&body.room_alias, &body.appservice_info).await?;
services
.rooms
.alias
.appservice_checks(&body.room_alias, &body.appservice_info)
.await?;
// this isn't apart of alias_checks or delete alias route because we should
// allow removing forbidden room aliases
@ -61,7 +65,11 @@ pub(crate) async fn delete_alias_route(
) -> Result<delete_alias::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
service::rooms::alias::appservice_checks(&body.room_alias, &body.appservice_info).await?;
services
.rooms
.alias
.appservice_checks(&body.room_alias, &body.appservice_info)
.await?;
if services
.rooms

View file

@ -43,7 +43,6 @@ use crate::{
service::{
pdu::{gen_event_id_canonical_json, PduBuilder},
rooms::state::RoomMutexGuard,
sending::convert_to_outgoing_federation_event,
server_is_ours, user_is_local, Services,
},
Ruma,
@ -791,7 +790,9 @@ async fn join_room_by_id_helper_remote(
federation::membership::create_join_event::v2::Request {
room_id: room_id.to_owned(),
event_id: event_id.to_owned(),
pdu: convert_to_outgoing_federation_event(join_event.clone()),
pdu: services
.sending
.convert_to_outgoing_federation_event(join_event.clone()),
omit_members: false,
},
)
@ -1203,7 +1204,9 @@ async fn join_room_by_id_helper_local(
federation::membership::create_join_event::v2::Request {
room_id: room_id.to_owned(),
event_id: event_id.to_owned(),
pdu: convert_to_outgoing_federation_event(join_event.clone()),
pdu: services
.sending
.convert_to_outgoing_federation_event(join_event.clone()),
omit_members: false,
},
)
@ -1431,7 +1434,9 @@ pub(crate) async fn invite_helper(
room_id: room_id.to_owned(),
event_id: (*pdu.event_id).to_owned(),
room_version: room_version_id.clone(),
event: convert_to_outgoing_federation_event(pdu_json.clone()),
event: services
.sending
.convert_to_outgoing_federation_event(pdu_json.clone()),
invite_room_state,
via: services.rooms.state_cache.servers_route_via(room_id).ok(),
},
@ -1763,7 +1768,9 @@ async fn remote_leave_room(services: &Services, user_id: &UserId, room_id: &Room
federation::membership::create_leave_event::v2::Request {
room_id: room_id.to_owned(),
event_id,
pdu: convert_to_outgoing_federation_event(leave_event.clone()),
pdu: services
.sending
.convert_to_outgoing_federation_event(leave_event.clone()),
},
)
.await?;

View file

@ -475,8 +475,6 @@ async fn handle_left_room(
async fn process_presence_updates(
services: &Services, presence_updates: &mut HashMap<OwnedUserId, PresenceEvent>, since: u64, syncing_user: &UserId,
) -> Result<()> {
use crate::service::presence::Presence;
// Take presence updates
for (user_id, _, presence_bytes) in services.presence.presence_since(since) {
if !services
@ -487,7 +485,9 @@ async fn process_presence_updates(
continue;
}
let presence_event = Presence::from_json_bytes_to_event(&presence_bytes, &user_id)?;
let presence_event = services
.presence
.from_json_bytes_to_event(&presence_bytes, &user_id)?;
match presence_updates.entry(user_id) {
Entry::Vacant(slot) => {
slot.insert(presence_event);

View file

@ -1,3 +1,5 @@
#![recursion_limit = "160"]
pub mod client;
pub mod router;
pub mod server;

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,