<commit_before>var window = {};

/**
 * IdentityProvider handles the individual identities for each network.
 */
function IdentityProvider() {
  window.current = this;
  console.log('Meta Identity Provider');
  this.profile = {
    me: {},
    roster: {}
  };

  // Map from clientIDs -> network
  this.reverseIndex = {};
  this.providers = {
    // loopback: {
     // ref: freedom.loopbackIdentity(),
     // status: 'offline',
     // userId: null,
     // network: 'loopback'
    // },
    //manual: {
    //  ref: freedom.manualIdentity(),
    //  status: 'offline',
    //  userId: null,
    //  network: 'manual'
    //},
    xmpp: {
      ref: freedom.xmppIdentity(),
      status: 'offline',
      userId: null,
      network: 'xmpp'
    },
    google: {
      ref: freedom.googleIdentity(),
      status: 'offline',
      userId: null,
      network: 'google'
    },
    facebook: {
      ref: freedom.facebookIdentity(),
      status: 'offline',
      userId: null,
      network: 'facebook'
    }
  };
  //Register listeners
  for (var key in this.providers) {
    if (this.providers.hasOwnProperty(key)) {
      this.providers[key].ref.on('onStatus', (function(key, data) {
        this.onStatus(data, key);
      }).bind(this, key));
      this.providers[key].ref.on('onChange', (function(key, data) {
        data.network = this.providers[key].network;
        this.onChange(data, key);
      }).bind(this, key));
      this.providers[key].ref.on('onMessage', (function(key, data) {
        data.network = this.providers[key].network;
        this.onMessage(data, key);
      }).bind(this, key));
    }
  }
};

// Either login to |network|, or try each provider.
IdentityProvider.prototype.login = function(opts, continuation) {
  if (opts.network && this.providers[opts.network]) {
    this.providers[opts.network].ref.login(opts);
  } else if (opts.network) {
    console.error('Invalid network name: '+opts.network);
  } else {
    for (var key in this.providers) {
      if (this.providers.hasOwnProperty(key)) {
        this.providers[key].ref.login(opts);
      }
    }
  }
  continuation();
};

IdentityProvider.prototype.getProfile = function(id, continuation) {
  if (id == undefined) {
    continuation(this.profile);
  } else if (this.profile.me[id]) {
    continuation(this.profile);
  } else if (this.profile.roster[id]) {
    continuation({me: this.profile.roster[id], roster: {}});
  }
};

// Send a message to someone.
IdentityProvider.prototype.sendMessage = function(to, msg, continuation) {
  if (this.reverseIndex[to]) {
    console.log('identity sending! ', to, msg);
    var key = this.reverseIndex[to];
    this.providers[key].ref.sendMessage(to, msg).done(function(ret) {
      continuation(ret);
    });
  } else {
    try {
      throw new Error("Error: identity provider missing for contact: " + to +
          ", current reverse index: " + JSON.stringify(this.reverseIndex));
    } catch (e) {
      console.log("call stack: " + e.stack);
    }
  }
};

IdentityProvider.prototype.logout = function(userId, networkName, continuation) {
  var results = {};
  var providerCount = 0;
  for (var key in this.providers) {
    if (this.providers.hasOwnProperty(key)) {
      if ((userId == undefined && networkName == undefined) ||
          this.providers[key].userId == userId ||
          this.providers[key].network == networkName) {
        providerCount += 1;
        this.providers[key].ref.logout(userId, networkName).done(function(data) {<commit_msg>Fix reset bug by making logout check for 'null' string.<commit_after>var window = {};

/**
 * IdentityProvider handles the individual identities for each network.
 */
function IdentityProvider() {
  window.current = this;
  console.log('Meta Identity Provider');
  this.profile = {
    me: {},
    roster: {}
  };

  // Map from clientIDs -> network
  this.reverseIndex = {};
  this.providers = {
    // loopback: {
     // ref: freedom.loopbackIdentity(),
     // status: 'offline',
     // userId: null,
     // network: 'loopback'
    // },
    //manual: {
    //  ref: freedom.manualIdentity(),
    //  status: 'offline',
    //  userId: null,
    //  network: 'manual'
    //},
    xmpp: {
      ref: freedom.xmppIdentity(),
      status: 'offline',
      userId: null,
      network: 'xmpp'
    },
    google: {
      ref: freedom.googleIdentity(),
      status: 'offline',
      userId: null,
      network: 'google'
    },
    facebook: {
      ref: freedom.facebookIdentity(),
      status: 'offline',
      userId: null,
      network: 'facebook'
    }
  };
  //Register listeners
  for (var key in this.providers) {
    if (this.providers.hasOwnProperty(key)) {
      this.providers[key].ref.on('onStatus', (function(key, data) {
        this.onStatus(data, key);
      }).bind(this, key));
      this.providers[key].ref.on('onChange', (function(key, data) {
        data.network = this.providers[key].network;
        this.onChange(data, key);
      }).bind(this, key));
      this.providers[key].ref.on('onMessage', (function(key, data) {
        data.network = this.providers[key].network;
        this.onMessage(data, key);
      }).bind(this, key));
    }
  }
};

// Either login to |network|, or try each provider.
IdentityProvider.prototype.login = function(opts, continuation) {
  console.log('dborkan: identity.js: IdentityProvider.prototype.login called');
  if (opts.network && this.providers[opts.network]) {
    this.providers[opts.network].ref.login(opts);
  } else if (opts.network) {
    console.error('Invalid network name: '+opts.network);
  } else {
    for (var key in this.providers) {
      if (this.providers.hasOwnProperty(key)) {
        this.providers[key].ref.login(opts);
      }
    }
  }
  continuation();
};

IdentityProvider.prototype.getProfile = function(id, continuation) {
  if (id == undefined) {
    continuation(this.profile);
  } else if (this.profile.me[id]) {
    continuation(this.profile);
  } else if (this.profile.roster[id]) {
    continuation({me: this.profile.roster[id], roster: {}});
  }
};

// Send a message to someone.
IdentityProvider.prototype.sendMessage = function(to, msg, continuation) {
  if (this.reverseIndex[to]) {
    console.log('identity sending! ', to, msg);
    var key = this.reverseIndex[to];
    this.providers[key].ref.sendMessage(to, msg).done(function(ret) {
      continuation(ret);
    });
  } else {
    try {
      throw new Error("Error: identity provider missing for contact: " + to +
          ", current reverse index: " + JSON.stringify(this.reverseIndex));
    } catch (e) {
      console.log("call stack: " + e.stack);
    }
  }
};

IdentityProvider.prototype.logout = function(userId, networkName, continuation) {
  var results = {};
  var providerCount = 0;
  for (var key in this.providers) {
    if (this.providers.hasOwnProperty(key)) {
      if ((userId == undefined && networkName == undefined) ||
          // Freedom passes null as a string 'null', so check for that too.
          (userId == 'null' && networkName == 'null') ||
          this.providers[key].userId == userId ||
          this.providers[key].network == networkName) {
        providerCount += 1;
        this.providers[key].ref.logout(userId, networkName).done(function(data) {
{'fraction_non_alphanumeric': 0.15955831608005522, 'fraction_numerical': 0.0005521048999309869, 'mean_word_length': 2.8076720966894375, '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': '1672790', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2273, 'n_words': 477}