<commit_before>_ = require 'underscore-plus'
React = require 'react'
{ListTabular, Spinner} = require 'ui-components'
{timestamp, subject} = require './formatting-utils'
{Actions,
 Utils,
 ThreadStore,
 WorkspaceStore,
 NamespaceStore} = require 'inbox-exports'

ThreadListParticipants = require './thread-list-participants'

module.exports =
ThreadList = React.createClass
  displayName: 'ThreadList'

  getInitialState: ->
    @_getStateFromStores()
 
  componentDidMount: ->
    @_prepareColumns()
    @thread_store_unsubscribe = ThreadStore.listen @_onChange
    @thread_unsubscriber = atom.commands.add '.thread-list', {
      'thread-list:star-thread': => @_onStarThread()
    }
    @body_unsubscriber = atom.commands.add 'body', {
      'application:previous-item': => @_onShiftSelectedIndex(-1)
      'application:next-item': => @_onShiftSelectedIndex(1)
      'application:focus-item': => @_onFocusSelectedIndex()
      'application:remove-item': @_onArchiveCurrentThread
      'application:remove-and-previous': -> Actions.archiveAndPrevious()
      'application:remove-and-next': -> Actions.archiveAndNext()
      'application:reply': @_onReply
      'application:reply-all': @_onReplyAll
      'application:forward': @_onForward
    }

  componentWillUnmount: ->
    @thread_store_unsubscribe()
    @thread_unsubscriber.dispose()
    @body_unsubscriber.dispose()

  render: ->
    # IMPORTANT: DO NOT pass inline functions as props. _.isEqual thinks these
    # are "different", and will re-render everything. Instead, declare them with ?=,
    # pass a reference. (Alternatively, ignore these in children's shouldComponentUpdate.)
    #
    # BAD:   onSelect={ (item) -> Actions.selectThreadId(item.id) }
    # GOOD:  onSelect={@_onSelectItem}
    #
    classes = React.addons.classSet("thread-list": true, "ready": @state.ready)

    @_itemClassProvider ?= (item) -> if item.isUnread() then 'unread' else ''
    @_itemOnSelect ?= (item) -> Actions.selectThreadId(item.id)

    <div className={classes}>
      <ListTabular
        columns={@_columns}
        items={@state.items}
        itemClassProvider={@_itemClassProvider}
        selectedId={@state.selectedId}
        onSelect={@_itemOnSelect} />
      <Spinner visible={!@state.ready} />
    </div>

  _prepareColumns: ->
    myEmail = NamespaceStore.current()?.emailAddress

    labelComponents = (thread) =>
      for label in @state.threadLabelComponents
        LabelComponent = label.view
        <LabelComponent thread={thread} />

    lastMessageType = (thread) -><commit_msg>fix(thread-list): Email not ready when _prepareColumns runs<commit_after>_ = require 'underscore-plus'
React = require 'react'
{ListTabular, Spinner} = require 'ui-components'
{timestamp, subject} = require './formatting-utils'
{Actions,
 Utils,
 ThreadStore,
 WorkspaceStore,
 NamespaceStore} = require 'inbox-exports'

ThreadListParticipants = require './thread-list-participants'

module.exports =
ThreadList = React.createClass
  displayName: 'ThreadList'

  getInitialState: ->
    @_getStateFromStores()
 
  componentDidMount: ->
    @_prepareColumns()
    @thread_store_unsubscribe = ThreadStore.listen @_onChange
    @thread_unsubscriber = atom.commands.add '.thread-list', {
      'thread-list:star-thread': => @_onStarThread()
    }
    @body_unsubscriber = atom.commands.add 'body', {
      'application:previous-item': => @_onShiftSelectedIndex(-1)
      'application:next-item': => @_onShiftSelectedIndex(1)
      'application:focus-item': => @_onFocusSelectedIndex()
      'application:remove-item': @_onArchiveCurrentThread
      'application:remove-and-previous': -> Actions.archiveAndPrevious()
      'application:remove-and-next': -> Actions.archiveAndNext()
      'application:reply': @_onReply
      'application:reply-all': @_onReplyAll
      'application:forward': @_onForward
    }

  componentWillUnmount: ->
    @thread_store_unsubscribe()
    @thread_unsubscriber.dispose()
    @body_unsubscriber.dispose()

  render: ->
    # IMPORTANT: DO NOT pass inline functions as props. _.isEqual thinks these
    # are "different", and will re-render everything. Instead, declare them with ?=,
    # pass a reference. (Alternatively, ignore these in children's shouldComponentUpdate.)
    #
    # BAD:   onSelect={ (item) -> Actions.selectThreadId(item.id) }
    # GOOD:  onSelect={@_onSelectItem}
    #
    classes = React.addons.classSet("thread-list": true, "ready": @state.ready)

    @_itemClassProvider ?= (item) -> if item.isUnread() then 'unread' else ''
    @_itemOnSelect ?= (item) -> Actions.selectThreadId(item.id)

    <div className={classes}>
      <ListTabular
        columns={@_columns}
        items={@state.items}
        itemClassProvider={@_itemClassProvider}
        selectedId={@state.selectedId}
        onSelect={@_itemOnSelect} />
      <Spinner visible={!@state.ready} />
    </div>

  _prepareColumns: ->
    labelComponents = (thread) =>
      for label in @state.threadLabelComponents
        LabelComponent = label.view
        <LabelComponent thread={thread} />

    lastMessageType = (thread) ->
      myEmail = NamespaceStore.current()?.emailAddress
{'fraction_non_alphanumeric': 0.13346265761396703, 'fraction_numerical': 0.0007759456838021338, 'mean_word_length': 3.8141923436041085, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 45, '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': '6074497', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1535, 'n_words': 294}