lib/features/auto-subscribe.js
function autoSubscribe(args) {
  var rtm = args.rtm;
  var listSubscriptions = args.listSubscriptions;
  var filterFn = args.filterFn || _autoSubscribeDefaultFilterFn;
  var subscriptionLoadLimit = 50;

  _observeSubscriptionSyncEvents({
    rtm: rtm,
    filterFn: filterFn
  });

  return listSubscriptions({limit: subscriptionLoadLimit}).then(function(list) {
    return _fetchAllReadSubscriptions({
      list: list,
      loadMore: listSubscriptions,
      batchSize: subscriptionLoadLimit
    }).then(function(fetchedSubscriptions) {
      var subscriptions = Array.prototype.concat.apply(
        [],
        fetchedSubscriptions
      );
      return Promise.all(subscriptions.map(filterFn)).then(function(
        filterResults
      ) {
        var promisedSubscriptions = [];
        filterResults.forEach(function(canSubscribe, subscriptionIndex) {
          if (canSubscribe) {
            promisedSubscriptions.push(
              rtm.subscribe({
                channel: subscriptions[subscriptionIndex].channelId
              })
            );
          }
        });

        return Promise.all(promisedSubscriptions);
      });
    });
  });
}
function autoSubscribe(args) {
  var rtm = args.rtm;
  var listSubscriptions = args.listSubscriptions;
  var filterFn = args.filterFn || _autoSubscribeDefaultFilterFn;
  var subscriptionLoadLimit = 50;

  _observeSubscriptionSyncEvents({
    rtm: rtm,
    filterFn: filterFn
  });

  return listSubscriptions({limit: subscriptionLoadLimit}).then(function(list) {
    return _fetchAllReadSubscriptions({
      list: list,
      loadMore: listSubscriptions,
      batchSize: subscriptionLoadLimit
    }).then(function(fetchedSubscriptions) {
      var subscriptions = Array.prototype.concat.apply(
        [],
        fetchedSubscriptions
      );
      return Promise.all(subscriptions.map(filterFn)).then(function(
        filterResults
      ) {
        var promisedSubscriptions = [];
        filterResults.forEach(function(canSubscribe, subscriptionIndex) {
          if (canSubscribe) {
            promisedSubscriptions.push(
              rtm.subscribe({
                channel: subscriptions[subscriptionIndex].channelId
              })
            );
          }
        });

        return Promise.all(promisedSubscriptions);
      });
    });
  });
}
function autoSubscribe ( args ) { var rtm = args . rtm ; var listSubscriptions = args . listSubscriptions ; var filterFn = args . filterFn || _autoSubscribeDefaultFilterFn ; var subscriptionLoadLimit = 50 ; _observeSubscriptionSyncEvents ( { rtm : rtm , filterFn : filterFn } ) ; return listSubscriptions ( { limit : subscriptionLoadLimit } ) . then ( function ( list ) { return _fetchAllReadSubscriptions ( { list : list , loadMore : listSubscriptions , batchSize : subscriptionLoadLimit } ) . then ( function ( fetchedSubscriptions ) { var subscriptions = Array . prototype . concat . apply ( [ ] , fetchedSubscriptions ) ; return Promise . all ( subscriptions . map ( filterFn ) ) . then ( function ( filterResults ) { var promisedSubscriptions = [ ] ; filterResults . forEach ( function ( canSubscribe , subscriptionIndex ) { if ( canSubscribe ) { promisedSubscriptions . push ( rtm . subscribe ( { channel : subscriptions [ subscriptionIndex ] . channelId } ) ) ; } } ) ; return Promise . all ( promisedSubscriptions ) ; } ) ; } ) ; } ) ; }
Subscribe to all read allowed subscriptions.

@param {Object} args
@param {RtmClient} args.rtm
@param {Function} args.listSubscriptions
@param {Function} [args.filterFn]
@return {Promise}
Subscribe to all read allowed subscriptions .