Class: Decidim::Comments::Comment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Comments::Comment
- Includes:
- Authorable, Commentable
- 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.
-
#root_commentable ⇒ Object
Public: Returns the commentable object of the parent comment.
-
#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?`
34 35 36 |
# File 'app/models/decidim/comments/comment.rb', line 34 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
48 49 50 |
# File 'app/models/decidim/comments/comment.rb', line 48 def down_voted_by?(user) down_votes.any? { |vote| vote. == user } end |
#root_commentable ⇒ Object
Public: Returns the commentable object of the parent comment
53 54 55 56 |
# File 'app/models/decidim/comments/comment.rb', line 53 def root_commentable return commentable if depth == 0 commentable.root_commentable 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
41 42 43 |
# File 'app/models/decidim/comments/comment.rb', line 41 def up_voted_by?(user) up_votes.any? { |vote| vote. == user } end |