<commit_before>class StatusActivityItemView extends ActivityItemChild
  constructor:(options = {}, data={})->
    options.cssClass or= "activity-item status"
    options.tooltip  or=
      title            : "Status Update"
      selector         : "span.type-icon"
      offset           :
        top            : 3
        left           : -5

    super options, data

    embedOptions  =
      hasDropdown : no
      delegate    : this

    if data.link?
      @embedBox = new EmbedBox embedOptions, data.link
      @setClass "two-columns"  if @twoColumns
    else
      @embedBox = new KDView

    @timeAgoView = new KDTimeAgoView {}, @getData().meta.createdAt

  getTokenMap: (tokens) ->
    return  unless tokens
    map = {}
    tokens.forEach (token) -> map[token.getId()] = token
    return  map

  expandTokens: (str = "") ->
    return  str unless tokenMatches = str.match /\|.+?\|/g

    data = @getData()
    tagMap = @getTokenMap data.tags  if data.tags

    for tokenString in tokenMatches
      [prefix, constructorName, id] = @decodeToken tokenString

      switch prefix
        when "#" then token = tagMap?[id]
        else continue

      continue  unless token

      domId     = @utils.getUniqueId()
      itemClass = tokenClassMap[prefix]
      tokenView = new TokenView {domId, itemClass}, token
      tokenView.emit "viewAppended"

      str = str.replace tokenString, tokenView.getElement().outerHTML

    return  str

  decodeToken: (str) ->
    return  match[1].split /:/g  if match = str.match /^\|(.+)\|$/

  formatContent: (str = "")->
    str = @utils.applyMarkdown str
    str = @expandTokens str
    return  str

  viewAppended:->
    return if @getData().constructor is KD.remote.api.CStatusActivity
    super
    @setTemplate @pistachio()
    @template.update()

    @utils.defer =>
      predicate = @getData().link?.link_url? and @getData().link.link_url isnt ''
      if predicate
      then @embedBox.show()
      else @embedBox.hide()

  pistachio:->
    """
      {{> @avatar}}
      {{> @settingsButton}}
      {{> @author}}<commit_msg>resurrection.activity: defer actual TokenView instantiation procedures<commit_after>class StatusActivityItemView extends ActivityItemChild
  constructor:(options = {}, data={})->
    options.cssClass or= "activity-item status"
    options.tooltip  or=
      title            : "Status Update"
      selector         : "span.type-icon"
      offset           :
        top            : 3
        left           : -5

    super options, data

    embedOptions  =
      hasDropdown : no
      delegate    : this

    if data.link?
      @embedBox = new EmbedBox embedOptions, data.link
      @setClass "two-columns"  if @twoColumns
    else
      @embedBox = new KDView

    @timeAgoView = new KDTimeAgoView {}, @getData().meta.createdAt

  getTokenMap: (tokens) ->
    return  unless tokens
    map = {}
    tokens.forEach (token) -> map[token.getId()] = token
    return  map

  expandTokens: (str = "") ->
    return  str unless tokenMatches = str.match /\|.+?\|/g

    data = @getData()
    tagMap = @getTokenMap data.tags  if data.tags

    viewParams = []
    for tokenString in tokenMatches
      [prefix, constructorName, id] = @decodeToken tokenString

      switch prefix
        when "#" then token = tagMap?[id]
        else continue

      continue  unless token

      domId     = @utils.getUniqueId()
      itemClass = tokenClassMap[prefix]
      tokenView = new TokenView {domId, itemClass}, token
      tokenView.emit "viewAppended"
      str = str.replace tokenString, tokenView.getElement().outerHTML
      tokenView.destroy()

      viewParams.push {options: {domId, itemClass}, data: token}

    @utils.defer ->
      for {options, data} in viewParams
        new TokenView options, data

    return  str

  decodeToken: (str) ->
    return  match[1].split /:/g  if match = str.match /^\|(.+)\|$/

  formatContent: (str = "")->
    str = @utils.applyMarkdown str
    str = @expandTokens str
    return  str

  viewAppended:->
    return if @getData().constructor is KD.remote.api.CStatusActivity
    super
    @setTemplate @pistachio()
    @template.update()

    @utils.defer =>
      predicate = @getData().link?.link_url? and @getData().link.link_url isnt ''
      if predicate
      then @embedBox.show()
      else @embedBox.hide()

  pistachio:->
    """
      {{> @avatar}}
      {{> @settingsButton}}
      {{> @author}}
{'fraction_non_alphanumeric': 0.1185904675852722, 'fraction_numerical': 0.0013553196295459679, 'mean_word_length': 2.31685393258427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '982370', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1316, 'n_words': 338}