Sha256: 3a07bcdb20bf3cb797e7e305469db7db64a8dbe6ae68b3046b4e1d4c68bfad80

Contents?: true

Size: 737 Bytes

Versions: 12

Compression:

Stored size: 737 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(show_all)
    created_at = Commontator::Comment.arel_table[:created_at]
    thread.filtered_comments(show_all).where(created_at.gteq(updated_at))
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
commontator-7.0.1 app/models/commontator/subscription.rb
commontator-7.0.0 app/models/commontator/subscription.rb
commontator-6.3.2 app/models/commontator/subscription.rb
commontator-6.3.1 app/models/commontator/subscription.rb
commontator-6.3.0 app/models/commontator/subscription.rb
commontator-6.2.1 app/models/commontator/subscription.rb
commontator-6.2.0 app/models/commontator/subscription.rb
commontator-6.1.1 app/models/commontator/subscription.rb
commontator-6.1.0 app/models/commontator/subscription.rb
commontator-6.0.1 app/models/commontator/subscription.rb
commontator-6.0.0 app/models/commontator/subscription.rb
commontator-6.0.0.pre.2 app/models/commontator/subscription.rb