<commit_before>class Kandan.Views.Chatbox extends Backbone.View

  template:  JST['chatbox']
  tagName:   'div'
  className: 'chatbox'


  events:
    "keypress .chat-input": 'postMessageOnEnter'
    "click    .post"      : 'postMessage'


  postMessageOnEnter: (event)->
    if event.keyCode == 13
      @postMessage(event)
      event.preventDefault()


  postMessage: (event)->
    $chatbox = $(event.target).parent().find(".chat-input")
    chatInput = $chatbox.val()
    return false if chatInput.trim().length==0

    activity = new Kandan.Models.Activity({
      'content':    chatInput,
      'action':     'message',
      'channel_id': @channel.get('id')
    })

    $chatbox.val("")
    Kandan.Helpers.Channels.addActivity(
      _.extend(activity.toJSON(), {cid: activity.cid, user: Kandan.Data.Users.currentUser()}, created_at: new Date()),
      Kandan.Helpers.Activities.ACTIVE_STATE,
      true
    )

    activity.save({},{success: (model, response)->
      $("#activity-c#{model.cid}").attr("id", "activity-#{model.get('id')}")
    })

  render: ()->
    @channel = @options.channel
    $(@el).html(@template())
    @<commit_msg>better scrolling in chat rooms<commit_after>class Kandan.Views.Chatbox extends Backbone.View

  template:  JST['chatbox']
  tagName:   'div'
  className: 'chatbox'


  events:
    "keypress .chat-input": 'postMessageOnEnter'
    "click    .post"      : 'postMessage'


  postMessageOnEnter: (event)->
    if event.keyCode == 13
      @postMessage(event)
      event.preventDefault()


  postMessage: (event)->
    $chatbox = $(event.target).parent().find(".chat-input")
    chatInput = $chatbox.val()
    return false if chatInput.trim().length==0

    activity = new Kandan.Models.Activity({
      'content':    chatInput,
      'action':     'message',
      'channel_id': @channel.get('id')
    })

    $chatbox.val("")
    Kandan.Helpers.Channels.addActivity(
      _.extend(activity.toJSON(), {cid: activity.cid, user: Kandan.Data.Users.currentUser()}, created_at: new Date()),
      Kandan.Helpers.Activities.ACTIVE_STATE,
      true
    )

    activity.save({},{success: (model, response)->
      $("#activity-c#{model.cid}").attr("id", "activity-#{model.get('id')}")
      $scrollbox = $(event.target).parent().find(".paginated-activities")
      $scrollbox.prop("scrollTop", $scrollbox.prop('scrollHeight'))
    })

  render: ()->
    @channel = @options.channel
    $(@el).html(@template())
    @
{'fraction_non_alphanumeric': 0.17733387688544638, 'fraction_numerical': 0.0024459845087647777, 'mean_word_length': 3.180579216354344, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '3398017', 'n_tokens_mistral': 814, 'n_tokens_neox': 807, 'n_words': 136}