diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index a9a60d80..60e03e4e 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -187,6 +187,14 @@ pub async fn kick_user_route( ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if let Ok(true) = services() + .rooms + .state_cache + .is_left(sender_user, &body.room_id) + { + return Ok(kick_user::v3::Response {}); + } + let mut event: RoomMemberEventContent = serde_json::from_str( services() .rooms @@ -247,6 +255,16 @@ pub async fn kick_user_route( pub async fn ban_user_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if let Ok(Some(membership_event)) = services() + .rooms + .state_accessor + .get_member(&body.room_id, sender_user) + { + if membership_event.membership == MembershipState::Ban { + return Ok(ban_user::v3::Response {}); + } + } + let event = services() .rooms .state_accessor @@ -318,6 +336,16 @@ pub async fn unban_user_route( ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if let Ok(Some(membership_event)) = services() + .rooms + .state_accessor + .get_member(&body.room_id, sender_user) + { + if membership_event.membership != MembershipState::Ban { + return Ok(unban_user::v3::Response {}); + } + } + let mut event: RoomMemberEventContent = serde_json::from_str( services() .rooms @@ -498,6 +526,12 @@ async fn join_room_by_id_helper( ) -> Result { let sender_user = sender_user.expect("user is authenticated"); + if let Ok(true) = services().rooms.state_cache.is_joined(sender_user, room_id) { + return Ok(join_room_by_id::v3::Response { + room_id: room_id.into(), + }); + } + let mutex_state = Arc::clone( services() .globals