2025-04-27 00:58:56 +00:00
|
|
|
use axum::extract::State;
|
2026-04-10 11:47:01 -04:00
|
|
|
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
2026-04-22 10:11:55 -04:00
|
|
|
use ruma::{
|
|
|
|
|
api::client::membership::kick_user,
|
|
|
|
|
assign,
|
|
|
|
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
|
|
|
|
};
|
2025-04-27 00:58:56 +00:00
|
|
|
|
|
|
|
|
use crate::Ruma;
|
|
|
|
|
|
|
|
|
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/kick`
|
|
|
|
|
///
|
|
|
|
|
/// Tries to send a kick event into the room.
|
|
|
|
|
pub(crate) async fn kick_user_route(
|
|
|
|
|
State(services): State<crate::State>,
|
|
|
|
|
body: Ruma<kick_user::v3::Request>,
|
|
|
|
|
) -> Result<kick_user::v3::Response> {
|
|
|
|
|
let sender_user = body.sender_user();
|
|
|
|
|
if services.users.is_suspended(sender_user).await? {
|
|
|
|
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
|
|
|
|
}
|
2026-03-29 12:25:42 -04:00
|
|
|
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
2025-04-27 00:58:56 +00:00
|
|
|
|
2026-04-22 10:11:55 -04:00
|
|
|
if !services
|
2025-04-27 00:58:56 +00:00
|
|
|
.rooms
|
2026-04-22 10:11:55 -04:00
|
|
|
.state_cache
|
|
|
|
|
.is_joined(&body.user_id, &body.room_id)
|
2025-04-27 00:58:56 +00:00
|
|
|
.await
|
2026-04-22 10:11:55 -04:00
|
|
|
{
|
|
|
|
|
return Err!(Request(Forbidden("You cannot kick users who are not in the room.")));
|
2025-04-27 00:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
services
|
|
|
|
|
.rooms
|
|
|
|
|
.timeline
|
|
|
|
|
.build_and_append_pdu(
|
2026-04-22 10:11:55 -04:00
|
|
|
PartialPdu::state(
|
|
|
|
|
body.user_id.to_string(),
|
|
|
|
|
&assign!(RoomMemberEventContent::new(MembershipState::Leave), {
|
|
|
|
|
reason: body.reason.clone(),
|
2026-04-25 10:59:54 -04:00
|
|
|
redact_events: body.redact_events,
|
2026-04-22 10:11:55 -04:00
|
|
|
}),
|
|
|
|
|
),
|
2025-04-27 00:58:56 +00:00
|
|
|
sender_user,
|
2025-09-17 20:46:03 +00:00
|
|
|
Some(&body.room_id),
|
2025-04-27 00:58:56 +00:00
|
|
|
&state_lock,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
drop(state_lock);
|
|
|
|
|
|
|
|
|
|
Ok(kick_user::v3::Response::new())
|
|
|
|
|
}
|