2020-07-30 17:14:47 +01:00
|
|
|
use super::State;
|
|
|
|
use crate::{utils, ConduitResult, Database, Ruma};
|
2020-09-08 16:32:03 +01:00
|
|
|
use create_typing_event::Typing;
|
2020-07-30 17:14:47 +01: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>")
|
|
|
|
)]
|
|
|
|
pub fn create_typing_event_route(
|
|
|
|
db: State<'_, Database>,
|
2020-09-08 16:32:03 +01:00
|
|
|
body: Ruma<create_typing_event::Request<'_>>,
|
2020-07-30 17:14:47 +01:00
|
|
|
) -> ConduitResult<create_typing_event::Response> {
|
|
|
|
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
|
|
|
|
2020-09-08 16:32:03 +01:00
|
|
|
if let Typing::Yes(duration) = body.state {
|
2020-08-23 16:29:39 +01:00
|
|
|
db.rooms.edus.typing_add(
|
2020-07-30 17:14:47 +01:00
|
|
|
&sender_id,
|
|
|
|
&body.room_id,
|
2020-09-08 16:32:03 +01:00
|
|
|
duration.as_millis() as u64 + utils::millis_since_unix_epoch(),
|
2020-07-30 17:14:47 +01:00
|
|
|
&db.globals,
|
|
|
|
)?;
|
|
|
|
} else {
|
|
|
|
db.rooms
|
|
|
|
.edus
|
2020-08-23 16:29:39 +01:00
|
|
|
.typing_remove(&sender_id, &body.room_id, &db.globals)?;
|
2020-07-30 17:14:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(create_typing_event::Response.into())
|
|
|
|
}
|