Files
danbooru/app/components/comment_section_component.rb
evazion c8d27c2719 Fix #4669: Track moderation report status.
* Add ability to mark moderation reports as 'handled' or 'rejected'.
* Automatically mark reports as handled when the comment or forum post
  is deleted.
* Send a dmail to the reporter when their report is handled.
* Don't show the report notice on comments or forum posts when all
  reports against it have been handled or rejected.
* Add a fix script to mark all existing reports for deleted comments,
  forum posts, or dmails as handled.
2022-01-20 20:50:23 -06:00

30 lines
864 B
Ruby

# frozen_string_literal: true
class CommentSectionComponent < ApplicationComponent
attr_reader :post, :comments, :current_user, :limit, :dtext_data
def initialize(post:, current_user:, limit: nil)
super
@post = post
@current_user = current_user
@limit = limit
@comments = @post.comments.order(id: :asc)
@comments = @comments.includes(:creator)
@comments = @comments.includes(:votes) if !current_user.is_anonymous?
@comments = @comments.includes(:pending_moderation_reports) if policy(ModerationReport).can_see_moderation_reports?
@comments = @comments.last(limit) if limit.present?
@dtext_data = DText.preprocess(@comments.map(&:body))
end
def has_unloaded_comments?
unloaded_comment_count > 0
end
def unloaded_comment_count
return 0 if limit.nil?
[post.comments.size - limit, 0].max
end
end