<commit_before>class RoomsUsersController < ApplicationController

  def create
    if RoomsUser.where(:user_id => current_user.id).last
      @room = Room.find(params[:room_id])
      if RoomsUser.create(:room_id=>params[:room_id], :user_id => params[:user_id]).valid?
        joined_user = User.find(params[:user_id])
        room_user_ids = RoomsUser.where(:room_id => @room.id).pluck(:user_id)
        @room_users = User.where("id IN (?)", room_user_ids)
        Pusher["private-#{params[:room_id]}"].trigger('add_user_to_room', {:user_id=>joined_user.id,:user_login=>joined_user.login,:rooms_name=>@room.name, :room_id=>@room.id})
        Pusher["private-#{params[:user_id]}"].trigger('user_add_to_room', {:rooms_id=>@room.id,:rooms_name=>@room.name})
      else
        flash[:error] = "User already in room"
      end

      render json: {:joined_user => joined_user, :room_id => @room.id}
  end
  end

  def destroy
    room_user = RoomsUser.where("user_id = ? AND room_id = ?", params[:user_id], params[:room_id]).first
    room_users_count = RoomsUser.where("room_id = ?", params[:room_id]).count
    if(current_user.id == params[:user_id].to_i)
      room_user.destroy
      if (room_users_count -= 1).zero?
        room = Room.find(params[:room_id])
        room.destroy
      end
    end
    render json: {:drop_user_id => params[:user_id], :cur_user_id => current_user.id}
  end

end

<commit_msg>fix add to room<commit_after>class RoomsUsersController < ApplicationController

  def create
    if RoomsUser.where(:user_id => current_user.id, :room_id=>params[:room_id]).first
      @room = Room.find(params[:room_id])
      if RoomsUser.create(:room_id=>params[:room_id], :user_id => params[:user_id]).valid?
        joined_user = User.find(params[:user_id])
        room_user_ids = RoomsUser.where(:room_id => @room.id).pluck(:user_id)
        @room_users = User.where("id IN (?)", room_user_ids)
        Pusher["private-#{params[:room_id]}"].trigger('add_user_to_room', {:user_id=>joined_user.id,:user_login=>joined_user.login,:rooms_name=>@room.name, :room_id=>@room.id})
        Pusher["private-#{params[:user_id]}"].trigger('user_add_to_room', {:rooms_id=>@room.id,:rooms_name=>@room.name})
      else
        flash[:error] = "User already in room"
      end
      render json: {:joined_user => joined_user, :room_id => @room.id}
  end
  end

  def destroy
    room_user = RoomsUser.where("user_id = ? AND room_id = ?", params[:user_id], params[:room_id]).first
    room_users_count = RoomsUser.where("room_id = ?", params[:room_id]).count
    if(current_user.id == params[:user_id].to_i)
      room_user.destroy
      if (room_users_count -= 1).zero?
        room = Room.find(params[:room_id])
        room.destroy
      end
    end
    render json: {:drop_user_id => params[:user_id], :cur_user_id => current_user.id}
  end

end


{'fraction_non_alphanumeric': 0.16164095371669004, 'fraction_numerical': 0.0007012622720897616, 'mean_word_length': 4.005263157894737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5312559', 'n_tokens_mistral': 1018, 'n_tokens_neox': 1011, 'n_words': 150}