<commit_before>class NotificationListItemView extends KDListItemView

  JView.mixin @prototype

  activityNameMap =
    comment : "status."
    like    : "status."
    follow  : "started following you."
    join    : "your group"
    leave   : "your group"
    mention : "status."

  actionPhraseMap =
    comment  : "commented on"
    reply    : "replied to"
    like     : "liked"
    follow   : ""
    share    : "shared"
    commit   : "committed"
    member   : "joined"
    join     : "joined"
    leave    : "left"
    mention  : "mentioned you in"

  constructor:(options = {}, data)->
    options.tagName        or= "li"
    options.linkGroupClass or= LinkGroup
    options.avatarClass    or= AvatarView

    super options, data

    @participants = new KDCustomHTMLView
    @avatar = new KDCustomHTMLView

    # if @snapshot.anchor.constructorName is "JGroup"
    #   @interactedGroups = new options.linkGroupClass
    #     itemClass : GroupLinkView
    #     group     : [@snapshot.anchor.data]
    # else
    @interactedGroups = new KDCustomHTMLView

    @activityPlot = new KDCustomHTMLView tagName: "span"
    @timeAgoView  = new KDTimeAgoView null, @getLatestTimeStamp @getData().dummy


    @initializeReadState()

  initializeReadState:->
    if @getData().glanced
    then @unsetClass 'unread'
    else @setClass 'unread'

  fetchActors: ->
    @actors = []
    options = @getOptions()
    {latestActors} = @getData()
    promises = latestActors.map (actorId) =>
      new Promise (resolve, reject) =>
        KD.remote.api.JAccount.one _id: actorId, (err, actor) =>
          return reject err  if err
          @actors.push actor
          resolve()

    Promise.all(promises).then =>
      @participants = new options.linkGroupClass {group:@actors}
      @avatar       = new options.avatarClass
        size     :
          width  : 40
          height : 40
        origin   : @actors[0]

    .catch (err) ->
      warn err.description

  viewAppended: ->
    promises = []
    promises.push @fetchActors()
    promises.push @getActivityPlot()

    Promise.all(promises).then =>
      @setTemplate @pistachio()
      @template.update()
    .catch (err) ->
      warn err.description

  pistachio:->
    """
      <div class='avatar-wrapper fl'>
        {{> @avatar}}
      </div>
      <div class='right-overflow'>
        <p>{{> @participants}} {{@getActionPhrase #(dummy)}} {{> @activityPlot}} {{> @interactedGroups}}</p>
        <footer>
          {{> @timeAgoView}}
        </footer>
      </div>
    """


  getLatestTimeStamp:->
    return @getData().updatedAt


  getActionPhrase:->
    {type} = @getData()
    actionPhraseMap[type]


  getActivityName:->
    return activityNameMap[@getData().type]

  getActivityPlot:->
    new Promise (resolve, reject)=>
      data = @getData()
      adjective = ""
      switch data.type
        when "comment", "like", "mention"
          {message} = KD.singletons.socialapi
          message.byId {id: data.targetId}, (err, message)=>
            return reject err  if err or not message
            KD.remote.api.JAccount.one _id: message.accountOldId, (err, origin)=>
              return reject err  if err or not origin

              adjective = if message.account._id is KD.whoami()?.getId() then "your"
              else if @actors.length == 1 and @actors[0].getId() is origin.getId() then "their own"
              else
                originatorName = KD.utils.getFullnameFromAccount origin
                "#{originatorName}'s"

              @activityPlot.updatePartial "#{adjective} #{@getActivityName()}"
              resolve()
        else
          @activityPlot.updatePartial "#{@getActivityName()}"
          resolve()



  click:->
    showPost = (err, post)->
      return warn err if err
      if post
        # TODO group slug must be prepended after groups are implemented
        # groupSlug = if post.group is "koding" then "" else "/#{post.group}"
        KD.getSingleton('router').handleRoute "/Activity/Post/#{post.slug}", state:post
      else
        new KDNotificationView
          title : "This post has been deleted!"<commit_msg>Notification: use cacheable for fetching account data<commit_after>class NotificationListItemView extends KDListItemView

  JView.mixin @prototype

  activityNameMap =
    comment : "status."
    like    : "status."
    follow  : "started following you."
    join    : "your group"
    leave   : "your group"
    mention : "status."

  actionPhraseMap =
    comment  : "commented on"
    reply    : "replied to"
    like     : "liked"
    follow   : ""
    share    : "shared"
    commit   : "committed"
    member   : "joined"
    join     : "joined"
    leave    : "left"
    mention  : "mentioned you in"

  constructor:(options = {}, data)->
    options.tagName        or= "li"
    options.linkGroupClass or= LinkGroup
    options.avatarClass    or= AvatarView

    super options, data

    @participants = new KDCustomHTMLView
    @avatar = new KDCustomHTMLView

    # if @snapshot.anchor.constructorName is "JGroup"
    #   @interactedGroups = new options.linkGroupClass
    #     itemClass : GroupLinkView
    #     group     : [@snapshot.anchor.data]
    # else
    @interactedGroups = new KDCustomHTMLView

    @activityPlot = new KDCustomHTMLView tagName: "span"
    @timeAgoView  = new KDTimeAgoView null, @getLatestTimeStamp @getData().dummy


    @initializeReadState()

  initializeReadState:->
    if @getData().glanced
    then @unsetClass 'unread'
    else @setClass 'unread'

  fetchActors: ->
    @actors = []
    options = @getOptions()
    {latestActors} = @getData()
    constructorName = 'JAccount'
    origins = latestActors.map (id) -> {id, constructorName}

    new Promise (resolve, reject) =>
      KD.remote.cacheable origins, (err, actors) =>
        return reject err if err?
        @actors = actors
        @participants = new options.linkGroupClass {group:actors}
        @avatar       = new options.avatarClass
          size     :
            width  : 40
            height : 40
          origin   : @actors[0]
        resolve()

  viewAppended: ->
    promises = []
    promises.push @fetchActors()
    promises.push @getActivityPlot()

    Promise.all(promises).then =>
      @setTemplate @pistachio()
      @template.update()
    .catch (err) ->
      warn err.description

  pistachio:->
    """
      <div class='avatar-wrapper fl'>
        {{> @avatar}}
      </div>
      <div class='right-overflow'>
        <p>{{> @participants}} {{@getActionPhrase #(dummy)}} {{> @activityPlot}} {{> @interactedGroups}}</p>
        <footer>
          {{> @timeAgoView}}
        </footer>
      </div>
    """


  getLatestTimeStamp:->
    return @getData().updatedAt


  getActionPhrase:->
    {type} = @getData()
    actionPhraseMap[type]


  getActivityName:->
    return activityNameMap[@getData().type]

  getActivityPlot:->
    new Promise (resolve, reject)=>
      data = @getData()
      adjective = ""
      switch data.type
        when "comment", "like", "mention"
          {message} = KD.singletons.socialapi
          message.byId {id: data.targetId}, (err, message)=>
            return reject err  if err or not message

            KD.remote.cacheable 'JAccount', message.account._id, (err, origin)=>
              return reject err  if err or not origin

              adjective = if message.account._id is KD.whoami()?.getId() then "your"
              else if @actors.length == 1 and @actors[0].getId() is origin.getId() then "their own"
              else
                originatorName = KD.utils.getFullnameFromAccount origin
                "#{originatorName}'s"

              @activityPlot.updatePartial "#{adjective} #{@getActivityName()}"
              resolve()
        else
          @activityPlot.updatePartial "#{@getActivityName()}"
          resolve()



  click:->
    showPost = (err, post)->
      return warn err if err
      if post
        # TODO group slug must be prepended after groups are implemented
        # groupSlug = if post.group is "koding" then "" else "/#{post.group}"
        KD.getSingleton('router').handleRoute "/Activity/Post/#{post.slug}", state:post
      else
        new KDNotificationView
          title : "This post has been deleted!"
{'fraction_non_alphanumeric': 0.120203365210023, 'fraction_numerical': 0.001694710083524997, 'mean_word_length': 2.2890127388535033, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 69, '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': '6536247', 'n_tokens_mistral': 2566, 'n_tokens_neox': 2447, 'n_words': 611}