Sha256: 4e725dee9c3fea9f4292a8ebca4ffb0be140c5954502927c7a6ff5747e463932

Contents?: true

Size: 918 Bytes

Versions: 25

Compression:

Stored size: 918 Bytes

Contents

module Loco
  class NotificationCenter
    include Emitter

    def received_signal permissions, data
      return if not res = validate_signal(data['signal'], permissions, data)
      case data['signal']
      when 'ping'
        emit_to res[:user], signal: 'ping'
      when 'message'
        emit_to res[:hub], signal: 'message', message: data['txt'], author: permissions[:user].username
      end
    end

    protected

      def validate_signal name, permissions, data = {}
        case name
        when 'ping'
          return false if permissions[:admin].nil?
          user = User.new id: data['user_id']
          {user: user}
        when 'message'
          return false if permissions[:user].nil?
          return false if not hub = find_room(data['room_id'])
          {hub: hub}
        else
          false
        end
      end

      def find_room id
        Hub.get "room_#{id}"
      end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
loco-rails-1.4.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-1.3.3 test/dummy/app/services/loco/notification_center.rb
loco-rails-1.3.2 test/dummy/app/services/loco/notification_center.rb
loco-rails-1.3.1 test/dummy/app/services/loco/notification_center.rb
loco-rails-1.3.0 test/dummy/app/services/loco/notification_center.rb