conduit/src/client_server/typing.rs

34 lines
989 B
Rust
Raw Normal View History

2020-07-30 16:14:47 +00:00
use super::State;
use crate::{utils, ConduitResult, Database, 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>")
)]
pub fn create_typing_event_route(
db: State<'_, Database>,
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())
}