<commit_before>class Cloudsdale.Views.CloudsChatMessage extends Backbone.View

  template: JST['clouds/chat/message']

  model: 'message'
  tagName: 'div'
  className: 'chat-message'

  initialize: ->
    @render()
    @bindEvents()

  render: ->
    $(@el).html(@template(model: @model))
    .addClass("role-#{@model.user().get('role')}")
    .addClass("device-#{@model.get('device')}")
    .addClass("status-#{@model.user().get('status')}")

    if @model.get('author_id') == @model.topic().get('owner_id')
      $(@el).addClass("role-owner")

    if _.include(@model.topic().get('moderator_ids'), @model.get('author_id')) and @model.get('author_id') != @model.topic().get('owner_id')
      $(@el).addClass("role-mod")

    @.$('.chat-message-avatar > a, .chat-message-head > a').attr('data-entity-id',@model.user().id).attr('data-action',"showUser")

    @appendContent(@model)
    @appendDrops(@model)

    $(@el).addClass('self-reference') if @model.selfReference()

    this

  bindEvents: ->
    @model.user().on 'change', (event,user) =>
      @refreshGfx()

  refreshGfx: ->
    $(@el).removeClass('status-away').removeClass('status-busy')
    .removeClass('status-online').removeClass('status-offline')

    $(@el).addClass("status-#{@model.user().get('status')}")

    @.$('.chat-message-avatar a img').attr('src',@model.user().get('avatar').thumb)
    @.$('.chat-message-head a').text(@model.user().get('name'))
    if @.$('ul.chat-message-drops').children().length > 0
      $(@el).addClass('chat-message-with-drops')

  # Appends content to the message
  appendContent: (message) ->

    content = message.get('content')
    content = escapeHTML(content).autoLink({ target: "_blank", rel: 'safe' })

    content = content + "\\n"

    # Tab fix
    content = content.replace(/\\t/ig,"&nbsp;&nbsp;&nbsp;&nbsp;")

    # Greentext
    content = content.replace(/((^&gt;|\\n&gt;)[\w\d\s\!\'\"\'\.\,\-\_\/\?\:\&\^\<\>\=\#\%\+\*\~\\√\◊\(\)\[\]\{\}]*\\n)/ig,"<span style='color: green;'>$1</span>")

    elem = $("<p></p>")

    if message.selfReference()
      content = content.replace(/\\n$/ig,"").replace(/\\n/ig," ")
      content = content.replace(/^\/me/i,message.user().get('name'))
      elem.html(content)
    else
      content = content.replace(/\\n$/ig,"").replace(/\\n/ig,"<br/>")
      elem.html(content)

    @.$('.chat-message-content').append(elem)
    @.$('.chat-message-meta').text(message.timestamp().toString('HH:mm:ss'))

  appendDrops: (message) ->
    message.drops().each (drop) =>
      view = new Cloudsdale.Views.CloudsDropsListItem(model: drop)
      @.$('ul.chat-message-drops').append(view.el)<commit_msg>I feel the need to emphasise redacted content.<commit_after>class Cloudsdale.Views.CloudsChatMessage extends Backbone.View

  template: JST['clouds/chat/message']

  model: 'message'
  tagName: 'div'
  className: 'chat-message'

  initialize: ->
    @render()
    @bindEvents()

  render: ->
    $(@el).html(@template(model: @model))
    .addClass("role-#{@model.user().get('role')}")
    .addClass("device-#{@model.get('device')}")
    .addClass("status-#{@model.user().get('status')}")

    if @model.get('author_id') == @model.topic().get('owner_id')
      $(@el).addClass("role-owner")

    if _.include(@model.topic().get('moderator_ids'), @model.get('author_id')) and @model.get('author_id') != @model.topic().get('owner_id')
      $(@el).addClass("role-mod")

    @.$('.chat-message-avatar > a, .chat-message-head > a').attr('data-entity-id',@model.user().id).attr('data-action',"showUser")

    @appendContent(@model)
    @appendDrops(@model)

    $(@el).addClass('self-reference') if @model.selfReference()

    this

  bindEvents: ->
    @model.user().on 'change', (event,user) =>
      @refreshGfx()

  refreshGfx: ->
    $(@el).removeClass('status-away').removeClass('status-busy')
    .removeClass('status-online').removeClass('status-offline')

    $(@el).addClass("status-#{@model.user().get('status')}")

    @.$('.chat-message-avatar a img').attr('src',@model.user().get('avatar').thumb)
    @.$('.chat-message-head a').text(@model.user().get('name'))
    if @.$('ul.chat-message-drops').children().length > 0
      $(@el).addClass('chat-message-with-drops')

  # Appends content to the message
  appendContent: (message) ->

    content = message.get('content')
    content = escapeHTML(content).autoLink({ target: "_blank", rel: 'safe' })

    content = content + "\\n"

    # Tab fix
    content = content.replace(/\\t/ig,"&nbsp;&nbsp;&nbsp;&nbsp;")

    # Greentext
    content = content.replace(/((^&gt;|\\n&gt;)[\w\d\s\!\'\"\'\.\,\-\_\/\?\:\&\^\<\>\=\#\%\+\*\~\\√\◊\(\)\[\]\{\}]*\\n)/ig,"<span style='color: green;'>$1</span>")

    # Redacted
    content = content.replace(/(\[REDACTED\])/ig,"<span style='color: red; font-weight: bold;'>[REDACTED]</span>")

    elem = $("<p></p>")

    if message.selfReference()
      content = content.replace(/\\n$/ig,"").replace(/\\n/ig," ")
      content = content.replace(/^\/me/i,message.user().get('name'))
      elem.html(content)
    else
      content = content.replace(/\\n$/ig,"").replace(/\\n/ig,"<br/>")
      elem.html(content)

    @.$('.chat-message-content').append(elem)
    @.$('.chat-message-meta').text(message.timestamp().toString('HH:mm:ss'))

  appendDrops: (message) ->
    message.drops().each (drop) =>
      view = new Cloudsdale.Views.CloudsDropsListItem(model: drop)
      @.$('ul.chat-message-drops').append(view.el)
{'fraction_non_alphanumeric': 0.25705903923725704, 'fraction_numerical': 0.0007334066740007334, 'mean_word_length': 3.5458333333333334, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 39, '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': '3399487', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1889, 'n_words': 235}