1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-06-27 16:35:59 +00:00
conduit/src/client_server/typing.rs

29 lines
916 B
Rust
Raw Normal View History

use crate::{database::DatabaseGuard, utils, Result, Ruma};
2020-09-08 17:32:03 +02:00
use create_typing_event::Typing;
2020-07-30 18:14:47 +02:00
use ruma::api::client::r0::typing::create_typing_event;
2021-08-31 19:14:37 +02:00
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`
///
/// Sets the typing state of the sender user.
2022-01-20 11:51:31 +01:00
pub async fn create_typing_event_route(
2021-07-14 07:07:08 +00:00
db: DatabaseGuard,
2020-09-08 17:32:03 +02:00
body: Ruma<create_typing_event::Request<'_>>,
) -> Result<create_typing_event::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
2020-07-30 18:14:47 +02:00
2020-09-08 17:32:03 +02:00
if let Typing::Yes(duration) = body.state {
db.rooms.edus.typing_add(
sender_user,
2020-07-30 18:14:47 +02:00
&body.room_id,
2020-09-08 17:32:03 +02:00
duration.as_millis() as u64 + utils::millis_since_unix_epoch(),
2020-07-30 18:14:47 +02:00
&db.globals,
)?;
} else {
db.rooms
.edus
.typing_remove(sender_user, &body.room_id, &db.globals)?;
2020-07-30 18:14:47 +02:00
}
Ok(create_typing_event::Response {})
2020-07-30 18:14:47 +02:00
}