Sha256: 4484045e77882e612c796e30a29e49fbf43821f1808aba58d8ec271fb6f42b69

Contents?: true

Size: 1.52 KB

Versions: 107

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8
require 'singleton'

class NotificationSender
  include Singleton

  def send_to(user,creator,title,message,label,link=nil)
    notification = Notification.find_or_create(:user_id => user.id,
                                :creator_id => creator.id,
                                :title => title,
                                :message => message,
                                :label => label,
                                :link => link,
                                :creation_date => Date.today)
    if link.nil?
      notification.link = "/notifications/#{notification.id}"
      notification.save
    end
    notification
  end

  def send_to_subscriptors(creator,title,message,label,link=nil)
    Subscription.where(:label => label).all.each do |subscription|
      notification = send_to(subscription.user,creator,title,message,label,link)
    end
  end

  def send_error(creator,title,message)
    Subscription.where(:label => 'error').all.each do |subscription|
      creator = subscription.user if creator.nil?
      notification = Notification.find(:user_id => subscription.user_id,
                                       :creator_id => creator.id,
                                       :title => title,
                                       :message => message,
                                       :label => 'error',
                                       :read_date => nil)
      if notification.nil?
        notification = send_to(subscription.user,creator,title,message,'error')
      end
    end

  end

end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
sinatra-hexacta-1.7.20 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.19 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.18 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.17 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.16 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.15 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.14 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.13 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.12 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.11 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.10 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.9 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.8 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.7 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.6 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.5 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.4 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.3 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.2 lib/sinatra/extensions/notification.rb
sinatra-hexacta-1.7.0 lib/sinatra/extensions/notification.rb