Files
danbooru/app/components/comment_component.rb
evazion bed5fdafb8 comments: add dtext shortlink option to comment menu.
Add a Shortlink menu option to the comment menu. Clicking this will copy
a DText comment shortlink (e.g. `comment #12345`) to the clipboard. You
can middle-click or right-click the menu option to get the full URL.

The menu option is called Shortlink instead of `comment #1234` because
show the full comment ID in the menu makes the menu look too unbalanced.

Note that the `navigator.clipboard` API can only be used in a https://
environment. It won't work in non-HTTPS development environments. ngrok
can help with this.
2021-01-22 03:55:48 -06:00

44 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class CommentComponent < ApplicationComponent
attr_reader :comment, :context, :dtext_data, :current_user
delegate :link_to_user, :time_ago_in_words_tagged, :format_text, :edit_icon, :delete_icon, :undelete_icon, :flag_icon, :upvote_icon, :downvote_icon, :link_icon, to: :helpers
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.select(&:is_positive?).map(&:user_id).include?(current_user.id)
end
def downvoted?
return false if current_user.is_anonymous?
comment.votes.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