conduit/src/client_server/typing.rs

34 lines
1019 B
Rust
Raw Normal View History

2021-07-14 07:07:08 +00:00
use crate::{database::DatabaseGuard, utils, ConduitResult, Ruma};
2020-09-08 15:32:03 +00:00
use create_typing_event::Typing;
2020-07-30 16:14:47 +00:00
use ruma::api::client::r0::typing::create_typing_event;
#[cfg(feature = "conduit_bin")]
use rocket::put;
#[cfg_attr(
feature = "conduit_bin",
put("/_matrix/client/r0/rooms/<_>/typing/<_>", data = "<body>")
)]
2021-02-28 11:41:03 +00:00
#[tracing::instrument(skip(db, body))]
2020-07-30 16:14:47 +00:00
pub fn create_typing_event_route(
2021-07-14 07:07:08 +00:00
db: DatabaseGuard,
2020-09-08 15:32:03 +00:00
body: Ruma<create_typing_event::Request<'_>>,
2020-07-30 16:14:47 +00:00
) -> ConduitResult<create_typing_event::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
2020-07-30 16:14:47 +00:00
2020-09-08 15:32:03 +00:00
if let Typing::Yes(duration) = body.state {
db.rooms.edus.typing_add(
&sender_user,
2020-07-30 16:14:47 +00:00
&body.room_id,
2020-09-08 15:32:03 +00:00
duration.as_millis() as u64 + utils::millis_since_unix_epoch(),
2020-07-30 16:14:47 +00:00
&db.globals,
)?;
} else {
db.rooms
.edus
.typing_remove(&sender_user, &body.room_id, &db.globals)?;
2020-07-30 16:14:47 +00:00
}
Ok(create_typing_event::Response.into())
}