Sha256: 960c636fb1405e1fac380c4a2a15ec4ff7cdc4b963c0134316cd36101f8f6c13

Contents?: true

Size: 1.47 KB

Versions: 20

Compression:

Stored size: 1.47 KB

Contents

module Loco
  class NotificationCenterChannel < ApplicationCable::Channel
    def subscribed
      return if not loco_permissions.is_a?(Array)
      loco_permissions.compact.each do |resource|
        if resource.is_a? String
          @uuid = resource
          stream_for_resource resource
          SenderJob.perform_later @uuid, loco: {uuid: @uuid}
        else
          UuidJob.perform_later resource, @uuid, 'add'
          stream_for_resource resource
        end
      end
      return if loco_permissions.compact.size > 1
      SenderJob.perform_later @uuid, loco: {start_ajax_polling: true}
    end

    def unsubscribed
      loco_permissions.each do |resource|
        next if resource.nil? || resource.is_a?(String)
        UuidJob.perform_later resource, @uuid, 'del'
      end
    end

    def receive data
      if data['loco']
        if data['loco']['connection_check']
          update_connections
        end
      end
      NotificationCenter.new.received_signal permissions, data
    end

    protected

      def stream_for_resource resource
        identifier = WsConnectionManager.new(resource).identifier
        stream_from "loco:notification_center:#{identifier}"
      end

      def permissions
        loco_permissions.compact.map{ |o| [o.class.name.downcase.to_sym, o] }.to_h
      end

      def update_connections
        permissions.each do |key, val|
          next if key == :string
          UuidJob.perform_later val, @uuid, 'update'
        end
      end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
loco-rails-2.5.3 app/channels/loco/notification_center_channel.rb
loco-rails-2.5.2 app/channels/loco/notification_center_channel.rb
loco-rails-2.5.1 app/channels/loco/notification_center_channel.rb
loco-rails-2.5.0 app/channels/loco/notification_center_channel.rb
loco-rails-2.4.0 app/channels/loco/notification_center_channel.rb
loco-rails-2.3.0 app/channels/loco/notification_center_channel.rb
loco-rails-3.0.0 app/channels/loco/notification_center_channel.rb
loco-rails-2.2.2 app/channels/loco/notification_center_channel.rb
loco-rails-2.2.1 app/channels/loco/notification_center_channel.rb
loco-rails-2.2.0 app/channels/loco/notification_center_channel.rb
loco-rails-2.1.0 app/channels/loco/notification_center_channel.rb
loco-rails-2.0.0 app/channels/loco/notification_center_channel.rb
loco-rails-1.5.2 app/channels/loco/notification_center_channel.rb
loco-rails-1.5.1 app/channels/loco/notification_center_channel.rb
loco-rails-1.5.0 app/channels/loco/notification_center_channel.rb
loco-rails-1.4.0 app/channels/loco/notification_center_channel.rb
loco-rails-1.3.3 app/channels/loco/notification_center_channel.rb
loco-rails-1.3.2 app/channels/loco/notification_center_channel.rb
loco-rails-1.3.1 app/channels/loco/notification_center_channel.rb
loco-rails-1.3.0 app/channels/loco/notification_center_channel.rb