Class: Decidim::Comments::Comment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Comments::Comment
- Includes:
- Authorable, Commentable, FriendlyDates, Reportable
- Defined in:
- app/models/decidim/comments/comment.rb
Overview
Some resources will be configured as commentable objects so users can comment on them. The will be able to create conversations between users to discuss or share their thoughts about the resource.
Constant Summary collapse
- MAX_DEPTH =
Limit the max depth of a comment tree. If C is a comment and R is a reply: C (depth 0) |–R (depth 1) |–R (depth 1)
|--R (depth 2) |--R (depth 3) 3
Instance Method Summary collapse
-
#accepts_new_comments? ⇒ Boolean
Public: Override Commentable concern method ‘accepts_new_comments?`.
-
#down_voted_by?(user) ⇒ Boolean
Public: Check if the user has downvoted the comment.
-
#formatted_body ⇒ Object
Public: Returns the comment message ready to display (it is expected to include HTML).
-
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
-
#up_voted_by?(user) ⇒ Boolean
Public: Check if the user has upvoted the comment.
Instance Method Details
#accepts_new_comments? ⇒ Boolean
Public: Override Commentable concern method ‘accepts_new_comments?`
40 41 42 |
# File 'app/models/decidim/comments/comment.rb', line 40 def accepts_new_comments? depth < MAX_DEPTH end |
#down_voted_by?(user) ⇒ Boolean
Public: Check if the user has downvoted the comment
Returns a bool value to indicate if the condition is truthy or not
57 58 59 |
# File 'app/models/decidim/comments/comment.rb', line 57 def down_voted_by?(user) down_votes.any? { |vote| vote. == user } end |
#formatted_body ⇒ Object
Public: Returns the comment message ready to display (it is expected to include HTML)
67 68 69 |
# File 'app/models/decidim/comments/comment.rb', line 67 def formatted_body @formatted_body ||= Decidim::ContentProcessor.render(sanitized_body) end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
62 63 64 |
# File 'app/models/decidim/comments/comment.rb', line 62 def reported_content_url ResourceLocatorPresenter.new(root_commentable).url(anchor: "comment_#{id}") end |
#up_voted_by?(user) ⇒ Boolean
Public: Check if the user has upvoted the comment
Returns a bool value to indicate if the condition is truthy or not
50 51 52 |
# File 'app/models/decidim/comments/comment.rb', line 50 def up_voted_by?(user) up_votes.any? { |vote| vote. == user } end |