eliminate references to services.globals.config

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-01-24 07:02:56 +00:00
parent 7c6b8b132a
commit 5be07ebc0f
26 changed files with 116 additions and 114 deletions

View file

@ -299,7 +299,7 @@ pub(crate) async fn register_route(
if !services.globals.new_user_displayname_suffix().is_empty()
&& body.appservice_info.is_none()
{
write!(displayname, " {}", services.globals.config.new_user_displayname_suffix)
write!(displayname, " {}", services.server.config.new_user_displayname_suffix)
.expect("should be able to write to string buffer");
}
@ -365,7 +365,7 @@ pub(crate) async fn register_route(
\"{device_display_name}\""
);
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
@ -378,7 +378,7 @@ pub(crate) async fn register_route(
} else {
info!("New user \"{user_id}\" registered on this server.");
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
@ -395,7 +395,7 @@ pub(crate) async fn register_route(
info!("New guest user \"{user_id}\" registered on this server.");
if !device_display_name.is_empty() {
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
@ -407,7 +407,7 @@ pub(crate) async fn register_route(
}
} else {
#[allow(clippy::collapsible_else_if)]
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
@ -438,10 +438,10 @@ pub(crate) async fn register_route(
}
if body.appservice_info.is_none()
&& !services.globals.config.auto_join_rooms.is_empty()
&& !services.server.config.auto_join_rooms.is_empty()
&& (services.globals.allow_guests_auto_join_rooms() || !is_guest)
{
for room in &services.globals.config.auto_join_rooms {
for room in &services.server.config.auto_join_rooms {
let Ok(room_id) = services.rooms.alias.resolve(room).await else {
error!(
"Failed to resolve room alias to room ID when attempting to auto join \
@ -570,7 +570,7 @@ pub(crate) async fn change_password_route(
info!("User {sender_user} changed their password.");
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
@ -673,7 +673,7 @@ pub(crate) async fn deactivate_route(
info!("User {sender_user} deactivated their account.");
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(

View file

@ -152,7 +152,7 @@ pub(crate) async fn set_room_visibility_route(
match &body.visibility {
| room::Visibility::Public => {
if services.globals.config.lockdown_public_room_directory
if services.server.config.lockdown_public_room_directory
&& !services.users.is_admin(sender_user).await
&& body.appservice_info.is_none()
{
@ -162,7 +162,7 @@ pub(crate) async fn set_room_visibility_route(
body.room_id
);
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_text(&format!(
@ -181,7 +181,7 @@ pub(crate) async fn set_room_visibility_route(
services.rooms.directory.set_public(&body.room_id);
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_text(&format!(

View file

@ -31,7 +31,7 @@ pub(crate) async fn get_media_config_route(
_body: Ruma<get_media_config::v1::Request>,
) -> Result<get_media_config::v1::Response> {
Ok(get_media_config::v1::Response {
upload_size: ruma_from_usize(services.globals.config.max_request_size),
upload_size: ruma_from_usize(services.server.config.max_request_size),
})
}

View file

@ -27,7 +27,7 @@ pub(crate) async fn get_media_config_legacy_route(
_body: Ruma<get_media_config::v3::Request>,
) -> Result<get_media_config::v3::Response> {
Ok(get_media_config::v3::Response {
upload_size: ruma_from_usize(services.globals.config.max_request_size),
upload_size: ruma_from_usize(services.server.config.max_request_size),
})
}

View file

@ -71,7 +71,7 @@ async fn banned_room_check(
if let Some(room_id) = room_id {
if services.rooms.metadata.is_banned(room_id).await
|| services
.globals
.server
.config
.forbidden_remote_server_names
.contains(&room_id.server_name().unwrap().to_owned())
@ -81,12 +81,12 @@ async fn banned_room_check(
attempted to join a banned room or banned room server name: {room_id}"
);
if services.globals.config.auto_deactivate_banned_room_attempts {
if services.server.config.auto_deactivate_banned_room_attempts {
warn!(
"Automatically deactivating user {user_id} due to attempted banned room join"
);
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::text_plain(format!(
@ -112,7 +112,7 @@ async fn banned_room_check(
}
} else if let Some(server_name) = server_name {
if services
.globals
.server
.config
.forbidden_remote_server_names
.contains(&server_name.to_owned())
@ -122,12 +122,12 @@ async fn banned_room_check(
name {server_name} that is globally forbidden. Rejecting.",
);
if services.globals.config.auto_deactivate_banned_room_attempts {
if services.server.config.auto_deactivate_banned_room_attempts {
warn!(
"Automatically deactivating user {user_id} due to attempted banned room join"
);
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_message(RoomMessageEventContent::text_plain(format!(

View file

@ -37,7 +37,7 @@ pub(crate) async fn create_openid_token_route(
Ok(account::request_openid_token::v3::Response {
access_token,
token_type: TokenType::Bearer,
matrix_server_name: services.globals.config.server_name.clone(),
matrix_server_name: services.server.config.server_name.clone(),
expires_in: Duration::from_secs(expires_in),
})
}

View file

@ -50,7 +50,7 @@ pub(crate) async fn report_room_route(
if !services
.rooms
.state_cache
.server_in_room(&services.globals.config.server_name, &body.room_id)
.server_in_room(&services.server.config.server_name, &body.room_id)
.await
{
return Err!(Request(NotFound(

View file

@ -71,7 +71,7 @@ pub(crate) async fn create_room_route(
let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id {
custom_room_id_check(&services, custom_room_id)?
} else {
RoomId::new(&services.globals.config.server_name)
RoomId::new(&services.server.config.server_name)
};
// check if room ID doesn't already exist instead of erroring on auth check
@ -83,7 +83,7 @@ pub(crate) async fn create_room_route(
}
if body.visibility == room::Visibility::Public
&& services.globals.config.lockdown_public_room_directory
&& services.server.config.lockdown_public_room_directory
&& !services.users.is_admin(sender_user).await
&& body.appservice_info.is_none()
{
@ -93,7 +93,7 @@ pub(crate) async fn create_room_route(
&room_id
);
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_text(&format!(
@ -450,7 +450,7 @@ pub(crate) async fn create_room_route(
if body.visibility == room::Visibility::Public {
services.rooms.directory.set_public(&room_id);
if services.globals.config.admin_room_notices {
if services.server.config.admin_room_notices {
services
.admin
.send_text(&format!(

View file

@ -1,5 +1,5 @@
use axum::extract::State;
use conduwuit::Err;
use conduwuit::{utils::math::Tried, Err};
use ruma::api::client::typing::create_typing_event;
use crate::{utils, Result, Ruma};
@ -31,17 +31,15 @@ pub(crate) async fn create_typing_event_route(
let duration = utils::clamp(
duration.as_millis().try_into().unwrap_or(u64::MAX),
services
.globals
.server
.config
.typing_client_timeout_min_s
.checked_mul(1000)
.unwrap(),
.try_mul(1000)?,
services
.globals
.server
.config
.typing_client_timeout_max_s
.checked_mul(1000)
.unwrap(),
.try_mul(1000)?,
);
services
.rooms

View file

@ -38,7 +38,7 @@ pub(crate) async fn turn_server_route(
let user = body.sender_user.unwrap_or_else(|| {
UserId::parse_with_server_name(
utils::random_string(RANDOM_USER_ID_LENGTH).to_lowercase(),
&services.globals.config.server_name,
&services.server.config.server_name,
)
.unwrap()
});