Sha256: 53f2a83ba8340bd1e1e4429dcfdd7347c9d533c6316f5ef289c876cba5258e83

Contents?: true

Size: 656 Bytes

Versions: 5

Compression:

Stored size: 656 Bytes

Contents

module Commontator
  class Subscription < ActiveRecord::Base
    belongs_to :subscriber, :polymorphic => true
    belongs_to :thread

    validates_presence_of :subscriber, :thread
    validates_uniqueness_of :thread_id, :scope => [:subscriber_type, :subscriber_id]

    def self.comment_created(comment)
      recipients = comment.thread.subscribers.reject{|s| s == comment.creator}
      SubscriptionsMailer.comment_created(comment, recipients).deliver \
        unless recipients.empty?
    end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
commontator-4.10.3 app/models/commontator/subscription.rb
commontator-4.10.2 app/models/commontator/subscription.rb
commontator-4.10.1 app/models/commontator/subscription.rb
commontator-4.10.0 app/models/commontator/subscription.rb
commontator-4.9.0 app/models/commontator/subscription.rb