Module: MongoidForums::Concerns::Subscribable

Extended by:
ActiveSupport::Concern
Included in:
Topic
Defined in:
app/models/mongoid_forums/concerns/subscribable.rb

Instance Method Summary collapse

Instance Method Details

#alert_subscribers(*args) ⇒ Object



69
70
71
72
73
# File 'app/models/mongoid_forums/concerns/subscribable.rb', line 69

def alert_subscribers(*args)
    subscriptions.where(:unsubscribed => false).each do |sub|
        sub.alert_subscriber(args)
    end
end

#subscribe_creatorObject



40
41
42
# File 'app/models/mongoid_forums/concerns/subscribable.rb', line 40

def subscribe_creator
    subscribe_user(self.user_id)
end

#subscribe_user(user_id) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'app/models/mongoid_forums/concerns/subscribable.rb', line 44

def subscribe_user(user_id)
    if user_id && !subscriber?(user_id)
        if sub = subscriptions.where(:subscriber_id => user_id, :unsubscribed => true).first
            sub.unsubscribed = false
            sub.save
        else
            subscriptions.create(:subscriber_id => user_id)
        end
    end
end

#subscriber?(user_id) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/mongoid_forums/concerns/subscribable.rb', line 61

def subscriber?(user_id)
    subscriptions.where(:subscriber_id => user_id, :unsubscribed => false).count > 0
end

#subscription_for(user_id) ⇒ Object



65
66
67
# File 'app/models/mongoid_forums/concerns/subscribable.rb', line 65

def subscription_for user_id
    subscriptions.first(:conditions => { :subscriber_id=>user_id })
end

#unsubscribe_user(user_id) ⇒ Object



55
56
57
58
59
# File 'app/models/mongoid_forums/concerns/subscribable.rb', line 55

def unsubscribe_user(user_id)
    sub = subscriptions.where(:subscriber_id => user_id).first
    sub.unsubscribed = true
    sub.save
end