         exempt = (exempt? and ~exempt) or storage.getAt 'bucket.showLowQualityContent'
         callback exempt
 
+  constructor:(options={})->
+
+    options.view = new ActivityAppView
+
+    super options
+
+    @currentFilter = activityTypes
+    @appStorage = new AppStorage 'Activity', '1.0'
+    @getSingleton('activityController').on "ActivityListControllerReady", (controller)=>
+      @listControllerReady controller
+
+  bringToFront:()-> super name : 'Activity'
+
+  resetList:->
+
+    lastFrom = null
+    lastTo   = null
+    @listController.removeAllItems()
+
+  setFilter:(type) -> @currentFilter = if type? then [type] else activityTypes
+
+  getFilter: -> @currentFilter
+
+  listControllerReady:(controller)->
+
+    @listController    = controller
+    activityController = @getSingleton('activityController')
+
+    controller.on 'LazyLoadThresholdReached', @continueLoadingTeasers.bind @
+    controller.on 'teasersLoaded', @teasersLoaded.bind @
+
+    activityController.on "OwnActivityHasArrived", (activity)->
+      controller.ownActivityArrived activity
+
+    activityController.on 'ActivitiesArrived', (activities)=>
+      for activity in activities when activity.bongo_.constructorName in @getFilter()
+        controller.newActivityArrived activity
+
+    KD.whoami().on "FollowedActivityArrived", (activityId) =>
+      KD.remote.api.CActivity.one {_id: activityId}, (err, activity) =>
+        if activity.constructor.name in @getFilter()
+          activity.snapshot?.replace /&quot;/g, '"'
+          controller.followedActivityArrived activity
+
+    @getView().innerNav.on "NavItemReceivedClick", (data)=>
+      @resetList()
+      @setFilter data.type
+      @populateActivity()
+
+    @populateActivity()
+
+
+  populateActivity:(options = {})->
+
+    return if isLoading
+    isLoading = yes
+    @listController.showLazyLoader()
+
+    isExempt (exempt)=>
+
+      if exempt or @getFilter() isnt activityTypes
+
+        options = to : options.to or Date.now()
+
+        @fetchActivity options, (err, teasers)=>
+          if err then warn err
+          else
+            isLoading = no
+            @listController.listActivities teasers
+            @listController.hideLazyLoader()
+
+      else
+        @fetchCachedActivity options, (err, cache)=>
+          if err then warn err
+          else
+            @sanitizeCache cache, (err, cache)=>
+              @listController.listActivitiesFromCache cache
+              isLoading = no
+              @listController.hideLazyLoader()
+
   sanitizeCache:(cache, callback)->
 
     activities = clearQuotes cache.activities

  aRange    = 2*60*60*1000
  isLoading = no

  constructor:(options={})->

    options.view = new ActivityAppView

    super options

    @currentFilter = activityTypes
    @appStorage = new AppStorage 'Activity', '1.0'
    @getSingleton('activityController').on "ActivityListControllerReady", (controller)=>
      @listControllerReady controller

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

  resetList:->

    lastFrom = null
    lastTo   = null
    @listController.removeAllItems()

  setFilter:(type) -> @currentFilter = if type? then [type] else activityTypes

  getFilter: -> @currentFilter

  listControllerReady:(controller)->

    @listController    = controller
    activityController = @getSingleton('activityController')

    controller.on 'LazyLoadThresholdReached', @continueLoadingTeasers.bind @
    controller.on 'teasersLoaded', @teasersLoaded.bind @

    activityController.on "OwnActivityHasArrived", (activity)->
      controller.ownActivityArrived activity

    activityController.on 'ActivitiesArrived', (activities)=>
      for activity in activities when activity.bongo_.constructorName in @getFilter()
        controller.newActivityArrived activity

    KD.whoami().on "FollowedActivityArrived", (activityId) =>
      KD.remote.api.CActivity.one {_id: activityId}, (err, activity) =>
        if activity.constructor.name in @getFilter()
          activity.snapshot?.replace /&quot;/g, '"'
          controller.followedActivityArrived activity

    @getView().innerNav.on "NavItemReceivedClick", (data)=>
      @resetList()
      @setFilter data.type
      @populateActivity()

    @populateActivity()


  populateActivity:(options = {})->

    return if isLoading
    isLoading = yes
    @listController.showLazyLoader()

    if @getFilter() isnt activityTypes

      options = to : options.to or Date.now()

      @fetchActivity options, (err, teasers)=>
        if err then warn err
        else
          isLoading = no
          @listController.listActivities teasers
          @listController.hideLazyLoader()

    else
      @fetchCachedActivity options, (err, cache)=>
        if err then warn err
        else
          @sanitizeCache cache, (err, cache)=>
            @listController.listActivitiesFromCache cache
            isLoading = no
            @listController.hideLazyLoader()


  clearQuotes = (activities)->

    return activities = for activityId, activity of activities


        callback null, cache

  continueLoadingTeasers:->
    unless isLoading
      lastDate = new Date @listController.itemsOrdered.last.getData().meta.createdAt
      @populateActivity {slug : "before/#{lastDate.getTime()}"}

  teasersLoaded:->
    {scrollView} = @listController
    if scrollView.getScrollHeight() <= scrollView.getHeight()
      @continueLoadingTeasers()

  createContentDisplay:(activity)->
    switch activity.bongo_.constructorName
      when "JStatusUpdate" then @createStatusUpdateContentDisplay activity
      when "JCodeSnip"     then @createCodeSnippetContentDisplay activity
      when "JDiscussion"   then @createDiscussionContentDisplay activity
      when "JTutorial"     then @createTutorialContentDisplay activity
      # THIS WILL DISABLE CODE SHARES/LINKS/DISCUSSIONS
      # when "JCodeShare"    then @createCodeShareContentDisplay activity

  showContentDisplay:(contentDisplay)->
    contentDisplayController = @getSingleton "contentDisplayController"
    contentDisplayController.emit "ContentDisplayWantsToBeShown", contentDisplay

  createStatusUpdateContentDisplay:(activity)->
    @showContentDisplay new ContentDisplayStatusUpdate
      title : "Status Update"
      type  : "status"
    ,activity

  createCodeSnippetContentDisplay:(activity)->
    @showContentDisplay new ContentDisplayCodeSnippet
      title : "Code Snippet"
      type  : "codesnip"
    ,activity

  createCodeShareContentDisplay:(activity)->
    @showContentDisplay new ContentDisplayCodeShare
      title       : "Code Share"
      type        : "codeshare"
    , activity

  createDiscussionContentDisplay:(activity)->
    @showContentDisplay new ContentDisplayDiscussion
      title : "Discussion"
      type  : "discussion"
    ,activity

  createTutorialContentDisplay:(activity)->
    @showContentDisplay new ContentDisplayTutorial
      title : "Tutorial"
      type  : "tutorial"
    ,activity



  # delete
  fetchActivityOverview:(callback)->

