<commit_before>/*global app */
/**
 * Talkilla models and collections.
 */
(function(app, Backbone) {
  "use strict";

  app.models.AppStatus = Backbone.Model.extend({
    defaults: {workerInitialized: false,
               firstReconnection: undefined,
               reconnecting: false,
               connected: false
             },
    /**
     * Triggered when a reconnection event occured on the server.
     *
     * @param {app.payloads.Reconnection} the reconnection payload object.
     **/
    ongoingReconnection: function(reconnectionMsg) {
      // Reconnections can happen without the user notifying it.
      // To accomplish this, we store some state about the reconnection
      // in here, and only change the reconnecting property when
      // the user should be notified.
      if (this.get('firstReconnection') === undefined){
        this.set('firstReconnection', new Date());
      } else if (new Date() - this.get('firstReconnection') >= 10000){
        // Only notify the users there is a server-connection problem after
        // trying for some time (10s)
        this.set('connected', false);
        this.set('reconnecting', reconnectionMsg);
      }
    }
  });

  app.models.UserSet = Backbone.Collection.extend({
    model: app.models.User,

    /**
     * Internal higher order function for comparing a user model to a user
     * identifier.
     *
     * @private
     * @param  {String} userId Either an email address or a phone number
     * @return {Function}
     */
    _userIs: function(userId) {
      return function(user) {
        return user.get("username")    === userId ||
               user.get("email")       === userId ||
               user.get("phoneNumber") === userId;
      };
    },

    /**
     * Used to sort users by lowercased username.
     *
     * @param  {User} item
     * @return {String}
     */
    comparator: function(item) {
      return (item.get("fullName") ||
              item.get("email")    ||
              item.get("phoneNumber")).toLowerCase();
    },

    /**
     * Excludes a user from the list.
     *
     * @param  {app.models.User} user
     * @return {Array}
     */
    excludeUser: function(userId) {
      return this.chain().reject(this._userIs(userId)).value();
    },

    /**
     * Find a user from its identifier which can be either an email address or
     * a phone number.<commit_msg>simplified UserSet#excludeUser()<commit_after>/*global app */
/**
 * Talkilla models and collections.
 */
(function(app, Backbone) {
  "use strict";

  app.models.AppStatus = Backbone.Model.extend({
    defaults: {workerInitialized: false,
               firstReconnection: undefined,
               reconnecting: false,
               connected: false
             },
    /**
     * Triggered when a reconnection event occured on the server.
     *
     * @param {app.payloads.Reconnection} the reconnection payload object.
     **/
    ongoingReconnection: function(reconnectionMsg) {
      // Reconnections can happen without the user notifying it.
      // To accomplish this, we store some state about the reconnection
      // in here, and only change the reconnecting property when
      // the user should be notified.
      if (this.get('firstReconnection') === undefined){
        this.set('firstReconnection', new Date());
      } else if (new Date() - this.get('firstReconnection') >= 10000){
        // Only notify the users there is a server-connection problem after
        // trying for some time (10s)
        this.set('connected', false);
        this.set('reconnecting', reconnectionMsg);
      }
    }
  });

  app.models.UserSet = Backbone.Collection.extend({
    model: app.models.User,

    /**
     * Internal higher order function for comparing a user model to a user
     * identifier.
     *
     * @private
     * @param  {String} userId Either an email address or a phone number
     * @return {Function}
     */
    _userIs: function(userId) {
      return function(user) {
        return user.get("username")    === userId ||
               user.get("email")       === userId ||
               user.get("phoneNumber") === userId;
      };
    },

    /**
     * Used to sort users by lowercased username.
     *
     * @param  {User} item
     * @return {String}
     */
    comparator: function(item) {
      return (item.get("fullName") ||
              item.get("email")    ||
              item.get("phoneNumber")).toLowerCase();
    },

    /**
     * Excludes a user having the provided id from the list.
     *
     * @param  {app.models.User} user
     * @return {Array}
     */
    excludeUser: function(userId) {
      return this.reject(this._userIs(userId));
    },

    /**
     * Find a user from its identifier which can be either an email address or
     * a phone number.
{'fraction_non_alphanumeric': 0.12073981712385702, 'fraction_numerical': 0.0029093931837073984, 'mean_word_length': 2.1622864651773983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3487972', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1322, 'n_words': 390}