<commit_before>/* @flow */
import type { OutboxState, Action } from '../types';
import {
  MESSAGE_SEND_START,
  EVENT_NEW_MESSAGE,
  LOGOUT,
  DELETE_OUTBOX_MESSAGE,
  MESSAGE_SEND_COMPLETE,
} from '../actionConstants';
import { NULL_ARRAY } from '../nullObjects';
import { filterArray } from '../utils/immutability';

const initialState = NULL_ARRAY;

export default (state: OutboxState = initialState, action: Action): OutboxState => {
  switch (action.type) {
    case MESSAGE_SEND_START: {
      const message = state.find(item => item.timestamp === action.params.timestamp);
      if (message) return state;
      return [...state, { ...action.params }];
    }

    case MESSAGE_SEND_COMPLETE:
    case DELETE_OUTBOX_MESSAGE:
    case EVENT_NEW_MESSAGE:
      return filterArray(state, item => item && item.timestamp !== +action.localMessageId);

    case LOGOUT:
      return initialState;

    default:
      return state;
  }
};<commit_msg>Clear outbox on account switch. (#1530)<commit_after>/* @flow */
import type { OutboxState, Action } from '../types';
import {
  MESSAGE_SEND_START,
  EVENT_NEW_MESSAGE,
  LOGOUT,
  ACCOUNT_SWITCH,
  DELETE_OUTBOX_MESSAGE,
  MESSAGE_SEND_COMPLETE,
} from '../actionConstants';
import { NULL_ARRAY } from '../nullObjects';
import { filterArray } from '../utils/immutability';

const initialState = NULL_ARRAY;

export default (state: OutboxState = initialState, action: Action): OutboxState => {
  switch (action.type) {
    case MESSAGE_SEND_START: {
      const message = state.find(item => item.timestamp === action.params.timestamp);
      if (message) return state;
      return [...state, { ...action.params }];
    }

    case MESSAGE_SEND_COMPLETE:
    case DELETE_OUTBOX_MESSAGE:
    case EVENT_NEW_MESSAGE:
      return filterArray(state, item => item && item.timestamp !== +action.localMessageId);

    case ACCOUNT_SWITCH:
    case LOGOUT:
      return initialState;

    default:
      return state;
  }
};
{'fraction_non_alphanumeric': 0.12404677173360447, 'fraction_numerical': 0.0020335536349771225, 'mean_word_length': 3.5767441860465117, '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': '4865322', 'n_tokens_mistral': 621, 'n_tokens_neox': 604, 'n_words': 148}