diff --git a/src/api/client/state.rs b/src/api/client/state.rs index 323d07189..460521d2d 100644 --- a/src/api/client/state.rs +++ b/src/api/client/state.rs @@ -366,14 +366,23 @@ async fn allowed_to_send_state_event( } }, | StateEventType::RoomMember => match json.deserialize_as::() { - | Ok(membership_content) => { + | Ok(mut membership_content) => { let Ok(state_key) = UserId::parse(state_key) else { return Err!(Request(BadJson( "Membership event has invalid or non-existent state key" ))); }; - if let Some(authorising_user) = + // Moved the check for if user is already joined and then stripped the Option + // Unsure if this actually fixes it + if services + .rooms + .state_cache + .is_joined(state_key, room_id) + .await + { + membership_content.join_authorized_via_users_server.take(); + } else if let Some(authorising_user) = membership_content.join_authorized_via_users_server { if membership_content.membership != MembershipState::Join { @@ -382,17 +391,6 @@ async fn allowed_to_send_state_event( ))); } - if services - .rooms - .state_cache - .is_joined(state_key, room_id) - .await - { - return Err!(Request(InvalidParam( - "{state_key} is already joined, an authorising user is not required." - ))); - } - if !services.globals.user_is_local(&authorising_user) { return Err!(Request(InvalidParam( "Authorising user {authorising_user} does not belong to this \