<commit_before>kd              = require 'kd'
React           = require 'kd-react'
ChatList        = require 'activity/components/chatlist'
ChatInputWidget = require 'activity/components/chatinputwidget'
Scroller        = require 'app/components/scroller'
ActivityFlux    = require 'activity/flux'


module.exports = class ChatPane extends React.Component

  @defaultProps =
    title         : null
    messages      : null
    isDataLoading : no
    onLoadMore    : kd.noop
    isParticipant : no


  componentWillUpdate: ->

    return  unless @refs?.scrollContainer

    { @scrollTop, offsetHeight, @scrollHeight } = React.findDOMNode @refs.scrollContainer
    @shouldScrollToBottom = @scrollTop + offsetHeight is @scrollHeight


  componentDidUpdate: ->

    return  unless @refs?.scrollContainer

    element = React.findDOMNode @refs.scrollContainer

    if @shouldScrollToBottom
      element.scrollTop = element.scrollHeight
    else
      element.scrollTop = @scrollTop + (element.scrollHeight - @scrollHeight)


  onSubmit: (event) -> @props.onSubmit? event


  onTopThresholdReached: -> @props.onLoadMore()


  renderBody: ->
    return null  unless @props.messages

    messages = @props.messages.sortBy (m) -> m?.get 'createdAt'

    <section className="ChatPane-body" ref="ChatPaneBody">
      <Scroller
        onTopThresholdReached={@bound 'onTopThresholdReached'}
        ref="scrollContainer">
        <ChatList messages={messages} />
      </Scroller>
    </section>


  onFollowChannelButtonClick: ->

    ActivityFlux.actions.channel.followChannel @props.thread.getIn ['channel', 'id']


  renderFollowChannel: ->
<commit_msg>activity: delegate to component creator for follow button action<commit_after>kd              = require 'kd'
React           = require 'kd-react'
ChatList        = require 'activity/components/chatlist'
ChatInputWidget = require 'activity/components/chatinputwidget'
Scroller        = require 'app/components/scroller'
ActivityFlux    = require 'activity/flux'


module.exports = class ChatPane extends React.Component

  @defaultProps =
    title         : null
    messages      : null
    isDataLoading : no
    onLoadMore    : kd.noop
    isParticipant : no


  componentWillUpdate: ->

    return  unless @refs?.scrollContainer

    { @scrollTop, offsetHeight, @scrollHeight } = React.findDOMNode @refs.scrollContainer
    @shouldScrollToBottom = @scrollTop + offsetHeight is @scrollHeight


  componentDidUpdate: ->

    return  unless @refs?.scrollContainer

    element = React.findDOMNode @refs.scrollContainer

    if @shouldScrollToBottom
      element.scrollTop = element.scrollHeight
    else
      element.scrollTop = @scrollTop + (element.scrollHeight - @scrollHeight)


  onSubmit: (event) -> @props.onSubmit? event


  onTopThresholdReached: -> @props.onLoadMore()


  renderBody: ->
    return null  unless @props.messages

    messages = @props.messages.sortBy (m) -> m?.get 'createdAt'

    <section className="ChatPane-body" ref="ChatPaneBody">
      <Scroller
        onTopThresholdReached={@bound 'onTopThresholdReached'}
        ref="scrollContainer">
        <ChatList messages={messages} />
      </Scroller>
    </section>


  onFollowChannelButtonClick: -> @props.onFollowChannelButtonClick()


  renderFollowChannel: ->

{'fraction_non_alphanumeric': 0.09887776766757658, 'fraction_numerical': 0.0, 'mean_word_length': 3.233632862644416, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, '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': '6955384', 'n_tokens_mistral': 959, 'n_tokens_neox': 901, 'n_words': 199}