<commit_before>class MessagePane extends KDTabPaneView

  constructor: (options = {}, data) ->

    options.type        or= ''
    options.cssClass      = "message-pane #{options.type}"
    options.wrapper      ?= yes
    options.lastToFirst  ?= no
    options.itemClass   or= ActivityListItemView

    super options, data

    @lastScrollTops =
      window        : 0
      parent        : 0
      self          : 0
      body          : 0

    {itemClass, lastToFirst, wrapper, channelId} = @getOptions()
    {typeConstant} = @getData()

    @listController = new ActivityListController {
      type          : typeConstant
      viewOptions   :
        itemOptions : {channelId}
      wrapper
      itemClass
      lastToFirst
    }

    @listController.getView().setClass 'padded'

    @createChannelTitle()
    @createInputWidget()
    @createFilterLinks()
    @bindInputEvents()

    @submitIsPending = no

    @fakeMessageMap = {}

    @setFilter @getDefaultFilter()

    {socialapi} = KD.singletons
    @once 'ChannelReady', @bound 'bindChannelEvents'
    socialapi.onChannelReady data, @lazyBound 'emit', 'ChannelReady'

    if typeConstant in ['group', 'topic', 'announcement']
      @on 'LazyLoadThresholdReached', @bound 'lazyLoad'

    KD.singletons.windowController.addFocusListener @bound 'handleFocus'

    switch typeConstant
      when 'post'
        @listController.getListView().once 'ItemWasAdded', (item) =>
          listView = @listController.getListItems().first.commentBox.controller.getListView()
          listView.on 'ItemWasAdded', @bound 'scrollDown'
      when 'privatemessage'
        @listController.getListView().on 'ItemWasAdded', @bound 'scrollDown'
      when 'group', 'announcement'
      else
        @listController.getListView().on 'ItemWasAdded', @bound 'scrollUp'


  bindInputEvents: ->

    return  unless @input

    @input
      .on 'SubmitStarted',    @bound 'handleEnter'
      .on 'SubmitStarted',    => @submitIsPending = yes
      .on 'SubmitSucceeded',  @bound 'replaceFakeItemView'
      .on 'SubmitSucceeded',  => KD.utils.defer => @submitIsPending = no
      .on 'SubmitFailed',     @bound 'messageSubmitFailed'

  whenSubmitted: ->
    new Promise (resolve) =>
      unless @submitIsPending
        resolve()
      else
        @input.once 'SubmitSucceeded', -> resolve()

  replaceFakeItemView: (message) ->
    @putMessage message, @removeFakeMessage message.clientRequestId<commit_msg>activity: latency compensation related race condition<commit_after>class MessagePane extends KDTabPaneView

  constructor: (options = {}, data) ->

    options.type        or= ''
    options.cssClass      = "message-pane #{options.type}"
    options.wrapper      ?= yes
    options.lastToFirst  ?= no
    options.itemClass   or= ActivityListItemView

    super options, data

    @lastScrollTops =
      window        : 0
      parent        : 0
      self          : 0
      body          : 0

    {itemClass, lastToFirst, wrapper, channelId} = @getOptions()
    {typeConstant} = @getData()

    @listController = new ActivityListController {
      type          : typeConstant
      viewOptions   :
        itemOptions : {channelId}
      wrapper
      itemClass
      lastToFirst
    }

    @listController.getView().setClass 'padded'

    @createChannelTitle()
    @createInputWidget()
    @createFilterLinks()
    @bindInputEvents()

    @submitIsPending = no

    @fakeMessageMap = {}

    @setFilter @getDefaultFilter()

    {socialapi} = KD.singletons
    @once 'ChannelReady', @bound 'bindChannelEvents'
    socialapi.onChannelReady data, @lazyBound 'emit', 'ChannelReady'

    if typeConstant in ['group', 'topic', 'announcement']
      @on 'LazyLoadThresholdReached', @bound 'lazyLoad'

    KD.singletons.windowController.addFocusListener @bound 'handleFocus'

    switch typeConstant
      when 'post'
        @listController.getListView().once 'ItemWasAdded', (item) =>
          listView = @listController.getListItems().first.commentBox.controller.getListView()
          listView.on 'ItemWasAdded', @bound 'scrollDown'
      when 'privatemessage'
        @listController.getListView().on 'ItemWasAdded', @bound 'scrollDown'
      when 'group', 'announcement'
      else
        @listController.getListView().on 'ItemWasAdded', @bound 'scrollUp'


  bindInputEvents: ->

    return  unless @input

    @input
      .on 'SubmitStarted',    => @submitIsPending = yes
      .on 'SubmitStarted',    @bound 'handleEnter'
      .on 'SubmitSucceeded',  @bound 'replaceFakeItemView'
      .on 'SubmitSucceeded',  => KD.utils.defer => @submitIsPending = no
      .on 'SubmitFailed',     @bound 'messageSubmitFailed'

  whenSubmitted: ->
    new Promise (resolve) =>
      unless @submitIsPending
        resolve()
      else
        @input.once 'SubmitSucceeded', -> resolve()

  replaceFakeItemView: (message) ->
    @putMessage message, @removeFakeMessage message.clientRequestId
{'fraction_non_alphanumeric': 0.10964734495338468, 'fraction_numerical': 0.0016214025131738954, 'mean_word_length': 2.8137557959814528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5518604', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1392, 'n_words': 312}