Module: NotifyOn::PusherSupport
- Extended by:
- ActiveSupport::Concern
- Included in:
- Notification
- Defined in:
- app/models/concerns/notify_on/pusher_support.rb
Instance Method Summary collapse
- #push! ⇒ Object
- #pusher_attrs ⇒ Object
- #pusher_channel_name ⇒ Object
- #pusher_event_name ⇒ Object
- #pusher_recipient_active? ⇒ Boolean
- #pusher_sender_active? ⇒ Boolean
Instance Method Details
#push! ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/concerns/notify_on/pusher_support.rb', line 5 def push! return false unless can_push? pusher_config msg = "Pusher Event: #{pusher_event_name} | " msg += "To Channel: #{pusher_channel_name}\n#{pusher_attrs}" Rails.logger.debug(msg) Pusher.trigger_async(pusher_channel_name, pusher_event_name, pusher_attrs) end |
#pusher_attrs ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'app/models/concerns/notify_on/pusher_support.rb', line 43 def pusher_attrs return nil unless can_push? { :notification => self.to_json, :trigger => trigger.to_json, :data => ([:pusher][:data] if [:pusher].respond_to?(:[])) } end |
#pusher_channel_name ⇒ Object
29 30 31 32 33 34 |
# File 'app/models/concerns/notify_on/pusher_support.rb', line 29 def pusher_channel_name return nil unless can_push? channel = [:pusher][:channel] if [:pusher].respond_to?(:[]) channel = NotifyOn.configuration.default_pusher_channel if channel.blank? @pusher_channel_name ||= convert_string(channel) end |
#pusher_event_name ⇒ Object
36 37 38 39 40 41 |
# File 'app/models/concerns/notify_on/pusher_support.rb', line 36 def pusher_event_name return nil unless can_push? event = [:pusher][:event] if [:pusher].respond_to?(:[]) event = NotifyOn.configuration.default_pusher_event if event.blank? @pusher_event_name ||= convert_string(event) end |
#pusher_recipient_active? ⇒ Boolean
23 24 25 26 27 |
# File 'app/models/concerns/notify_on/pusher_support.rb', line 23 def pusher_recipient_active? ids = Pusher.channel_users(pusher_channel_name)[:users] .collect { |u| u["id"].to_i } ids.include?(recipient_id) end |
#pusher_sender_active? ⇒ Boolean
17 18 19 20 21 |
# File 'app/models/concerns/notify_on/pusher_support.rb', line 17 def pusher_sender_active? ids = Pusher.channel_users(pusher_channel_name)[:users] .collect { |u| u["id"].to_i } ids.include?(sender_id) end |