Class: PushNotificationChannel

Inherits:
ApplicationCable::Channel
  • Object
show all
Defined in:
app/channels/push_notification_channel.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.broadcast_to(subscriber, message) ⇒ Object



15
16
17
# File 'app/channels/push_notification_channel.rb', line 15

def self.broadcast_to(subscriber, message)
  ActionCable.server.broadcast("push_notifications_subscriber_#{subscriber.id}", message.as_json)
end

Instance Method Details

#subscribedObject



2
3
4
5
6
7
8
9
10
11
# File 'app/channels/push_notification_channel.rb', line 2

def subscribed
  if params[:subscriber_id].present?
    subscriber = PushSubscriber.active.find_by(id: params[:subscriber_id], user_id: current_user.id)
    stream_from "push_notifications_subscriber_#{subscriber.id}" if subscriber
  elsif params[:user_id].present? && params[:user_id].to_i == current_user.id
    PushSubscriber.active.where(user_id: current_user.id).each do |sub|
      stream_from "push_notifications_subscriber_#{sub.id}"
    end
  end
end

#unsubscribedObject



13
# File 'app/channels/push_notification_channel.rb', line 13

def unsubscribed; end