combine service/users data w/ mod unit split sliding sync related out of service/users instrument database entry points remove increment crap from database interface de-wrap all database get() calls de-wrap all database insert() calls de-wrap all database remove() calls refactor database interface for async streaming add query key serializer for database implement Debug for result handle add query deserializer for database add deserialization trait for option handle start a stream utils suite de-wrap/asyncify/type-query count_one_time_keys() de-wrap/asyncify users count add admin query users command suite de-wrap/asyncify users exists de-wrap/partially asyncify user filter related asyncify/de-wrap users device/keys related asyncify/de-wrap user auth/misc related asyncify/de-wrap users blurhash asyncify/de-wrap account_data get; merge Data into Service partial asyncify/de-wrap uiaa; merge Data into Service partially asyncify/de-wrap transaction_ids get; merge Data into Service partially asyncify/de-wrap key_backups; merge Data into Service asyncify/de-wrap pusher service getters; merge Data into Service asyncify/de-wrap rooms alias getters/some iterators asyncify/de-wrap rooms directory getters/iterator partially asyncify/de-wrap rooms lazy-loading partially asyncify/de-wrap rooms metadata asyncify/dewrap rooms outlier asyncify/dewrap rooms pdu_metadata dewrap/partially asyncify rooms read receipt de-wrap rooms search service de-wrap/partially asyncify rooms user service partial de-wrap rooms state_compressor de-wrap rooms state_cache de-wrap room state et al de-wrap rooms timeline service additional users device/keys related de-wrap/asyncify sender asyncify services refactor database to TryFuture/TryStream refactor services for TryFuture/TryStream asyncify api handlers additional asyncification for admin module abstract stream related; support reverse streams additional stream conversions asyncify state-res related Signed-off-by: Jason Volk <jason@zemos.net>
61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
use axum::extract::State;
|
|
use ruma::api::client::{error::ErrorKind, typing::create_typing_event};
|
|
|
|
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(
|
|
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
|
|
.rooms
|
|
.state_cache
|
|
.is_joined(sender_user, &body.room_id)
|
|
.await
|
|
{
|
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "You are not in this room."));
|
|
}
|
|
|
|
if let Typing::Yes(duration) = body.state {
|
|
let duration = utils::clamp(
|
|
duration.as_millis().try_into().unwrap_or(u64::MAX),
|
|
services
|
|
.globals
|
|
.config
|
|
.typing_client_timeout_min_s
|
|
.checked_mul(1000)
|
|
.unwrap(),
|
|
services
|
|
.globals
|
|
.config
|
|
.typing_client_timeout_max_s
|
|
.checked_mul(1000)
|
|
.unwrap(),
|
|
);
|
|
services
|
|
.rooms
|
|
.typing
|
|
.typing_add(
|
|
sender_user,
|
|
&body.room_id,
|
|
utils::millis_since_unix_epoch()
|
|
.checked_add(duration)
|
|
.expect("user typing timeout should not get this high"),
|
|
)
|
|
.await?;
|
|
} else {
|
|
services
|
|
.rooms
|
|
.typing
|
|
.typing_remove(sender_user, &body.room_id)
|
|
.await?;
|
|
}
|
|
|
|
Ok(create_typing_event::v3::Response {})
|
|
}
|