Class: Decidim::Comments::Comment

Inherits:
ApplicationRecord show all
Includes:
Authorable, Commentable, Reportable
Defined in:
decidim-comments/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

Instance Method Details

#accepts_new_comments?Boolean

Public: Override Commentable concern method ‘accepts_new_comments?`

Returns:

  • (Boolean)


36
37
38
# File 'decidim-comments/app/models/decidim/comments/comment.rb', line 36

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

Returns:

  • (Boolean)


50
51
52
# File 'decidim-comments/app/models/decidim/comments/comment.rb', line 50

def down_voted_by?(user)
  down_votes.any? { |vote| vote.author == user }
end

#reported_contentObject

Public: Overrides the ‘reported_content` Reportable concern method.



55
56
57
# File 'decidim-comments/app/models/decidim/comments/comment.rb', line 55

def reported_content
  body
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

Returns:

  • (Boolean)


43
44
45
# File 'decidim-comments/app/models/decidim/comments/comment.rb', line 43

def up_voted_by?(user)
  up_votes.any? { |vote| vote.author == user }
end