<commit_before>// @flow
import * as I from 'immutable'
import * as Constants from '../../constants/chat'
import * as SearchConstants from '../../constants/search'
import * as ChatTypes from '../../constants/types/flow-types-chat'
import Inbox from './index'
import pausableConnect from '../../util/pausable-connect'
import {
  loadInbox,
  newChat,
  untrustedInboxVisible,
  setInboxFilter,
  selectConversation,
} from '../../actions/chat/creators'
import {createSelector} from 'reselect'
import {compose, lifecycle, withState, withHandlers} from 'recompose'
import throttle from 'lodash/throttle'
import flatten from 'lodash/flatten'

import type {TypedState} from '../../constants/reducer'

const smallTeamsCollapsedMaxShown = 5
const getInbox = (state: TypedState) => state.chat.get('inbox')
const getSupersededByState = (state: TypedState) => state.chat.get('supersededByState')
const getAlwaysShow = (state: TypedState) => state.chat.get('alwaysShow')
const getPending = (state: TypedState) => state.chat.get('pendingConversations')
const getFilter = (state: TypedState) => state.chat.get('inboxFilter')
const getUnreadCounts = (state: TypedState) => state.chat.get('conversationUnreadCounts')

const passesStringFilter = (filter: string, toCheck: string): boolean => {
  // No need to worry about Unicode issues with toLowerCase(), since
  // names can only be ASCII.
  return toCheck.toLowerCase().indexOf(filter.toLowerCase()) >= 0
}

const passesParticipantFilter = (filter: string, participants: Array<string>, you: ?string): boolean => {
  if (!filter) {
    return true
  }

  // don't filter you out if its just a convo with you!
  const justYou = participants.length === 1 && participants[0] === you
  const names = justYou ? participants : participants.filter(p => p !== you)
  if (names.some(n => passesStringFilter(filter, n))) {
    return true
  }

  if (passesStringFilter(filter, names.join(','))) {
    return true
  }

  return false
}

// Simple score for a filter. returns 1 for exact match. 0.75 for full name match
// in a group conversation. 0.5 for a partial match
// 0 for no match
function scoreFilter(filter: string, stringToFilterOn: string, participants: Array<string>, you: string) {
  const lcFilter = filter.toLowerCase()
  if (!stringToFilterOn && participants.length) {
    if (lcFilter === you.toLowerCase()) {
      return 1
    }
    if (participants.some(p => p.toLowerCase() === lcFilter)) {
      return 1 - (participants.length - 1) / 100 * 0.25
    }<commit_msg>Ditch the .some()<commit_after>// @flow
import * as I from 'immutable'
import * as Constants from '../../constants/chat'
import * as SearchConstants from '../../constants/search'
import * as ChatTypes from '../../constants/types/flow-types-chat'
import Inbox from './index'
import pausableConnect from '../../util/pausable-connect'
import {
  loadInbox,
  newChat,
  untrustedInboxVisible,
  setInboxFilter,
  selectConversation,
} from '../../actions/chat/creators'
import {createSelector} from 'reselect'
import {compose, lifecycle, withState, withHandlers} from 'recompose'
import throttle from 'lodash/throttle'
import flatten from 'lodash/flatten'

import type {TypedState} from '../../constants/reducer'

const smallTeamsCollapsedMaxShown = 5
const getInbox = (state: TypedState) => state.chat.get('inbox')
const getSupersededByState = (state: TypedState) => state.chat.get('supersededByState')
const getAlwaysShow = (state: TypedState) => state.chat.get('alwaysShow')
const getPending = (state: TypedState) => state.chat.get('pendingConversations')
const getFilter = (state: TypedState) => state.chat.get('inboxFilter')
const getUnreadCounts = (state: TypedState) => state.chat.get('conversationUnreadCounts')

const passesStringFilter = (filter: string, toCheck: string): boolean => {
  // No need to worry about Unicode issues with toLowerCase(), since
  // names can only be ASCII.
  return toCheck.toLowerCase().indexOf(filter.toLowerCase()) >= 0
}

const passesParticipantFilter = (filter: string, participants: Array<string>, you: ?string): boolean => {
  if (!filter) {
    return true
  }

  // don't filter you out if its just a convo with you!
  const justYou = participants.length === 1 && participants[0] === you
  const names = justYou ? participants : participants.filter(p => p !== you)
  return passesStringFilter(filter, names.join(','))
}

// Simple score for a filter. returns 1 for exact match. 0.75 for full name match
// in a group conversation. 0.5 for a partial match
// 0 for no match
function scoreFilter(filter: string, stringToFilterOn: string, participants: Array<string>, you: string) {
  const lcFilter = filter.toLowerCase()
  if (!stringToFilterOn && participants.length) {
    if (lcFilter === you.toLowerCase()) {
      return 1
    }
    if (participants.some(p => p.toLowerCase() === lcFilter)) {
      return 1 - (participants.length - 1) / 100 * 0.25
    }
{'fraction_non_alphanumeric': 0.13739059637695908, 'fraction_numerical': 0.008141664970486465, 'mean_word_length': 4.283870967741936, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, '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': '2621987', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1494, 'n_words': 448}