Sha256: e5c010f94f0c00bc461d579761a1e51519f9c2e5af60c8bd1704123d26245892

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

class Commontator::Subscription < ActiveRecord::Base
  belongs_to :subscriber, polymorphic: true
  belongs_to :thread, inverse_of: :subscriptions

  validates :thread, presence: true, uniqueness: { scope: [ :subscriber_type, :subscriber_id ] }

  def self.comment_created(comment)
    recipients = comment.thread.subscribers.reject { |sub| sub == comment.creator }
    return if recipients.empty?

    mail = Commontator::SubscriptionsMailer.comment_created(comment, recipients)
    mail.respond_to?(:deliver_later) ? mail.deliver_later : mail.deliver
  end

  def unread_comments
    created_at = Commontator::Comment.arel_table[:created_at]
    thread.filtered_comments.where(created_at.gteq(updated_at))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
commontator-6.0.0.pre.1 app/models/commontator/subscription.rb