"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.receivedHeartbeats = receivedHeartbeats;

var _rxjs = require("rxjs");

var _operators = require("rxjs/operators");

var _drr = require("../util/drr");

// Copyright 2017-2019 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

/**
 * @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session
 */
function receivedHeartbeats(api) {
  return addresses => {
    return api.query.imOnline && api.query.imOnline.receivedHeartbeats ? api.queryMulti([api.query.session.currentIndex, api.query.imOnline.keys]).pipe((0, _operators.switchMap)((_ref) => {
      let [currentIndex, keys] = _ref;
      return api.query.imOnline.receivedHeartbeats.multi(addresses.map(address => [currentIndex, keys.indexOf(address)]));
    }), (0, _operators.map)(heartbeats => heartbeats.map(heartbeat => !heartbeat.isEmpty)), (0, _drr.drr)()) : (0, _rxjs.of)([...new Array(addresses.length).keys()].map(() => false));
  };
}