Class: MongoidForums::Subscription

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/mongoid_forums/subscription.rb

Instance Method Summary collapse

Instance Method Details

#alert_subscriber(*args) ⇒ Object

attr_accessible :subscriber_id


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/mongoid_forums/subscription.rb', line 45

def alert_subscriber(*args)
  alert = MongoidForums::Alert.where(:subscription_id => self.id, :read => false).first
  puts "ALERTING SUBSCRIBERS WITH"
  puts alert
  case self.subscribable_type
  when "MongoidForums::Topic"
    if alert == nil
      last_post = self.subscribable.posts.last
      return if last_post.user.id == self.subscriber_id
      MongoidForums::Alert.create(:subscription_id => self.id, :user_id => self.subscriber_id, :mongoid_forums_topic_post => last_post, :mongoid_forums_topic_replier => last_post.user.forum_display_name)
    else
      alert.updated_at = Time.now
      alert.mongoid_forums_topic_count += 1
      alert.save
    end
  else
    raise TypeError, 'This object is not subscribable!'
  end
end