mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-12-05 06:41:46 +00:00
chore: Address review comments for #2583
This commit is contained in:
4 files changed
+97
-20
No files matched your search
@@ -2,15 +2,21 @@ use axum::extract::State;
|
||||
use conduwuit::{Err, Result};
|
||||
use ruma::{
|
||||
api::client::delayed_events::{
|
||||
get_delayed_event, schedule_delayed_event, update_delayed_event,
|
||||
get_delayed_event, schedule_delayed_event,
|
||||
update_delayed_event::{self, UpdateAction},
|
||||
},
|
||||
events::TimelineEventType,
|
||||
signatures::MAX_PDU_BYTES,
|
||||
};
|
||||
use serde_json::{Map as JsonMap, Value as JsonValue};
|
||||
use service::rooms::delayed_events::NewDelayedEvent;
|
||||
|
||||
use crate::{Ruma, client_ip::ClientIp};
|
||||
|
||||
/// The largest content we accept for a delayed event, leaving 4 KiB of the PDU
|
||||
/// size limit for the rest of the event (IDs, hashes, signatures, etc).
|
||||
const MAX_CONTENT_BYTES: usize = MAX_PDU_BYTES - 4096;
|
||||
|
||||
/// # `PUT /_matrix/client/v3/rooms/{roomId}/delayed_event/{eventType}/{txnId}`
|
||||
///
|
||||
/// Schedules an event to be sent into a room after a delay.
|
||||
@@ -50,6 +56,13 @@ pub(crate) async fn schedule_delayed_event_route(
|
||||
return Err!(Request(BadJson("The event content must be a JSON object.")));
|
||||
}
|
||||
|
||||
// The full PDU is size checked again when it is sent.
|
||||
if body.content.json().get().len() > MAX_CONTENT_BYTES {
|
||||
return Err!(Request(TooLarge(
|
||||
"The event content exceeds the maximum of {MAX_CONTENT_BYTES} bytes."
|
||||
)));
|
||||
}
|
||||
|
||||
// Auth is checked again when the event is sent
|
||||
let is_own_membership = body.event_type == TimelineEventType::RoomMember
|
||||
&& body.state_key.as_deref() == Some(sender_user.as_str());
|
||||
@@ -98,6 +111,11 @@ pub(crate) async fn update_delayed_event_route(
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
let update_delayed_event::v1::Request { delay_id, action, .. } = body.body;
|
||||
|
||||
// Cancelling is still allowed, since it only stops activity.
|
||||
if action != UpdateAction::Cancel && services.users.is_suspended(sender_user).await? {
|
||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||
}
|
||||
|
||||
services
|
||||
.rooms
|
||||
.delayed_events
|
||||
|
||||
Reference in new issue
Block a user