Sha256: 3400d81293ee865cad7551281237f3b53b77e3c2e1018bca240be3a321f9ca07

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 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

  def content_fields
    [:body]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
publify_core-9.2.1 app/models/comment.rb
publify_core-9.2.0 app/models/comment.rb