<commit_before>class MembersAppController extends AppController

  KD.registerAppClass this,
    name         : "Members"
    routes       :
      "/:name?/Members" : ({params, query}) ->
        {router, appManager} = KD.singletons
        KD.getSingleton('groupsController').ready ->
          group = KD.getGroup()
          KD.getSingleton("appManager").tell 'Members', 'createContentDisplay', group, (contentDisplay) ->
            contentDisplay.emit "handleQuery", {filter: "members"}

    hiddenHandle : yes

  {externalProfiles} = KD.config

  constructor:(options = {}, data)->
    options.view    = new KDView
      cssClass      : 'content-page members'
    options.appInfo =
      name          : 'Members'

    @appManager = KD.getSingleton "appManager"

    super options, data


  createContentDisplay:(model, callback=->)->
    KD.singletons.appManager.setFrontApp this
    {JAccount} = KD.remote.api
    type = if model instanceof JAccount then "profile" else "members"

    contentDisplay = new KDView
      cssClass : 'member content-display'
      type     : type

    contentDisplay.on 'handleQuery', (query)=>
      @ready => @feedController?.handleQuery? query

    contentDisplay.once 'KDObjectWillBeDestroyed', ->
      KD.singleton('appManager').tell 'Activity', 'resetProfileLastTo'

    KD.getSingleton('groupsController').ready =>
      contentDisplay.$('div.lazy').remove()
      if type is "profile"
        @createProfileView contentDisplay, model
      else
        @createGroupMembersView contentDisplay
      @showContentDisplay contentDisplay
      @utils.defer -> callback contentDisplay

  createProfileView: (contentDisplay, model)->
    @prepareProfileView model, (profileView)=>
      contentDisplay.addSubView profileView
      @prepareFeederView model, (feederView)->
        contentDisplay.addSubView feederView
        contentDisplay.setCss minHeight : window.innerHeight

  createGroupMembersView: (contentDisplay)->
    contentDisplay.addSubView new HeaderViewSection
      title    : "Members"
      type     : "big"
    @prepareFeederView KD.whoami(), (feederView)->
      contentDisplay.addSubView feederView
      contentDisplay.setCss minHeight : window.innerHeight

  prepareFeederView:(account, callback)->
    windowController = KD.getSingleton('windowController')

    if KD.isMine account
      owner   = "you"
      auxVerb =
        have : "have"
        be   : "are"
    else
      owner = KD.utils.getFullnameFromAccount account
      auxVerb =
        have : "has"
        be   : "is"

    KD.getSingleton("appManager").tell 'Feeder', 'createContentFeedController', {
      itemClass             : ActivityListItemView
      listControllerClass   : MemberActivityListController
      listCssClass          : "activity-related"
      limitPerPage          : 8
      useHeaderNav          : yes
      delegate              : this
      creator               : account
      filter                :
        statuses            :
          noItemFoundText   : "#{owner} #{auxVerb.have} not shared any posts yet."
          dataSource        : (selector, options = {}, callback)=>
            options.originId = account.getId()
            KD.getSingleton("appManager").tell 'Activity', 'fetchActivitiesProfilePage', options, callback
        followers           :
          loggedInOnly      : yes
          itemClass         : GroupMembersPageListItemView
          listControllerClass: MembersListViewController
          listCssClass      : "member-related"
          noItemFoundText   : "No one is following #{owner} yet."
          dataSource        : (selector, options, callback)=>
            options.groupId or= KD.getGroup().getId()
            account.fetchFollowersWithRelationship selector, options, callback
        following           :
          loggedInOnly      : yes
          itemClass         : GroupMembersPageListItemView
          listControllerClass: MembersListViewController
          listCssClass      : "member-related"
          noItemFoundText   : "#{owner} #{auxVerb.be} not following anyone."
          dataSource        : (selector, options, callback)=>
            options.groupId or= KD.getGroup().getId()
            account.fetchFollowingWithRelationship selector, options, callback
        likes               :
          loggedInOnly      : yes
          noItemFoundText   : "#{owner} #{auxVerb.have} not liked any posts yet."
          dataSource        : (selector, options, callback)->
            selector = {sourceName: $in: ['JNewStatusUpdate']}
            account.fetchLikedContents options, selector, callback
        members              :
          noItemFoundText    : "There is no member."
          itemClass          : GroupMembersPageListItemView
          listControllerClass: MembersListViewController
          listCssClass       : "member-related"
          title              : ""
          dataSource         : (selector, options, callback)=>
            group = KD.getGroup()
            group.fetchMembers selector, options, (err, res)=>
              KD.mixpanel "Load member list, success"  unless err
              callback err, res

      sort                  :
        'modifiedAt'        :
          title             : "Latest activity"
          direction         : -1
        'counts.followers'  :
          title             : "Most followers"
          direction         : -1
        'counts.following'  :<commit_msg>Profile: Prevented "Load member list, success" event to be sent to mixpanel with each lazyload<commit_after>class MembersAppController extends AppController

  KD.registerAppClass this,
    name         : "Members"
    routes       :
      "/:name?/Members" : ({params, query}) ->
        {router, appManager} = KD.singletons
        KD.getSingleton('groupsController').ready ->
          group = KD.getGroup()
          KD.getSingleton("appManager").tell 'Members', 'createContentDisplay', group, (contentDisplay) ->
            contentDisplay.emit "handleQuery", {filter: "members"}

    hiddenHandle : yes

  {externalProfiles} = KD.config

  constructor:(options = {}, data)->
    options.view    = new KDView
      cssClass      : 'content-page members'
    options.appInfo =
      name          : 'Members'

    @appManager = KD.getSingleton "appManager"

    super options, data

    @once "MemberListLoaded", ->
      KD.mixpanel "Load member list, success"

  createContentDisplay:(model, callback=->)->
    KD.singletons.appManager.setFrontApp this
    {JAccount} = KD.remote.api
    type = if model instanceof JAccount then "profile" else "members"

    contentDisplay = new KDView
      cssClass : 'member content-display'
      type     : type

    contentDisplay.on 'handleQuery', (query)=>
      @ready => @feedController?.handleQuery? query

    contentDisplay.once 'KDObjectWillBeDestroyed', ->
      KD.singleton('appManager').tell 'Activity', 'resetProfileLastTo'

    KD.getSingleton('groupsController').ready =>
      contentDisplay.$('div.lazy').remove()
      if type is "profile"
        @createProfileView contentDisplay, model
      else
        @createGroupMembersView contentDisplay
      @showContentDisplay contentDisplay
      @utils.defer -> callback contentDisplay

  createProfileView: (contentDisplay, model)->
    @prepareProfileView model, (profileView)=>
      contentDisplay.addSubView profileView
      @prepareFeederView model, (feederView)->
        contentDisplay.addSubView feederView
        contentDisplay.setCss minHeight : window.innerHeight

  createGroupMembersView: (contentDisplay)->
    contentDisplay.addSubView new HeaderViewSection
      title    : "Members"
      type     : "big"
    @prepareFeederView KD.whoami(), (feederView)->
      contentDisplay.addSubView feederView
      contentDisplay.setCss minHeight : window.innerHeight

  prepareFeederView:(account, callback)->
    windowController = KD.getSingleton('windowController')

    if KD.isMine account
      owner   = "you"
      auxVerb =
        have : "have"
        be   : "are"
    else
      owner = KD.utils.getFullnameFromAccount account
      auxVerb =
        have : "has"
        be   : "is"

    KD.getSingleton("appManager").tell 'Feeder', 'createContentFeedController', {
      itemClass             : ActivityListItemView
      listControllerClass   : MemberActivityListController
      listCssClass          : "activity-related"
      limitPerPage          : 8
      useHeaderNav          : yes
      delegate              : this
      creator               : account
      filter                :
        statuses            :
          noItemFoundText   : "#{owner} #{auxVerb.have} not shared any posts yet."
          dataSource        : (selector, options = {}, callback)=>
            options.originId = account.getId()
            KD.getSingleton("appManager").tell 'Activity', 'fetchActivitiesProfilePage', options, callback
        followers           :
          loggedInOnly      : yes
          itemClass         : GroupMembersPageListItemView
          listControllerClass: MembersListViewController
          listCssClass      : "member-related"
          noItemFoundText   : "No one is following #{owner} yet."
          dataSource        : (selector, options, callback)=>
            options.groupId or= KD.getGroup().getId()
            account.fetchFollowersWithRelationship selector, options, callback
        following           :
          loggedInOnly      : yes
          itemClass         : GroupMembersPageListItemView
          listControllerClass: MembersListViewController
          listCssClass      : "member-related"
          noItemFoundText   : "#{owner} #{auxVerb.be} not following anyone."
          dataSource        : (selector, options, callback)=>
            options.groupId or= KD.getGroup().getId()
            account.fetchFollowingWithRelationship selector, options, callback
        likes               :
          loggedInOnly      : yes
          noItemFoundText   : "#{owner} #{auxVerb.have} not liked any posts yet."
          dataSource        : (selector, options, callback)->
            selector = {sourceName: $in: ['JNewStatusUpdate']}
            account.fetchLikedContents options, selector, callback
        members              :
          noItemFoundText    : "There is no member."
          itemClass          : GroupMembersPageListItemView
          listControllerClass: MembersListViewController
          listCssClass       : "member-related"
          title              : ""
          dataSource         : (selector, options, callback)=>
            group = KD.getGroup()
            group.fetchMembers selector, options, (err, res)=>
              @emit "MemberListLoaded"  unless err
              callback err, res

      sort                  :
        'modifiedAt'        :
          title             : "Latest activity"
          direction         : -1
        'counts.followers'  :
          title             : "Most followers"
          direction         : -1
        'counts.following'  :
{'fraction_non_alphanumeric': 0.09041542221015476, 'fraction_numerical': 0.0005430355688297583, 'mean_word_length': 2.104804720427086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, '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': '7138628', 'n_tokens_mistral': 2866, 'n_tokens_neox': 2760, 'n_words': 652}