Class: Loco::NotificationCenterChannel

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

Instance Method Summary collapse

Instance Method Details

#receive(payload) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'app/channels/loco/notification_center_channel.rb', line 22

def receive(payload)
  if payload.dig('loco', 'pong')
    update_connections
    broadcast_to(@uuid, loco: { ping: true })
  end
  return if payload.keys == ['loco']

  indexed_permissions = PermissionsPresenter.indexed(loco_permissions)
  NotificationCenter.new.received_message(indexed_permissions, payload)
end

#subscribedObject



5
6
7
8
9
10
11
12
13
14
# File 'app/channels/loco/notification_center_channel.rb', line 5

def subscribed
  return unless loco_permissions.is_a?(Array)

  @uuid, *signed_in_resources = PermissionsPresenter.signed_in(loco_permissions)
  return unless @uuid.is_a?(String)

  stream_from("loco:notification_center:#{@uuid}")
  broadcast_to(@uuid, loco: { uuid: @uuid })
  signed_in_resources.each { |resource| WsConnectionManager.new(resource).add(@uuid) }
end

#unsubscribedObject



16
17
18
19
20
# File 'app/channels/loco/notification_center_channel.rb', line 16

def unsubscribed
  PermissionsPresenter.signed_in(loco_permissions, except: :uuid).each do |resource|
    WsConnectionManager.new(resource).del(@uuid)
  end
end