Make it so that when a user removes their own vote, the vote is soft deleted (the is_deleted flag is set) instead of hard deleted. Changes: * Add is_deleted flag to comment votes. * Relax uniqueness constraint so you can have multiple deleted votes on the same comment. You can still only have one active vote on the comment. * Add `soft_delete` method to Deletable concern.
43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class CommentComponent < ApplicationComponent
|
|
attr_reader :comment, :context, :dtext_data, :current_user
|
|
|
|
def initialize(comment:, current_user:, context: nil, dtext_data: nil)
|
|
@comment = comment
|
|
@context = context
|
|
@dtext_data = dtext_data
|
|
@current_user = current_user
|
|
end
|
|
|
|
def dimmed?
|
|
comment.is_deleted? || (!comment.is_sticky? && comment.score <= current_user.comment_threshold/2.0)
|
|
end
|
|
|
|
def thresholded?
|
|
!comment.is_deleted? && !comment.is_sticky? && comment.score <= current_user.comment_threshold
|
|
end
|
|
|
|
def redact_deleted?
|
|
comment.is_deleted? && !policy(comment).can_see_deleted?
|
|
end
|
|
|
|
def votable?
|
|
!comment.is_deleted? || current_user.is_moderator?
|
|
end
|
|
|
|
def upvoted?
|
|
return false if current_user.is_anonymous?
|
|
comment.votes.active.select(&:is_positive?).map(&:user_id).include?(current_user.id)
|
|
end
|
|
|
|
def downvoted?
|
|
return false if current_user.is_anonymous?
|
|
comment.votes.active.select(&:is_negative?).map(&:user_id).include?(current_user.id)
|
|
end
|
|
|
|
def reported?
|
|
policy(ModerationReport).can_see_moderation_reports? && comment.moderation_reports.present?
|
|
end
|
|
end
|