module Decidim::Comments::Commentable
Shared behaviour for commentable models.
Public Instance Methods
Public: Whether the object can have new comments or not.
# File lib/decidim/comments/commentable.rb, line 21 def accepts_new_comments? true end
Public: Whether the object's comments are visible or not.
# File lib/decidim/comments/commentable.rb, line 16 def commentable? true end
Public: Identifies the commentable type in the API.
# File lib/decidim/comments/commentable.rb, line 38 def commentable_type self.class.name end
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
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
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
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
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