mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-28 04:54:22 +01:00
fix: don't allow unjoined users to send typing notifications
This commit is contained in:
parent
3573d40027
commit
b6b27b66c8
2 changed files with 24 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::{database::DatabaseGuard, utils, Result, Ruma};
|
||||
use ruma::api::client::typing::create_typing_event;
|
||||
use crate::{database::DatabaseGuard, Error, utils, Result, Ruma};
|
||||
use ruma::api::client::{typing::create_typing_event, error::ErrorKind};
|
||||
|
||||
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`
|
||||
///
|
||||
|
@ -12,6 +12,13 @@ pub async fn create_typing_event_route(
|
|||
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::Forbidden,
|
||||
"You are not in this room.",
|
||||
));
|
||||
}
|
||||
|
||||
if let Typing::Yes(duration) = body.state {
|
||||
db.rooms.edus.typing_add(
|
||||
sender_user,
|
||||
|
|
|
@ -770,17 +770,21 @@ pub async fn send_transaction_message_route(
|
|||
}
|
||||
}
|
||||
Edu::Typing(typing) => {
|
||||
if typing.typing {
|
||||
db.rooms.edus.typing_add(
|
||||
&typing.user_id,
|
||||
&typing.room_id,
|
||||
3000 + utils::millis_since_unix_epoch(),
|
||||
&db.globals,
|
||||
)?;
|
||||
} else {
|
||||
db.rooms
|
||||
.edus
|
||||
.typing_remove(&typing.user_id, &typing.room_id, &db.globals)?;
|
||||
if db.rooms.is_joined(&typing.user_id, &typing.room_id)? {
|
||||
if typing.typing {
|
||||
db.rooms.edus.typing_add(
|
||||
&typing.user_id,
|
||||
&typing.room_id,
|
||||
3000 + utils::millis_since_unix_epoch(),
|
||||
&db.globals,
|
||||
)?;
|
||||
} else {
|
||||
db.rooms.edus.typing_remove(
|
||||
&typing.user_id,
|
||||
&typing.room_id,
|
||||
&db.globals,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Edu::DeviceListUpdate(DeviceListUpdateContent { user_id, .. }) => {
|
||||
|
|
Loading…
Reference in a new issue