<commit_before>/* @flow */
import type { Action, TypingState } from '../types';
import { EVENT_TYPING_START, EVENT_TYPING_STOP } from '../actionConstants';
import { normalizeRecipientsSansMe } from '../utils/message';
import { NULL_ARRAY, NULL_OBJECT } from '../nullObjects';

const initialState: TypingState = NULL_OBJECT;

export default (state: TypingState = initialState, action: Action): TypingState => {
  switch (action.type) {
    case EVENT_TYPING_START: {
      const normalizedRecipients = normalizeRecipientsSansMe(action.recipients, action.ownEmail);
      const previousTypingUsers = state[normalizedRecipients] || NULL_ARRAY;

      const isUserAlreadyTyping = previousTypingUsers.indexOf(action.sender.user_id);
      if (isUserAlreadyTyping > -1) {
        return state;
      }

      return {
        ...state,
        [normalizedRecipients]: [...previousTypingUsers, action.sender.user_id],
      };
    }

    case EVENT_TYPING_STOP: {
      const normalizedRecipients = normalizeRecipientsSansMe(action.recipients, action.ownEmail);
      const previousTypingUsers = state[normalizedRecipients];

      if (!previousTypingUsers) {
        return state;<commit_msg>Ignore typing events sent by self. (#1563)<commit_after>/* @flow */
import type { Action, TypingState } from '../types';
import { EVENT_TYPING_START, EVENT_TYPING_STOP } from '../actionConstants';
import { normalizeRecipientsSansMe } from '../utils/message';
import { NULL_ARRAY, NULL_OBJECT } from '../nullObjects';

const initialState: TypingState = NULL_OBJECT;

export default (state: TypingState = initialState, action: Action): TypingState => {
  switch (action.type) {
    case EVENT_TYPING_START: {
      if (action.sender.email === action.ownEmail) {
        // don't change state when self is typing
        return state;
      }

      const normalizedRecipients = normalizeRecipientsSansMe(action.recipients, action.ownEmail);
      const previousTypingUsers = state[normalizedRecipients] || NULL_ARRAY;

      const isUserAlreadyTyping = previousTypingUsers.indexOf(action.sender.user_id);
      if (isUserAlreadyTyping > -1) {
        return state;
      }

      return {
        ...state,
        [normalizedRecipients]: [...previousTypingUsers, action.sender.user_id],
      };
    }

    case EVENT_TYPING_STOP: {
      const normalizedRecipients = normalizeRecipientsSansMe(action.recipients, action.ownEmail);
      const previousTypingUsers = state[normalizedRecipients];

      if (!previousTypingUsers) {
        return state;
{'fraction_non_alphanumeric': 0.10808678500986194, 'fraction_numerical': 0.002366863905325444, 'mean_word_length': 3.6446886446886446, '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': '942862', 'n_tokens_mistral': 755, 'n_tokens_neox': 711, 'n_words': 161}