<commit_before>/*
 * Copyright (C) 2015 SUSE Linux
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE.txt file for details.
 */

(function () {
  'use strict';

  angular.module('janusHangouts')
    .service('FeedsService', FeedsService);

  FeedsService.$inject = ['$q'];

  function FeedsService($q) {
    this.mainFeed = null;
    this.feeds = {};

    this.find = find;
    this.findMain = findMain;
    this.add = add;
    this.destroy = destroy;
    this.allFeeds = allFeeds;
    this.publisherFeeds = publisherFeeds;
    this.localScreenFeeds = localScreenFeeds;
    this.speakingFeed = speakingFeed;
    this.waitFor = waitFor;

    function find(id) {
      return (this.feeds[id] || null);
    }

    function findMain() {
      return this.mainFeed;
    }

    /**
     * Find a feed but, if not found, waits until it appears
     *
     * @param {string} id       Feed's id
     * @param {number} attempts Max number of attempts
     * @param {number} timeout  Time (in miliseconds) between attempts
     * @return {Object}         Promise to be resolved when the feed is found.
     */
    function waitFor(id, attempts, timeout) {
      var deferred = $q.defer();
      var feed = this.find(id);
      var that = this;
      attempts = attempts || 10;
      timeout = timeout || 1000;

      if (feed === null) { // If feed is not found, set an interval to check again.
        var interval = setInterval(function () {
          feed = that.find(id);
          if (feed === null) { // The feed was not found this time
            attempts -= 1;
          } else { // The feed was finally found
            clearInterval(interval);
            deferred.resolve(feed);
          }
          if (attempts === 0) { // No more attempts left and feed was not found
            clearInterval(interval);
            deferred.reject("feed with id " + id + " was not found");
          }
        }, timeout);
      } else {
        deferred.resolve(feed);
      }

      return deferred.promise;
    }

    function add(feed, options) {
      this.feeds[feed.id] = feed;
      if (options && options.main) {<commit_msg>Avoid warnings about usage of global timeout functions<commit_after>/*
 * Copyright (C) 2015 SUSE Linux
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE.txt file for details.
 */

(function () {
  'use strict';

  angular.module('janusHangouts')
    .service('FeedsService', FeedsService);

  FeedsService.$inject = ['$q', '$window'];

  function FeedsService($q, $window) {
    this.mainFeed = null;
    this.feeds = {};

    this.find = find;
    this.findMain = findMain;
    this.add = add;
    this.destroy = destroy;
    this.allFeeds = allFeeds;
    this.publisherFeeds = publisherFeeds;
    this.localScreenFeeds = localScreenFeeds;
    this.speakingFeed = speakingFeed;
    this.waitFor = waitFor;

    function find(id) {
      return (this.feeds[id] || null);
    }

    function findMain() {
      return this.mainFeed;
    }

    /**
     * Find a feed but, if not found, waits until it appears
     *
     * @param {string} id       Feed's id
     * @param {number} attempts Max number of attempts
     * @param {number} timeout  Time (in miliseconds) between attempts
     * @return {Object}         Promise to be resolved when the feed is found.
     */
    function waitFor(id, attempts, timeout) {
      var deferred = $q.defer();
      var feed = this.find(id);
      var that = this;
      attempts = attempts || 10;
      timeout = timeout || 1000;

      if (feed === null) { // If feed is not found, set an interval to check again.
        var interval = $window.setInterval(function () {
          feed = that.find(id);
          if (feed === null) { // The feed was not found this time
            attempts -= 1;
          } else { // The feed was finally found
            $window.clearInterval(interval);
            deferred.resolve(feed);
          }
          if (attempts === 0) { // No more attempts left and feed was not found
            $window.clearInterval(interval);
            deferred.reject("feed with id " + id + " was not found");
          }
        }, timeout);
      } else {
        deferred.resolve(feed);
      }

      return deferred.promise;
    }

    function add(feed, options) {
      this.feeds[feed.id] = feed;
      if (options && options.main) {
{'fraction_non_alphanumeric': 0.1156355455568054, 'fraction_numerical': 0.005399325084364455, 'mean_word_length': 2.177984274481773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6600594', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1271, 'n_words': 407}