Files
danbooru/app/controllers/comment_votes_controller.rb
evazion f1b5c34b4d posts: show length of videos and animations in thumbnails.
Show the length of videos and animated posts in the thumbnail. The
length is shown the top left corner in MM:SS format. This replaces the
play button icon.

Show a speaker icon instead of a music note icon for posts with sound.

Doing this requires doing `.includes(:media_asset)` in a bunch of
places to avoid N+1 queries when we access the post's duration.
2021-10-25 02:56:55 -05:00

35 lines
1.1 KiB
Ruby

class CommentVotesController < ApplicationController
respond_to :js, :json, :xml, :html
def index
@comment_votes = authorize CommentVote.visible(CurrentUser.user).paginated_search(params, count_pages: true)
@comment_votes = @comment_votes.includes(:user, comment: [:creator, { post: [:uploader, :media_asset] }]) if request.format.html?
respond_with(@comment_votes)
end
def create
@comment = Comment.find(params[:comment_id])
@comment.with_lock do
@comment_vote = authorize CommentVote.new(comment: @comment, score: params[:score], user: CurrentUser.user)
CommentVote.active.where(comment: @comment, user: CurrentUser.user).each do |vote|
vote.soft_delete!(updater: CurrentUser.user)
end
@comment_vote.save
end
flash.now[:notice] = @comment_vote.errors.full_messages.join("; ") if @comment_vote.errors.present?
respond_with(@comment_vote)
end
def destroy
@comment_vote = authorize CommentVote.find(params[:id])
@comment_vote.soft_delete(updater: CurrentUser.user)
respond_with(@comment_vote)
end
end