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-3.0.5 test/dummy/app/services/loco/notification_center.rb
loco-rails-3.0.4 test/dummy/app/services/loco/notification_center.rb
loco-rails-3.0.3 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.5.3 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.5.2 test/dummy/app/services/loco/notification_center.rb
loco-rails-3.0.2 test/dummy/app/services/loco/notification_center.rb
loco-rails-3.0.1 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.5.1 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.5.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.4.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.3.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-3.0.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.2.2 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.2.1 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.2.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.1.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-2.0.0 test/dummy/app/services/loco/notification_center.rb
loco-rails-1.5.2 test/dummy/app/services/loco/notification_center.rb
loco-rails-1.5.1 test/dummy/app/services/loco/notification_center.rb
loco-rails-1.5.0 test/dummy/app/services/loco/notification_center.rb