 class ActivityListHeader extends JView
+
+  __count = 0
+
 
   constructor:->
 

      title        : "Live Updates: "
      size         : "tiny"
      callback     : (state) =>
        @appStorage.setValue 'liveUpdates', state, =>
        @updateShowNewItemsLink()
        KD.getSingleton('activityController').flags = liveUpdates : state
        KD.getSingleton('activityController').emit "LiveStatusUpdateStateChanged", state

      KD.getSingleton('activityController').flags = liveUpdates : state
      @lowQualitySwitch.setValue? @appStorage.getValue('showLowQualityContent') or off

  _checkForUpdates: do (lastTs = null, lastCount = null) ->
    itFailed = ->
      console.warn 'seems like live updates stopped coming'
      window._rollbar.push {
        user    : KD.nick()
        message : 'realtime failure detected'
      }
    ->
      KD.remote.api.CActivity.fetchLastActivityTimestamp (err, ts) =>
        itFailed()  if ts? and lastTs isnt ts and lastCount is __count
        lastTs = ts; lastCount = __count

  _togglePollForUpdates: do (i = null) -> (state) ->
    if state then i = setInterval (@bound '_checkForUpdates'), 60 * 1000 # 1 minute
    else clearInterval i

  pistachio:(newCount)->
    "<div class='header-wrapper'><span>Latest Activity</span>{{> @lowQualitySwitch}}{{> @liveUpdateButton}} {{> @showNewItemsLink}}{{> @refreshLink}}</div>"

  newActivityArrived:->
    __count++
    @_newItemsCount++
    @updateShowNewItemsLink()

