<commit_before>kd              = require 'kd'
React           = require 'kd-react'
immutable       = require 'immutable'
ActivityFlux    = require 'activity/flux'
ChatPane        = require 'activity/components/chatpane'
ChatInputFlux   = require 'activity/flux/chatinput'
ChatInputWidget = require 'activity/components/chatinputwidget'


module.exports = class PublicChatPane extends React.Component

  @defaultProps =
    thread   : immutable.Map()
    messages : immutable.List()
    padded   : no

  constructor: (props) ->

    super props

    @state =
      showIntegrationTooltip   : no
      showCollaborationTooltip : no


  channel: (key) -> @props.thread?.getIn ['channel', key]


  onSubmit: ({ value }) ->

    return  unless body = value
    name = @channel 'name'

    unless body.match ///\##{name}///
      body += " ##{name} "

    ActivityFlux.actions.message.createMessage @channel('id'), body


  onLoadMore: ->

    return  unless @props.messages.size
    return  if @props.thread.getIn ['flags', 'isMessagesLoading']

    from = @props.messages.first().get('createdAt')
    kd.utils.defer => ActivityFlux.actions.message.loadMessages @channel('id'), { from }


  onFollowChannel: ->

    ActivityFlux.actions.channel.followChannel @channel 'id'


  startCollaboration: (event) ->

    kd.utils.stopDOMEvent event

    @setState showCollaborationTooltip: yes

    kd.utils.wait 2000, => @setState showCollaborationTooltip: no


  inviteOthers: (event) ->

    kd.utils.stopDOMEvent event

    chatInputWidget = @refs.chatInputWidget
    textInput = React.findDOMNode chatInputWidget.refs.textInput
    textInput.focus()

    ChatInputFlux.actions.value.setValue @props.thread.get('channelId'), '/invite @'


  addIntegration: (event) ->

    kd.utils.stopDOMEvent event

    @setState showIntegrationTooltip: yes

    kd.utils.wait 2000, => @setState showIntegrationTooltip: no


  renderFollowChannel: ->

    <div className="PublicChatPane-subscribeContainer">
      YOU NEED TO FOLLOW THIS CHANNEL TO JOIN THE CONVERSATION
      <button
        ref       = "button"
        className = "Button Button-followChannel"
        onClick   = { @bound 'onFollowChannel' }>
          FOLLOW CHANNEL
      </button>
    </div>


  renderFooter: ->

    return null  unless @props.messages

    { thread } = @props

    footerInnerComponent = if @channel 'isParticipant'
    then <ChatInputWidget ref='chatInputWidget' onSubmit={@bound 'onSubmit'} thread= {thread} enableSearch={yes} />
    else @renderFollowChannel()

    <footer className="PublicChatPane-footer">
      {footerInnerComponent}
    </footer>


  render: ->

    <ChatPane
      thread             = { @props.thread }
      className          = "PublicChatPane"
      messages           = { @props.messages }
      onSubmit           = { @bound 'onSubmit' }
      onLoadMore         = { @bound 'onLoadMore' }
      inviteOthers       = { @bound 'inviteOthers' }
      addIntegration     = { @bound 'addIntegration' }
      startCollaboration = { @bound 'startCollaboration' }
      showIntegrationTooltip = { @state.showIntegrationTooltip }
      showCollaborationTooltip = { @state.showCollaborationTooltip }
    >
      {@renderFooter()}
    </ChatPane>


<commit_msg>activity: don't add channel name to end of body when creating<commit_after>kd              = require 'kd'
React           = require 'kd-react'
immutable       = require 'immutable'
ActivityFlux    = require 'activity/flux'
ChatPane        = require 'activity/components/chatpane'
ChatInputFlux   = require 'activity/flux/chatinput'
ChatInputWidget = require 'activity/components/chatinputwidget'


module.exports = class PublicChatPane extends React.Component

  @defaultProps =
    thread   : immutable.Map()
    messages : immutable.List()
    padded   : no

  constructor: (props) ->

    super props

    @state =
      showIntegrationTooltip   : no
      showCollaborationTooltip : no


  channel: (key) -> @props.thread?.getIn ['channel', key]


  onSubmit: ({ value }) ->

    return  unless body = value

    ActivityFlux.actions.message.createMessage @channel('id'), body


  onLoadMore: ->

    return  unless @props.messages.size
    return  if @props.thread.getIn ['flags', 'isMessagesLoading']

    from = @props.messages.first().get('createdAt')
    kd.utils.defer => ActivityFlux.actions.message.loadMessages @channel('id'), { from }


  onFollowChannel: ->

    ActivityFlux.actions.channel.followChannel @channel 'id'


  startCollaboration: (event) ->

    kd.utils.stopDOMEvent event

    @setState showCollaborationTooltip: yes

    kd.utils.wait 2000, => @setState showCollaborationTooltip: no


  inviteOthers: (event) ->

    kd.utils.stopDOMEvent event

    chatInputWidget = @refs.chatInputWidget
    textInput = React.findDOMNode chatInputWidget.refs.textInput
    textInput.focus()

    ChatInputFlux.actions.value.setValue @props.thread.get('channelId'), '/invite @'


  addIntegration: (event) ->

    kd.utils.stopDOMEvent event

    @setState showIntegrationTooltip: yes

    kd.utils.wait 2000, => @setState showIntegrationTooltip: no


  renderFollowChannel: ->

    <div className="PublicChatPane-subscribeContainer">
      YOU NEED TO FOLLOW THIS CHANNEL TO JOIN THE CONVERSATION
      <button
        ref       = "button"
        className = "Button Button-followChannel"
        onClick   = { @bound 'onFollowChannel' }>
          FOLLOW CHANNEL
      </button>
    </div>


  renderFooter: ->

    return null  unless @props.messages

    { thread } = @props

    footerInnerComponent = if @channel 'isParticipant'
    then <ChatInputWidget ref='chatInputWidget' onSubmit={@bound 'onSubmit'} thread= {thread} enableSearch={yes} />
    else @renderFollowChannel()

    <footer className="PublicChatPane-footer">
      {footerInnerComponent}
    </footer>


  render: ->

    <ChatPane
      thread             = { @props.thread }
      className          = "PublicChatPane"
      messages           = { @props.messages }
      onSubmit           = { @bound 'onSubmit' }
      onLoadMore         = { @bound 'onLoadMore' }
      inviteOthers       = { @bound 'inviteOthers' }
      addIntegration     = { @bound 'addIntegration' }
      startCollaboration = { @bound 'startCollaboration' }
      showIntegrationTooltip = { @state.showIntegrationTooltip }
      showCollaborationTooltip = { @state.showCollaborationTooltip }
    >
      {@renderFooter()}
    </ChatPane>



{'fraction_non_alphanumeric': 0.10992413686329153, 'fraction_numerical': 0.002477163647623471, 'mean_word_length': 2.8682634730538923, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 49, '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': '3869295', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1873, 'n_words': 402}