<commit_before>class ImageController < ApplicationController
  include UserHelper
  include ImageHelper

  before_action :require_login

  def item
    @image = Image.find(params[:id])
    @likes = @image.likes
    @comments = @image.comments

    @image.liked = false
    if logged_in?
      @likes.each do |like|
        @image.liked = true if like.user_id == current_user.id
      end
    end
  end

  def explore
    @explore = {}
    @explore[:weekly_top] = weekly_top_list
    render "image/explore"
  end

  def digest
    digest = weekly_digest_photos
    unless params[:email].blank?
      if params[:email] == "all"
        @users = User.all
        @users.each do |u|
          I18n.with_locale(u.locale) do
            UserMailer.featured_photo(u, digest).deliver_now
          end
        end
      else
        @user = current_user
        @user.email = "<EMAIL>"
        UserMailer.featured_photo(@user, digest).deliver_now
      end

      render plain: "sent"
      return
    end
    render plain: "not mail address"
  end

  def upload
  end

  def create
    @image = Image.new(params.require(:image).permit(:title, :url, :img_file))
    @image.user = User.find(current_user.id)

    if @image.save
      flash[:info] = I18n.t(:upload_success)
    else
      flash[:warning] = @image.errors.messages
    end

    redirect_to root_url
  end

  def comment
    image_id = params[:id]
    user_id = current_user.id

    @comment = Comment.new
    params.require(:comment).permit(:content)
    @comment.content = params[:comment][:content]
    @comment.user_id = user_id
    @comment.image_id = image_id
    @comment.status = Comment::STATUS_OK
    @comment.save

    # render
    redirect_to "/image/#{image_id}"
  end

  def like
    image_id = params[:id]
    user_id = current_user.id
<commit_msg>Notify from comment<commit_after>class ImageController < ApplicationController
  include UserHelper
  include ImageHelper

  before_action :require_login

  def item
    @image = Image.find(params[:id])
    @likes = @image.likes
    @comments = @image.comments

    @image.liked = false
    if logged_in?
      @likes.each do |like|
        @image.liked = true if like.user_id == current_user.id
      end
    end
  end

  def explore
    @explore = {}
    @explore[:weekly_top] = weekly_top_list
    render "image/explore"
  end

  def digest
    digest = weekly_digest_photos
    unless params[:email].blank?
      if params[:email] == "all"
        @users = User.all
        @users.each do |u|
          I18n.with_locale(u.locale) do
            UserMailer.featured_photo(u, digest).deliver_now
          end
        end
      else
        @user = current_user
        @user.email = "<EMAIL>"
        UserMailer.featured_photo(@user, digest).deliver_now
      end

      render plain: "sent"
      return
    end
    render plain: "not mail address"
  end

  def upload
  end

  def create
    @image = Image.new(params.require(:image).permit(:title, :url, :img_file))
    @image.user = User.find(current_user.id)

    if @image.save
      flash[:info] = I18n.t(:upload_success)
    else
      flash[:warning] = @image.errors.messages
    end

    redirect_to root_url
  end

  def comment
    image_id = params[:id]
    user_id = current_user.id

    @comment = Comment.new
    params.require(:comment).permit(:content)
    @comment.content = params[:comment][:content]
    @comment.user_id = user_id
    @comment.image_id = image_id
    @comment.status = Comment::STATUS_OK
    @comment.save

    # notify
    notif = Notification.new
    notif.user_id = @comment.user_id
    notif.event_type = Notification::NOTIFICATION_TYPES[:comment]
    notif.event_id = @comment.image_id
    notif.status = Notification::STATUS_OK
    notif.save

    # render
    redirect_to "/image/#{image_id}"
  end

  def like
    image_id = params[:id]
    user_id = current_user.id

{'fraction_non_alphanumeric': 0.1048158640226629, 'fraction_numerical': 0.0020602626834921455, 'mean_word_length': 2.5698529411764706, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '910909', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1253, 'n_words': 272}