<commit_before>import _ from 'lodash';

import * as ActionTypes from '../action-types';
import * as ActionHelpers from '../action-helpers';
import { userParser } from '../../utils';

const { response } = ActionHelpers;
const indexById = list => _.keyBy(list || [], 'id');
const mergeByIds = (state, array) => _.merge({}, state, indexById(array));

export default function users(state = {}, action) {
  if (ActionHelpers.isFeedResponse(action)) {
    const combinedUsers = (action.payload.users || []).concat(action.payload.subscribers || []);
    return mergeByIds(state, combinedUsers.map(userParser));
  }
  switch (action.type) {
    case response(ActionTypes.WHO_AM_I):
    case response(ActionTypes.GET_USER_INFO): {
      let newState = state;

      // Add some users from "subscribers" (that's actually your subscriPTIONs, both people and groups)
      newState = mergeByIds(newState, (action.payload.subscribers || []).map(userParser));

      // Add some users from "users.subscribers" (that's real subscribers, people only)
      newState = mergeByIds(newState, (action.payload.users.subscribers || []).map(userParser));

      // Add some users from "admins"
      newState = mergeByIds(newState, (action.payload.admins || []).map(userParser));

      // Add some users from "managedGroups[].requests" (incoming group requests, waiting for your approval)
      let reqUsers = [];
      action.payload.managedGroups.forEach(g => {
        reqUsers = reqUsers.concat(g.requests || []);
      });
      newState = mergeByIds(newState, reqUsers.map(userParser));

      // Add target user
      let userId = action.payload.users.id;
      let oldUser = state[userId] || {};
      let newUser = userParser(action.payload.users);<commit_msg>summer-cleaning: Add outcoming reqs to state.users<commit_after>import _ from 'lodash';

import * as ActionTypes from '../action-types';
import * as ActionHelpers from '../action-helpers';
import { userParser } from '../../utils';

const { response } = ActionHelpers;
const indexById = list => _.keyBy(list || [], 'id');
const mergeByIds = (state, array) => _.merge({}, state, indexById(array));

export default function users(state = {}, action) {
  if (ActionHelpers.isFeedResponse(action)) {
    const combinedUsers = (action.payload.users || []).concat(action.payload.subscribers || []);
    return mergeByIds(state, combinedUsers.map(userParser));
  }
  switch (action.type) {
    case response(ActionTypes.WHO_AM_I):
    case response(ActionTypes.GET_USER_INFO): {
      let newState = state;

      // Add some users from "subscribers" (that's actually your subscriPTIONs, both people and groups)
      newState = mergeByIds(newState, (action.payload.subscribers || []).map(userParser));

      // Add some users from "users.subscribers" (that's real subscribers, people only)
      newState = mergeByIds(newState, (action.payload.users.subscribers || []).map(userParser));

      // Add some users from "admins"
      newState = mergeByIds(newState, (action.payload.admins || []).map(userParser));

      // Add some users from "requests" (outcoming subscription requests)
      newState = mergeByIds(newState, (action.payload.requests || []).map(userParser));

      // Add some users from "managedGroups[].requests" (incoming group requests, waiting for your approval)
      let reqUsers = [];
      action.payload.managedGroups.forEach(g => {
        reqUsers = reqUsers.concat(g.requests || []);
      });
      newState = mergeByIds(newState, reqUsers.map(userParser));

      // Add target user
      let userId = action.payload.users.id;
      let oldUser = state[userId] || {};
      let newUser = userParser(action.payload.users);
{'fraction_non_alphanumeric': 0.1448294531672983, 'fraction_numerical': 0.0, 'mean_word_length': 3.731113956466069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1434563', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1067, 'n_words': 270}