module Decidim::Comments::Commentable

Shared behaviour for commentable models.

Public Instance Methods

accepts_new_comments?() click to toggle source

Public: Whether the object can have new comments or not.

# File lib/decidim/comments/commentable.rb, line 21
def accepts_new_comments?
  true
end
commentable?() click to toggle source

Public: Whether the object's comments are visible or not.

# File lib/decidim/comments/commentable.rb, line 16
def commentable?
  true
end
commentable_type() click to toggle source

Public: Identifies the commentable type in the API.

# File lib/decidim/comments/commentable.rb, line 38
def commentable_type
  self.class.name
end
comments_have_alignment?() click to toggle source

Public: Whether the object's comments can have alignment or not. It enables the alignment selector in the add new comment form.

# File lib/decidim/comments/commentable.rb, line 27
def comments_have_alignment?
  false
end
comments_have_votes?() click to toggle source

Public: Whether the object's comments can have have votes or not. It enables the upvote and downvote buttons for comments.

# File lib/decidim/comments/commentable.rb, line 33
def comments_have_votes?
  false
end
update_comments_count() click to toggle source

Public: Updates the comments counter cache. We have to do it these way in order to properly calculate the coutner with hidden comments.

rubocop:disable Rails/SkipsModelValidations

# File lib/decidim/comments/commentable.rb, line 60
def update_comments_count
  comments_count = comments.not_hidden.count
  update_columns(comments_count: comments_count, updated_at: Time.current)
end
user_allowed_to_comment?(_user) click to toggle source

Public: Whether the object can have new comments or not.

# File lib/decidim/comments/commentable.rb, line 51
def user_allowed_to_comment?(_user)
  true
end
users_to_notify_on_comment_created() click to toggle source

Public: Defines which users will receive a notification when a comment is created. This method can be overridden at each resource model to include or exclude other users, eg. admins. Returns: a relation of Decidim::User objects.

# File lib/decidim/comments/commentable.rb, line 46
def users_to_notify_on_comment_created
  Decidim::User.none
end