Module: NotifyOn::PusherSupport

Extended by:
ActiveSupport::Concern
Included in:
Notification
Defined in:
app/models/concerns/notify_on/pusher_support.rb

Instance Method Summary collapse

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_attrsObject



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 => (options[:pusher][:data] if options[:pusher].respond_to?(:[]))
  }
end

#pusher_channel_nameObject



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 = options[:pusher][:channel] if options[:pusher].respond_to?(:[])
  channel = NotifyOn.configuration.default_pusher_channel if channel.blank?
  @pusher_channel_name ||= convert_string(channel)
end

#pusher_event_nameObject



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 = options[:pusher][:event] if options[:pusher].respond_to?(:[])
  event = NotifyOn.configuration.default_pusher_event if event.blank?
  @pusher_event_name ||= convert_string(event)
end

#pusher_recipient_active?Boolean

Returns:

  • (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

Returns:

  • (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