Class: Decidim::Comments::Comment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Comments::Comment
- Includes:
- Authorable, Commentable, 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.
-
#notifiable?(context) ⇒ Boolean
Public: Overrides the ‘notifiable?` Notifiable concern method.
-
#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.
-
#users_to_notify ⇒ Object
Public: Overrides the ‘users_to_notify` Notifiable concern method.
Instance Method Details
#accepts_new_comments? ⇒ Boolean
Public: Override Commentable concern method ‘accepts_new_comments?`
39 40 41 |
# File 'app/models/decidim/comments/comment.rb', line 39 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
53 54 55 |
# File 'app/models/decidim/comments/comment.rb', line 53 def down_voted_by?(user) down_votes.any? { |vote| vote. == user } end |
#notifiable?(context) ⇒ Boolean
Public: Overrides the ‘notifiable?` Notifiable concern method. When a comment is commented the comment’s author is notified if it is not the same who has replied the comment and if the comment’s author has replied notifiations enabled.
65 66 67 |
# File 'app/models/decidim/comments/comment.rb', line 65 def notifiable?(context) context[:author] != && .replies_notifications? end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
58 59 60 |
# File 'app/models/decidim/comments/comment.rb', line 58 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
46 47 48 |
# File 'app/models/decidim/comments/comment.rb', line 46 def up_voted_by?(user) up_votes.any? { |vote| vote. == user } end |
#users_to_notify ⇒ Object
Public: Overrides the ‘users_to_notify` Notifiable concern method.
70 71 72 |
# File 'app/models/decidim/comments/comment.rb', line 70 def users_to_notify [] end |