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,18 +1,19 @@
use axum::extract::State;
use ruma::api::client::{error::ErrorKind, typing::create_typing_event};
use crate::{services, utils, Error, Result, Ruma};
use crate::{utils, Error, Result, Ruma};
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`
///
/// Sets the typing state of the sender user.
pub(crate) async fn create_typing_event_route(
body: Ruma<create_typing_event::v3::Request>,
State(services): State<crate::State>, body: Ruma<create_typing_event::v3::Request>,
) -> Result<create_typing_event::v3::Response> {
use create_typing_event::v3::Typing;
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if !services()
if !services
.rooms
.state_cache
.is_joined(sender_user, &body.room_id)?
@ -23,20 +24,20 @@ pub(crate) async fn create_typing_event_route(
if let Typing::Yes(duration) = body.state {
let duration = utils::clamp(
duration.as_millis().try_into().unwrap_or(u64::MAX),
services()
services
.globals
.config
.typing_client_timeout_min_s
.checked_mul(1000)
.unwrap(),
services()
services
.globals
.config
.typing_client_timeout_max_s
.checked_mul(1000)
.unwrap(),
);
services()
services
.rooms
.typing
.typing_add(
@ -48,7 +49,7 @@ pub(crate) async fn create_typing_event_route(
)
.await?;
} else {
services()
services
.rooms
.typing
.typing_remove(sender_user, &body.room_id)