Services refactor
Replace structs of Dep<Service> with OnceServices, so each service has a Services reference Remove service name => Service map Flatten Services.rooms Make reqwest Clients lazy initialized (client service)
This commit is contained in:
@@ -114,7 +114,6 @@ pub(crate) async fn create_room_route(
|
||||
// 2. Let the room creator join
|
||||
let sender_user = body.sender_user();
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(sender_user.to_string(), &RoomMemberEventContent {
|
||||
@@ -176,7 +175,6 @@ pub(crate) async fn create_room_route(
|
||||
)?;
|
||||
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
@@ -195,7 +193,6 @@ pub(crate) async fn create_room_route(
|
||||
// 4. Canonical room alias
|
||||
if let Some(room_alias_id) = &alias {
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(String::new(), &RoomCanonicalAliasEventContent {
|
||||
@@ -214,7 +211,6 @@ pub(crate) async fn create_room_route(
|
||||
|
||||
// 5.1 Join Rules
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
@@ -234,7 +230,6 @@ pub(crate) async fn create_room_route(
|
||||
|
||||
// 5.2 History Visibility
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
@@ -250,7 +245,6 @@ pub(crate) async fn create_room_route(
|
||||
|
||||
// 5.3 Guest Access
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
@@ -299,7 +293,6 @@ pub(crate) async fn create_room_route(
|
||||
}
|
||||
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
|
||||
.boxed()
|
||||
@@ -309,7 +302,6 @@ pub(crate) async fn create_room_route(
|
||||
// 7. Events implied by name and topic
|
||||
if let Some(name) = &body.name {
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(String::new(), &RoomNameEventContent::new(name.clone())),
|
||||
@@ -323,7 +315,6 @@ pub(crate) async fn create_room_route(
|
||||
|
||||
if let Some(topic) = &body.topic {
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(String::new(), &RoomTopicEventContent {
|
||||
@@ -371,13 +362,12 @@ pub(crate) async fn create_room_route(
|
||||
// Homeserver specific stuff
|
||||
if let Some(alias) = alias {
|
||||
services
|
||||
.rooms
|
||||
.alias
|
||||
.set_alias(&alias, &room_id, sender_user)?;
|
||||
}
|
||||
|
||||
if body.visibility == room::Visibility::Public {
|
||||
services.rooms.directory.set_public(&room_id);
|
||||
services.directory.set_public(&room_id);
|
||||
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
@@ -463,9 +453,8 @@ async fn create_create_event(
|
||||
|
||||
// 1. The room create event, using a placeholder room_id
|
||||
let room_id = ruma::room_id!("!thiswillbereplaced").to_owned();
|
||||
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
|
||||
let state_lock = services.state.mutex.lock(&room_id).await;
|
||||
let create_event_id = services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
@@ -485,7 +474,7 @@ async fn create_create_event(
|
||||
|
||||
// The real room_id is now the event_id.
|
||||
let room_id = OwnedRoomId::from_parts('!', create_event_id.localpart(), None)?;
|
||||
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
|
||||
let state_lock = services.state.mutex.lock(&room_id).await;
|
||||
|
||||
Ok((room_id, state_lock))
|
||||
}
|
||||
@@ -501,10 +490,9 @@ async fn create_create_event_legacy(
|
||||
| Some(custom_id) => custom_room_id_check(services, custom_id).await?,
|
||||
};
|
||||
|
||||
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
|
||||
let state_lock = services.state.mutex.lock(&room_id).await;
|
||||
|
||||
let _short_id = services
|
||||
.rooms
|
||||
.short
|
||||
.get_or_create_shortroomid(&room_id)
|
||||
.await;
|
||||
@@ -567,7 +555,6 @@ async fn create_create_event_legacy(
|
||||
|
||||
// 1. The room create event
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
@@ -681,7 +668,6 @@ async fn room_alias_check(
|
||||
})?;
|
||||
|
||||
if services
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(&full_room_alias)
|
||||
.await
|
||||
@@ -740,7 +726,6 @@ async fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Resu
|
||||
|
||||
// check if room ID doesn't already exist instead of erroring on auth check
|
||||
if services
|
||||
.rooms
|
||||
.short
|
||||
.get_shortroomid(&room_id)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user