<commit_before>class ActivityInputWidget extends KDView

  {daisy, dash} = Bongo

  constructor: (options = {}, data) ->
    options.cssClass = KD.utils.curry "activity-input-widget", options.cssClass
    options.destroyOnSubmit ?= no
    options.inputViewClass  ?= ActivityInputView

    super options, data

    @createSubViews()
    @initEvents()


  createSubViews: ->

    {defaultValue, placeholder, inputViewClass} = @getOptions()
    data = @getData()

    @input        = new inputViewClass {defaultValue, placeholder}
    @helperView   = new ActivityInputHelperView
    @embedBox     = new EmbedBoxWidget delegate: @input, data
    @icon         = new KDCustomHTMLView tagName : 'figure'

    @submitButton = new KDButtonView
      type        : "submit"
      title       : "SEND"
      cssClass    : "solid green small"
      loader      : yes
      attributes  :
        testpath  : "post-activity-button"
      callback    : => @submit @input.getValue()


    @buttonBar    = new KDCustomHTMLView
      cssClass    : "widget-button-bar"

    @previewIcon = new KDCustomHTMLView
      tagName    : "span"
      cssClass   : "preview-icon"
      tooltip    :
        title    : "Markdown preview"
      click      : =>
        if not @preview
        then @showPreview()
        else @hidePreview()


  initEvents: ->

    @input.on 'Escape', @bound 'reset'
    @input.on 'Enter',  @bound 'submit'

    @on 'SubmitStarted', => @hidePreview()  if @preview


  submit: (value) ->

    return  if @locked
    return @reset yes  unless body = value.trim()

    activity       = @getData()
    {app, channel} = @getOptions()
    payload        = @getPayload()

    timestamp       = Date.now()
    clientRequestId = KD.utils.generateFakeIdentifier timestamp
    channelId       = channel?.id

    @lockSubmit()

    options = { channelId, body, payload, clientRequestId }

    if activity
    then @update options, @bound 'submissionCallback'
    else @create options, @bound 'submissionCallback'

    @emit 'SubmitStarted', body, clientRequestId


  submissionCallback: (err, activity) ->

    if err
      @showError err
      @emit 'SubmitFailed', err, activity.clientRequestId
      return

    @emit 'SubmitSucceeded', activity

    KD.mixpanel "Status update create, success", { length: activity?.body?.length }


  create: (options, callback) ->

    {appManager} = KD.singletons<commit_msg>Activity: fixed an error thrown on submit failure /cc @usirin<commit_after>class ActivityInputWidget extends KDView

  {daisy, dash} = Bongo

  constructor: (options = {}, data) ->
    options.cssClass = KD.utils.curry "activity-input-widget", options.cssClass
    options.destroyOnSubmit ?= no
    options.inputViewClass  ?= ActivityInputView

    super options, data

    @createSubViews()
    @initEvents()


  createSubViews: ->

    {defaultValue, placeholder, inputViewClass} = @getOptions()
    data = @getData()

    @input        = new inputViewClass {defaultValue, placeholder}
    @helperView   = new ActivityInputHelperView
    @embedBox     = new EmbedBoxWidget delegate: @input, data
    @icon         = new KDCustomHTMLView tagName : 'figure'

    @submitButton = new KDButtonView
      type        : "submit"
      title       : "SEND"
      cssClass    : "solid green small"
      loader      : yes
      attributes  :
        testpath  : "post-activity-button"
      callback    : => @submit @input.getValue()


    @buttonBar    = new KDCustomHTMLView
      cssClass    : "widget-button-bar"

    @previewIcon = new KDCustomHTMLView
      tagName    : "span"
      cssClass   : "preview-icon"
      tooltip    :
        title    : "Markdown preview"
      click      : =>
        if not @preview
        then @showPreview()
        else @hidePreview()


  initEvents: ->

    @input.on 'Escape', @bound 'reset'
    @input.on 'Enter',  @bound 'submit'

    @on 'SubmitStarted', => @hidePreview()  if @preview


  submit: (value) ->

    return  if @locked
    return @reset yes  unless body = value.trim()

    activity       = @getData()
    {app, channel} = @getOptions()
    payload        = @getPayload()

    timestamp       = Date.now()
    clientRequestId = KD.utils.generateFakeIdentifier timestamp
    channelId       = channel?.id

    @lockSubmit()

    options = { channelId, body, payload, clientRequestId }

    if activity
    then @update options, @bound 'submissionCallback'
    else @create options, @bound 'submissionCallback'

    @emit 'SubmitStarted', body, clientRequestId


  submissionCallback: (err, activity) ->

    if err
      @showError err
      @emit 'SubmitFailed', err, activity.clientRequestId  if activity
      return

    @emit 'SubmitSucceeded', activity

    KD.mixpanel "Status update create, success", { length: activity?.body?.length }


  create: (options, callback) ->

    {appManager} = KD.singletons
{'fraction_non_alphanumeric': 0.10531718332991172, 'fraction_numerical': 0.0, 'mean_word_length': 2.566617862371889, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '521097', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1377, 'n_words': 370}