Sha256: 21b6bfe4c31449cd4f4371a95c8d3c5670f1f9e0455c4ba6c8c48104a15b5b52

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "timeout"

class Comment < Feedback
  belongs_to :user, optional: true
  content_fields :body
  validates :author, :body, presence: true

  attr_accessor :referrer, :permalink

  scope :spam, -> { where(state: "spam") }
  scope :not_spam, -> { where("state != 'spam'") }
  scope :presumed_spam, -> { where(state: "presumed_spam") }
  scope :presumed_ham, -> { where(state: "presumed_ham") }
  scope :ham, -> { where(state: "ham") }
  scope :unconfirmed, -> { where(state: %w(presumed_spam presumed_ham)) }

  scope :last_published, -> { published.limit(5).order("created_at DESC") }

  def notify_user_via_email(user)
    EmailNotify.send_comment(self, user) if user.notify_via_email?
  end

  def interested_users
    User.where(notify_on_comments: true)
  end

  def default_text_filter
    TextFilter.find_or_default(blog.comment_text_filter)
  end

  def feed_title
    "Comment on #{article.title} by #{author}"
  end

  def send_notifications
    really_send_notifications
  end

  protected

  def article_allows_feedback?
    return true if article.allow_comments?

    errors.add(:article, "Article is not open to comments")
    false
  end

  def originator
    author
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
publify_core-9.2.7 app/models/comment.rb
publify_core-9.2.6 app/models/comment.rb
publify_core-9.2.5 app/models/comment.rb
publify_core-9.2.4 app/models/comment.rb
publify_core-9.2.3 app/models/comment.rb
publify_core-9.2.2 app/models/comment.rb