You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: handle_user_removed_from_group.rb
    path of file: ./repos/discourse/plugins/chat/app/services/chat/auto_remove
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Chat
  module AutoRemove
    # Fired from [Jobs::AutoRemoveMembershipHandleUserRemovedFromGroup], which
    # in turn is enqueued whenever the [DiscourseEvent] for :user_removed_from_group
    # is triggered.
    #
    # Staff users will never be affected by this, they can alway
    
      def remove_if_outside_chat_allowed_groups(user:)
        if SiteSetting.chat_allowed_groups_map.empty? ||
             !GroupUser.exists?(group_id: SiteSetting.chat_allowed_groups_map, user: user)
          memberships_to_remove =
            Chat::UserChatChannelMembership
              .joins(:chat_channel)
              .where(user_id: user.id)
              .where.not(chat_channel: { type: "DirectMessageChannel" })

          return if memberships_to_remove.empty?

          context[:users_removed_map] = Chat::Action::RemoveMemberships.call(
            memberships: memberships_to_remove,
          )
        end