<commit_before>class Activity12345 extends AppController

  constructor:(options={})->
    options.view = new KDView cssClass : "content-page activity"
    super options
    CodeSnippetView.on 'CodeSnippetWantsSave', (data)=>
      @saveCodeSnippet data.title, Encoder.htmlDecode data.content

    @currentFilter = [
      'CStatusActivity'
      'CCodeSnipActivity'
      'CDiscussionActivity'
      'CFollowerBucketActivity'
      'CNewMemberBucketActivity'
      # 'COpinionActivity'
      # THIS WILL DISABLE CODE SHARES
      # 'CCodeShareActivity'
      'CInstallerBucketActivity'
    ]

  saveCodeSnippet:(title, content)->
    # This custom method is used because FS,
    # command, environment are all a mess and
    # devrim is currently working on refactoring them - 3/15/12 sah

    # i kind of cleared that mess, still needs work - 26 April 2012 sinan
    if KD.isLoggedIn()
      @getSingleton('fs').saveToDefaultCodeSnippetFolder '"' + title + '"', content, (error, safeName)->
        if error
          new KDNotificationView
            title    : "Saving the snippet failed with error: #{error}"
            duration : 2500
            type     : 'mini'
        else
          nonEscapedName = safeName.replace /"(.*)"$/, '$1'
          new KDNotificationView
            title    : "Code snippet saved to: #{nonEscapedName}"
            duration : 2500
            type     : 'mini'
    else
      new KDNotificationView
        title    : "Please login!"
        type     : 'mini'
        duration : 2500

  bringToFront:()->
    super name : 'Activity'

  initAndBringToFront:(options,callback)->
    @environment = options.environment
    super

  loadView:(mainView)->

    mainController = @getSingleton('mainController')
    account        = KD.whoami()

    unless localStorage.welcomeMessageClosed?
      mainView.addSubView header = new WelcomeHeader
        type      : "big"
        title     : if KD.isLoggedIn() then "Hi #{account.profile.firstName}! Welcome to the Koding Public Beta." else "Welcome to the Koding Public Beta!"
        subtitle  : ""

    unless account instanceof KD.remote.api.JGuest
        # subtitle : "Last login #{$.timeago new Date account.meta.modifiedAt}
        # ... where have you been?!" # not relevant for now

      mainView.addSubView updateWidget = new ActivityUpdateWidget
        cssClass: 'activity-update-widget-wrapper'

      updateWidgetController = new ActivityUpdateWidgetController
        view : updateWidget

      updateWidgetController.registerListener
        KDEventTypes  : "OwnActivityHasArrived"
        listener      : @
        callback      : (pubInst,activity)=>
          @ownActivityArrived activity

    # mainView.addSubView new CommonFeedMessage
    #   title           : "<p> Since you're new to Koding, so we've prepared these helper boxes to introduce you to the system. This is your Activity Feed. It displays posts from the people and topics you follow on Koding. It's also the central place for sharing updates, code, links, discussions and questions with the community.</p>"
    #   messageLocation : 'Activity'

    activityInnerNavigation = new ActivityInnerNavigation
    @activityTabView = new KDTabView
      cssClass : "maincontent-tabs feeder-tabs"
    @activityTabView.hideHandleContainer()

    activitySplitView = @activitySplitView = new ActivitySplitView
      views     : [activityInnerNavigation,@activityTabView]
      sizes     : [139,null]
      minimums  : [10,null]
      resizable : no

    # ADD SPLITVIEW
    mainView.addSubView activitySplitView

    @createFollowedAndPublicTabs()

    # INITIAL HEIGHT SET FOR SPLIT
    @utils.wait 1000, =>
      # activitySplitView._windowDidResize()
      mainView.notifyResizeListeners()

    loadIfMoreItemsIsNecessary = =>
      if @activityListController.scrollView.getScrollHeight() <= @activityListController.scrollView.getHeight()
        @continueLoadingTeasers()

    @filter 'public', loadIfMoreItemsIsNecessary

    @getSingleton('activityController').on 'ActivitiesArrived', (activities)=>
      for activity in activities when activity.constructor.name in @currentFilter
        @activityListController.newActivityArrived activity

    activityInnerNavigation.registerListener
      KDEventTypes  : "CommonInnerNavigationListItemReceivedClick"
      listener      : @
      callback      : (pubInst, data)=>
        @filter data.type, loadIfMoreItemsIsNecessary

  ownActivityArrived:(activity)->
    @activityListController.ownActivityArrived activity

  createFollowedAndPublicTabs:->
    # FIRST TAB = FOLLOWED ACTIVITIES, SORT AND POST NEW
    @activityTabView.addPane followedTab = new KDTabPaneView
      cssClass : "activity-content"

    # SECOND TAB = ALL ACTIVITIES, SORT AND POST NEW
    @activityTabView.addPane allTab = new KDTabPaneView
      cssClass : "activity-content"

    @activityListController = activityListController = new ActivityListController
      delegate          : @
      lazyLoadThreshold : .75
      itemClass      : ActivityListItemView

    allTab.addSubView activityListScrollView = activityListController.getView()

    @activitySplitView.on "ViewResized", =>
      newHeight = @activitySplitView.getHeight() - 28 # HEIGHT OF THE HEADER
      activityListController.scrollView.setHeight newHeight

    controller = @

    activityListController.registerListener
      KDEventTypes  : 'LazyLoadThresholdReached'
      listener      : @
      callback      : => @continueLoadingTeasers()

  continueLoadingTeasers:->
    unless @activityListController.isLoading
      @activityListController.isLoading = yes
      @loadSomeTeasers =>
        @activityListController.isLoading = no
        @activityListController.hideLazyLoader()

  performFetchingTeasers:(type, selector, options, callback) ->
    if type is 'public'
      appManager.fetchStorage 'Activity', '1.0', (err, storage) =>
        if err
          log '>> error fetching app storage', err
        else
          options.collection = 'activities'
          flags = KD.whoami().globalFlags
          exempt = flags?.indexOf 'exempt'
          exempt = (exempt? and ~exempt) or storage.getAt 'bucket.showLowQualityContent'
          $.ajax KD.apiUri+'/1.0'
            data      :
              t       : if exempt then 1 else undefined
              data    : JSON.stringify(_.extend options, selector)
              env     : KD.config.env
            dataType  : 'jsonp'
            success   : (data) -> callback null, data

    else if type is 'private'
      KD.whoami().fetchFeeds (err, feeds) =>
        for feed in feeds
          continue unless feed.title is 'followed'
          feed.fetchActivities selector, options, (err, data) =>
            if err
              callback err
            else
              for datum in data
                datum.snapshot = datum.snapshot.replace /&quot;/g, '"'
              callback null, data
<commit_msg>Add hasFeed trait<commit_after>class Activity12345 extends AppController

  constructor:(options={})->
    options.view = new KDView cssClass : "content-page activity"
    super options
    CodeSnippetView.on 'CodeSnippetWantsSave', (data)=>
      @saveCodeSnippet data.title, Encoder.htmlDecode data.content

    @currentFilter = [
      'CStatusActivity'
      'CCodeSnipActivity'
      'CDiscussionActivity'
      'CFollowerBucketActivity'
      'CNewMemberBucketActivity'
      # 'COpinionActivity'
      # THIS WILL DISABLE CODE SHARES
      # 'CCodeShareActivity'
      'CInstallerBucketActivity'
    ]

  saveCodeSnippet:(title, content)->
    # This custom method is used because FS,
    # command, environment are all a mess and
    # devrim is currently working on refactoring them - 3/15/12 sah

    # i kind of cleared that mess, still needs work - 26 April 2012 sinan
    if KD.isLoggedIn()
      @getSingleton('fs').saveToDefaultCodeSnippetFolder '"' + title + '"', content, (error, safeName)->
        if error
          new KDNotificationView
            title    : "Saving the snippet failed with error: #{error}"
            duration : 2500
            type     : 'mini'
        else
          nonEscapedName = safeName.replace /"(.*)"$/, '$1'
          new KDNotificationView
            title    : "Code snippet saved to: #{nonEscapedName}"
            duration : 2500
            type     : 'mini'
    else
      new KDNotificationView
        title    : "Please login!"
        type     : 'mini'
        duration : 2500

  bringToFront:()->
    super name : 'Activity'

  initAndBringToFront:(options,callback)->
    @environment = options.environment
    super

  loadView:(mainView)->

    mainController = @getSingleton('mainController')
    account        = KD.whoami()

    unless localStorage.welcomeMessageClosed?
      mainView.addSubView header = new WelcomeHeader
        type      : "big"
        title     : if KD.isLoggedIn() then "Hi #{account.profile.firstName}! Welcome to the Koding Public Beta." else "Welcome to the Koding Public Beta!"
        subtitle  : ""

    unless account instanceof KD.remote.api.JGuest
        # subtitle : "Last login #{$.timeago new Date account.meta.modifiedAt}
        # ... where have you been?!" # not relevant for now

      mainView.addSubView updateWidget = new ActivityUpdateWidget
        cssClass: 'activity-update-widget-wrapper'

      updateWidgetController = new ActivityUpdateWidgetController
        view : updateWidget

      updateWidgetController.registerListener
        KDEventTypes  : "OwnActivityHasArrived"
        listener      : @
        callback      : (pubInst,activity)=>
          @ownActivityArrived activity

    # mainView.addSubView new CommonFeedMessage
    #   title           : "<p> Since you're new to Koding, so we've prepared these helper boxes to introduce you to the system. This is your Activity Feed. It displays posts from the people and topics you follow on Koding. It's also the central place for sharing updates, code, links, discussions and questions with the community.</p>"
    #   messageLocation : 'Activity'

    activityInnerNavigation = new ActivityInnerNavigation
    @activityTabView = new KDTabView
      cssClass : "maincontent-tabs feeder-tabs"
    @activityTabView.hideHandleContainer()

    activitySplitView = @activitySplitView = new ActivitySplitView
      views     : [activityInnerNavigation,@activityTabView]
      sizes     : [139,null]
      minimums  : [10,null]
      resizable : no

    # ADD SPLITVIEW
    mainView.addSubView activitySplitView

    @createFollowedAndPublicTabs()

    # INITIAL HEIGHT SET FOR SPLIT
    @utils.wait 1000, =>
      # activitySplitView._windowDidResize()
      mainView.notifyResizeListeners()

    loadIfMoreItemsIsNecessary = =>
      if @activityListController.scrollView.getScrollHeight() <= @activityListController.scrollView.getHeight()
        @continueLoadingTeasers()

    @filter 'public', loadIfMoreItemsIsNecessary

    @getSingleton('activityController').on 'ActivitiesArrived', (activities)=>
      for activity in activities when activity.constructor.name in @currentFilter
        @activityListController.newActivityArrived activity

    activityInnerNavigation.registerListener
      KDEventTypes  : "CommonInnerNavigationListItemReceivedClick"
      listener      : @
      callback      : (pubInst, data)=>
        @filter data.type, loadIfMoreItemsIsNecessary

  ownActivityArrived:(activity)->
    @activityListController.ownActivityArrived activity

  createFollowedAndPublicTabs:->
    # FIRST TAB = FOLLOWED ACTIVITIES, SORT AND POST NEW
    @activityTabView.addPane followedTab = new KDTabPaneView
      cssClass : "activity-content"

    # SECOND TAB = ALL ACTIVITIES, SORT AND POST NEW
    @activityTabView.addPane allTab = new KDTabPaneView
      cssClass : "activity-content"

    @activityListController = activityListController = new ActivityListController
      delegate          : @
      lazyLoadThreshold : .75
      itemClass      : ActivityListItemView

    allTab.addSubView activityListScrollView = activityListController.getView()

    @activitySplitView.on "ViewResized", =>
      newHeight = @activitySplitView.getHeight() - 28 # HEIGHT OF THE HEADER
      activityListController.scrollView.setHeight newHeight

    controller = @

    activityListController.registerListener
      KDEventTypes  : 'LazyLoadThresholdReached'
      listener      : @
      callback      : => @continueLoadingTeasers()

  continueLoadingTeasers:->
    unless @activityListController.isLoading
      @activityListController.isLoading = yes
      @loadSomeTeasers =>
        @activityListController.isLoading = no
        @activityListController.hideLazyLoader()

  performFetchingTeasers:(type, selector, options, callback) ->
    if type is 'public'
      appManager.fetchStorage 'Activity', '1.0', (err, storage) =>
        if err
          log '>> error fetching app storage', err
        else
          options.collection = 'activities'
          flags = KD.whoami().globalFlags
          exempt = flags?.indexOf 'exempt'
          exempt = (exempt? and ~exempt) or storage.getAt 'bucket.showLowQualityContent'
          $.ajax KD.apiUri+'/1.0'
            data      :
              t       : if exempt then 1 else undefined
              data    : JSON.stringify(_.extend options, selector)
              env     : KD.config.env
            dataType  : 'jsonp'
            success   : (data) -> callback null, data

    else if type is 'private'
      KD.whoami().getFeedByTitle "followed", (err, feed) ->
        feed.fetchActivities selector, options, (err, data) ->
          if err
            callback err
          else
            for datum in data
              datum.snapshot = datum.snapshot.replace /&quot;/g, '"'
            callback null, data

{'fraction_non_alphanumeric': 0.08323665893271462, 'fraction_numerical': 0.006815545243619489, 'mean_word_length': 2.6938939475093733, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, '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': '7152896', 'n_tokens_mistral': 3860, 'n_tokens_neox': 3612, 'n_words': 976}