<commit_before>/* @flow */
import isEqual from 'lodash.isequal';

import type { ChatState, Action } from '../types';
import {
  LOGOUT,
  LOGIN_SUCCESS,
  ACCOUNT_SWITCH,
  SWITCH_NARROW,
  MESSAGE_FETCH_START,
  MESSAGE_FETCH_SUCCESS,
  EVENT_NEW_MESSAGE,
  EVENT_REACTION_ADD,
  EVENT_REACTION_REMOVE,
  EVENT_UPDATE_MESSAGE,
} from '../actionConstants';
import { homeNarrow, isMessageInNarrow } from '../utils/narrow';
import chatUpdater from './chatUpdater';
import { getMessagesById } from '../selectors';

const initialState: ChatState = {
  fetchingOlder: true,
  fetchingNewer: true,
  narrow: homeNarrow(),
  messages: {},
};

export default (state: ChatState = initialState, action: Action) => {
  switch (action.type) {
    case LOGOUT:
    case LOGIN_SUCCESS:
    case ACCOUNT_SWITCH:
      return initialState;
    case MESSAGE_FETCH_START:
      return {
        ...state,
        narrow: action.narrow,
        fetchingOlder: action.fetchingOlder,
        fetchingNewer: action.fetchingNewer,
      };

    case SWITCH_NARROW: {
      return {
        ...state,
        narrow: action.narrow,
        fetchingOlder: false,
        fetchingNewer: false,
      };
    }
<commit_msg>Fix issue with tracking fetching status (#1025)<commit_after>/* @flow */
import isEqual from 'lodash.isequal';

import type { ChatState, Action } from '../types';
import {
  LOGOUT,
  LOGIN_SUCCESS,
  ACCOUNT_SWITCH,
  SWITCH_NARROW,
  MESSAGE_FETCH_START,
  MESSAGE_FETCH_SUCCESS,
  EVENT_NEW_MESSAGE,
  EVENT_REACTION_ADD,
  EVENT_REACTION_REMOVE,
  EVENT_UPDATE_MESSAGE,
} from '../actionConstants';
import { homeNarrow, isMessageInNarrow } from '../utils/narrow';
import chatUpdater from './chatUpdater';
import { getMessagesById } from '../selectors';

const initialState: ChatState = {
  fetchingOlder: true,
  fetchingNewer: true,
  narrow: homeNarrow(),
  messages: {},
};

export default (state: ChatState = initialState, action: Action) => {
  switch (action.type) {
    case LOGOUT:
    case LOGIN_SUCCESS:
    case ACCOUNT_SWITCH:
      return initialState;
    case MESSAGE_FETCH_START:
      if (!isEqual(action.narrow, state.narrow)) {
        return state;
      }

      return {
        ...state,
        fetchingOlder: action.fetchingOlder || state.fetchingOlder,
        fetchingNewer: action.fetchingNewer || state.fetchingNewer,
      };

    case SWITCH_NARROW: {
      return {
        ...state,
        narrow: action.narrow,
        fetchingOlder: false,
        fetchingNewer: false,
      };
    }

{'fraction_non_alphanumeric': 0.10987703292344307, 'fraction_numerical': 0.0015866719555731853, 'mean_word_length': 3.134426229508197, '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': '4117513', 'n_tokens_mistral': 848, 'n_tokens_neox': 825, 'n_words': 181}