<commit_before>/*
@license
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

import Xen from '../../../components/xen/xen.js';
import {Stores} from './stores.js';
import {SingleUserContext} from './single-user-context.js';
import {schemas} from './schemas.js';

const log = Xen.logFactory('UserContext', '#4f0433');

customElements.define('user-context', class extends Xen.Debug(Xen.Base, log) {
  static get observedAttributes() {
    return ['context', 'userid', 'coords', 'users'];
  }
  _getInitialState() {
    return {
      // maps userid to SingleUserContext for friends
      friends: {},
      // maps entityid's to userid's for friends to workaround missing data
      // in `remove` records
      friendEntityIds: {},
      // snapshot of BOXED_avatar for use by shell
      avatars: {},
    };
  }
  _update(props, state) {
    const {context, userid, coords, users} = props;
    const {user, userStore, usersStore} = state;
    if (context && !state.initStores) {
      state.initStores = true;
      this._requireStores(context);
    }
    if (users && usersStore && state.users !== users) {
      state.users = users;
      // TODO(sjmiles): clear usersStore first, or modify _updateSystemStores to avoid
      // duplication ... as of now this never happens since `users` is only generated
      // once.
      this._updateSystemUsers(users, usersStore);
    }
    if (user && userStore && userid !== state.userid) {
      state.userid = userid;
      this._updateSystemUser(props, state);
    }
    if (user && userStore && coords && coords !== user.rawData.location) {
      user.rawData.location = coords;
      log('updating user coords:', user);
      userStore.set({user});
    }
  }
  async _requireStores(context) {
    await Promise.all([<commit_msg>fix improper use of `set` (#1971)<commit_after>/*
@license
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

import Xen from '../../../components/xen/xen.js';
import {Stores} from './stores.js';
import {SingleUserContext} from './single-user-context.js';
import {schemas} from './schemas.js';

const log = Xen.logFactory('UserContext', '#4f0433');

customElements.define('user-context', class extends Xen.Debug(Xen.Base, log) {
  static get observedAttributes() {
    return ['context', 'userid', 'coords', 'users'];
  }
  _getInitialState() {
    return {
      // maps userid to SingleUserContext for friends
      friends: {},
      // maps entityid's to userid's for friends to workaround missing data
      // in `remove` records
      friendEntityIds: {},
      // snapshot of BOXED_avatar for use by shell
      avatars: {},
    };
  }
  _update(props, state) {
    const {context, userid, coords, users} = props;
    const {user, userStore, usersStore} = state;
    if (context && !state.initStores) {
      state.initStores = true;
      this._requireStores(context);
    }
    if (users && usersStore && state.users !== users) {
      state.users = users;
      // TODO(sjmiles): clear usersStore first, or modify _updateSystemStores to avoid
      // duplication ... as of now this never happens since `users` is only generated
      // once.
      this._updateSystemUsers(users, usersStore);
    }
    if (user && userStore && userid !== state.userid) {
      state.userid = userid;
      this._updateSystemUser(props, state);
    }
    if (user && userStore && coords && coords !== user.rawData.location) {
      user.rawData.location = coords;
      log('updating user coords:', user);
      userStore.set(user);
    }
  }
  async _requireStores(context) {
    await Promise.all([
{'fraction_non_alphanumeric': 0.12600716204118173, 'fraction_numerical': 0.004923903312444047, 'mean_word_length': 3.1844569288389515, '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': '5661478', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1294, 'n_words': 420}