**Does not yet work!** Currently, state resolution does not correctly resolve conflicting states. Everything else appears to work as expected, so stateres will be fixed soon, then we should be clear for takeoff. Also: a lot of things currently accept a nullable room ID that really just don't need to. This will need tidying up before merge. Some authentication checks have also been disabled temporarily but nothing important. A lot of things are tagged with `TODO(hydra)`, those need resolving before merge. External contributors should PR to the `hydra/public` branch, *not* ` main`. --- This PR should be squash merged. Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/943 Co-authored-by: nexy7574 <git@nexy7574.co.uk> Co-committed-by: nexy7574 <git@nexy7574.co.uk>
65 lines
1.7 KiB
Rust
65 lines
1.7 KiB
Rust
use axum::extract::State;
|
|
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
|
use ruma::{
|
|
api::client::membership::kick_user,
|
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
|
};
|
|
|
|
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.")));
|
|
}
|
|
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
|
|
|
let Ok(event) = services
|
|
.rooms
|
|
.state_accessor
|
|
.get_member(&body.room_id, &body.user_id)
|
|
.await
|
|
else {
|
|
// copy synapse's behaviour of returning 200 without any change to the state
|
|
// instead of erroring on left users
|
|
return Ok(kick_user::v3::Response::new());
|
|
};
|
|
|
|
if !matches!(
|
|
event.membership,
|
|
MembershipState::Invite | MembershipState::Knock | MembershipState::Join,
|
|
) {
|
|
return Err!(Request(Forbidden(
|
|
"Cannot kick a user who is not apart of the room (current membership: {})",
|
|
event.membership
|
|
)));
|
|
}
|
|
|
|
services
|
|
.rooms
|
|
.timeline
|
|
.build_and_append_pdu(
|
|
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
|
|
membership: MembershipState::Leave,
|
|
reason: body.reason.clone(),
|
|
is_direct: None,
|
|
join_authorized_via_users_server: None,
|
|
third_party_invite: None,
|
|
..event
|
|
}),
|
|
sender_user,
|
|
Some(&body.room_id),
|
|
&state_lock,
|
|
)
|
|
.await?;
|
|
|
|
drop(state_lock);
|
|
|
|
Ok(kick_user::v3::Response::new())
|
|
}
|