<commit_before>import { filter, merge } from 'lodash'
import { debug } from '../util/logging'
import {
  CREATE_COMMUNITY,
  FETCH_ACTIVITY,
  FETCH_CURRENT_USER,
  FETCH_LIVE_STATUS,
  FETCH_PEOPLE,
  FETCH_PERSON,
  JOIN_COMMUNITY_WITH_CODE,
  LEAVE_COMMUNITY_PENDING,
  LEAVE_COMMUNITY,
  LOGIN,
  LOGOUT,
  SIGNUP,
  UPDATE_USER_SETTINGS_PENDING,
  UPDATE_USER_SETTINGS,
  UPDATE_COMMUNITY_SETTINGS_PENDING,
  USE_INVITATION
} from '../actions'
import { mergeList } from './util'

export default function (state = {}, action) {
  let { type, error, payload, meta } = action
  if (error) {
    switch (type) {
      case UPDATE_USER_SETTINGS:
        return {
          ...state,
          current: merge({...state.current}, meta.prevProps)
        }
      case LEAVE_COMMUNITY:
        return {
          ...state,
          current: merge({...state.current}, meta.prevProps)
        }
      default:
        return state
    }
  }

  // the cases where there isn't a payload
  switch (type) {
    case LOGOUT:
      let currentUser = state.current
      if (!currentUser) return state

      debug('un-caching person:', currentUser.id)
      return {
        ...state,
        current: null,
        [currentUser.id]: null
      }
    case UPDATE_USER_SETTINGS_PENDING:
      let { params } = meta
      return {
        ...state,
        current: {...state.current, ...params},
        [params.id]: {...state[params.id], ...params}
      }
    case LEAVE_COMMUNITY_PENDING:
      let memberships = filter(state.current.memberships, m => m.community_id !== meta.communityId)
      return {
        ...state,
        current: {...state.current, memberships}
      }
    case UPDATE_COMMUNITY_SETTINGS_PENDING:
      if (meta.params.active === false) {
        memberships = filter(state.current.memberships, m => m.community.slug !== meta.params.slug)
        return {
          ...state,
          current: {...state.current, memberships}
        }
      }
  }

  if (!payload) return state

  switch (type) {
    case FETCH_PERSON:
      debug('caching person:', payload.id)
      return {
        ...state,
        [payload.id]: payload
      }
    case LOGIN:
    case SIGNUP:
    case FETCH_CURRENT_USER:
      debug('caching person:', payload.id)
      return {
        ...state,
        [payload.id]: payload,
        current: payload
      }
    case FETCH_PEOPLE:
      return mergeList(state, payload.people, 'id')
    case CREATE_COMMUNITY:
    case JOIN_COMMUNITY_WITH_CODE:
    case USE_INVITATION:
      return {
        ...state,
        current: {...state.current, memberships: [payload, ...state.current.memberships]}
      }
    case FETCH_ACTIVITY:
      if (meta.resetCount) {
        return {
          ...state,
          current: {...state.current, new_notification_count: 0}
        }
      }
      break
    case FETCH_LIVE_STATUS:
      return {
        ...state,
        current: {...state.current, new_notification_count: payload.new_notification_count}
      }
  }

  return state
}<commit_msg>stop live status polling from messing up login page<commit_after>import { filter, merge } from 'lodash'
import { debug } from '../util/logging'
import {
  CREATE_COMMUNITY,
  FETCH_ACTIVITY,
  FETCH_CURRENT_USER,
  FETCH_LIVE_STATUS,
  FETCH_PEOPLE,
  FETCH_PERSON,
  JOIN_COMMUNITY_WITH_CODE,
  LEAVE_COMMUNITY_PENDING,
  LEAVE_COMMUNITY,
  LOGIN,
  LOGOUT,
  SIGNUP,
  UPDATE_USER_SETTINGS_PENDING,
  UPDATE_USER_SETTINGS,
  UPDATE_COMMUNITY_SETTINGS_PENDING,
  USE_INVITATION
} from '../actions'
import { mergeList } from './util'

export default function (state = {}, action) {
  let { type, error, payload, meta } = action
  if (error) {
    switch (type) {
      case UPDATE_USER_SETTINGS:
        return {
          ...state,
          current: merge({...state.current}, meta.prevProps)
        }
      case LEAVE_COMMUNITY:
        return {
          ...state,
          current: merge({...state.current}, meta.prevProps)
        }
      default:
        return state
    }
  }

  // the cases where there isn't a payload
  switch (type) {
    case LOGOUT:
      let currentUser = state.current
      if (!currentUser) return state

      debug('un-caching person:', currentUser.id)
      return {
        ...state,
        current: null,
        [currentUser.id]: null
      }
    case UPDATE_USER_SETTINGS_PENDING:
      let { params } = meta
      return {
        ...state,
        current: {...state.current, ...params},
        [params.id]: {...state[params.id], ...params}
      }
    case LEAVE_COMMUNITY_PENDING:
      let memberships = filter(state.current.memberships, m => m.community_id !== meta.communityId)
      return {
        ...state,
        current: {...state.current, memberships}
      }
    case UPDATE_COMMUNITY_SETTINGS_PENDING:
      if (meta.params.active === false) {
        memberships = filter(state.current.memberships, m => m.community.slug !== meta.params.slug)
        return {
          ...state,
          current: {...state.current, memberships}
        }
      }
  }

  if (!payload) return state

  switch (type) {
    case FETCH_PERSON:
      debug('caching person:', payload.id)
      return {
        ...state,
        [payload.id]: payload
      }
    case LOGIN:
    case SIGNUP:
    case FETCH_CURRENT_USER:
      debug('caching person:', payload.id)
      return {
        ...state,
        [payload.id]: payload,
        current: payload
      }
    case FETCH_PEOPLE:
      return mergeList(state, payload.people, 'id')
    case CREATE_COMMUNITY:
    case JOIN_COMMUNITY_WITH_CODE:
    case USE_INVITATION:
      return {
        ...state,
        current: {...state.current, memberships: [payload, ...state.current.memberships]}
      }
    case FETCH_ACTIVITY:
      if (meta.resetCount) {
        return {
          ...state,
          current: {...state.current, new_notification_count: 0}
        }
      }
      break
    case FETCH_LIVE_STATUS:
      if (!state.current) return state
      return {
        ...state,
        current: {...state.current, new_notification_count: payload.new_notification_count}
      }
  }

  return state
}
{'fraction_non_alphanumeric': 0.11808840319686838, 'fraction_numerical': 0.00032621105855488503, 'mean_word_length': 2.106382978723404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '318635', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1956, 'n_words': 416}