<commit_before>class AvatarAreaIconMenu extends JView

  constructor:->

    super

    @setClass "account-menu"

    @helpIcon    = new AvatarAreaIconLink
      cssClass   : "help acc-dropdown-icon"
      attributes :
        title    : 'Help'

    @helpIcon.click = (event)=>
      KD.singletons.helpController.showHelp this
      KD.utils.stopDOMEvent event
      @animation?.destroy()

    @notificationsPopup = new AvatarPopupNotifications
      cssClass : "notifications"

    @notificationsIcon = new AvatarAreaIconLink
      cssClass   : 'notifications acc-dropdown-icon'
      attributes :
        title    : 'Notifications'
      delegate   : @notificationsPopup

    {mainController, troubleshoot} = KD.singletons
    troubleshoot.on "userIdle", =>
      idleModal = new KDModalView
        title          : "You were away from Koding for a while."
        content        : "Your dev VMs might have been turned off. Before you progress \
                          please check system status by clicking Resume."
        overlay        : yes
        buttons        :
          Resume       :
            style      : "modal-clean-green"
            callback   : ->
              idleModal.destroy()
              new TroubleshootModal
          Close        :
            style      : "modal-cancel"
            callback   : -> idleModal.destroy()


    mainController.ready =>
      storage = KD.singletons.localStorageController.storage('HelpController')
      unless storage.getValue 'shown'
        # KD.utils.wait 5000, =>
        #   KD.singletons.helpController.showHelp @helpIcon
        @helpIcon.addSubView @animation = new KDCustomHTMLView
          tagName    : "span"
          cssClass   : "intro-marker in help"

  pistachio:->
    """
    {{> @helpIcon}}
    {{> @notificationsIcon}}
    """

  viewAppended:->

    super

    mainView = KD.getSingleton 'mainView'
    mainView.addSubView @notificationsPopup

    @attachListeners()
    KD.getSingleton('mainController').on "AccountChanged", =>
      @attachListeners()


  attachListeners:->

    {listController, noNotification} = @notificationsPopup

    KD.getSingleton('notificationController').on 'NotificationHasArrived', ({event})=>

      if event is 'ActivityIsAdded' or 'BucketIsUpdated'
        listController.fetchNotificationTeasers (notifications)=>
          noNotification.hide()
          listController.removeAllItems()
          listController.instantiateListItems filterNotifications notifications

    listController.on 'NotificationCountDidChange', (count)=>
      @utils.killWait @notificationsPopup.loaderTimeout
      if count > 0
      then noNotification.hide()
      else noNotification.show()
      @notificationsIcon.updateCount count

  accountChanged:(account)->

    {listController} = @notificationsPopup
    listController.removeAllItems()

    return  unless KD.isLoggedIn()

    # Fetch Notifications
    KD.utils.defer ->
      listController.fetchNotificationTeasers (teasers)->
        listController.instantiateListItems filterNotifications teasers


  filterNotifications=(notifications)->
    activityNameMap = [
      "JNewStatusUpdate"
      "JAccount"
      "JPrivateMessage"
      "JComment"
      "JReview"
      "JGroup"
    ]
    notifications.filter (notification) ->
      return  unless notification.snapshot
      try
        snapshot = JSON.parse Encoder.htmlDecode notification.snapshot
        snapshot.anchor.constructorName in activityNameMap
<commit_msg>client: redirect quetion marks to learn.koding.com<commit_after>class AvatarAreaIconMenu extends JView

  constructor:->

    super

    @setClass "account-menu"

    @helpIcon    = new AvatarAreaIconLink
      cssClass   : "help acc-dropdown-icon"
      attributes :
        title    : 'Help'

    @helpIcon.click = (event)=>
      window.open "http://learn.koding.com"
      KD.utils.stopDOMEvent event

      # We disabled this feature since '?' relies on vm to be up for
      # certain items to show properly. SA
      #
      # KD.singletons.helpController.showHelp this
      # @animation?.destroy()

    @notificationsPopup = new AvatarPopupNotifications
      cssClass : "notifications"

    @notificationsIcon = new AvatarAreaIconLink
      cssClass   : 'notifications acc-dropdown-icon'
      attributes :
        title    : 'Notifications'
      delegate   : @notificationsPopup

    {mainController, troubleshoot} = KD.singletons
    troubleshoot.on "userIdle", =>
      idleModal = new KDModalView
        title          : "You were away from Koding for a while."
        content        : "Your dev VMs might have been turned off. Before you progress \
                          please check system status by clicking Resume."
        overlay        : yes
        buttons        :
          Resume       :
            style      : "modal-clean-green"
            callback   : ->
              idleModal.destroy()
              new TroubleshootModal
          Close        :
            style      : "modal-cancel"
            callback   : -> idleModal.destroy()


    mainController.ready =>
      storage = KD.singletons.localStorageController.storage('HelpController')
      unless storage.getValue 'shown'
        # KD.utils.wait 5000, =>
        #   KD.singletons.helpController.showHelp @helpIcon
        @helpIcon.addSubView @animation = new KDCustomHTMLView
          tagName    : "span"
          cssClass   : "intro-marker in help"

  pistachio:->
    """
    {{> @helpIcon}}
    {{> @notificationsIcon}}
    """

  viewAppended:->

    super

    mainView = KD.getSingleton 'mainView'
    mainView.addSubView @notificationsPopup

    @attachListeners()
    KD.getSingleton('mainController').on "AccountChanged", =>
      @attachListeners()


  attachListeners:->

    {listController, noNotification} = @notificationsPopup

    KD.getSingleton('notificationController').on 'NotificationHasArrived', ({event})=>

      if event is 'ActivityIsAdded' or 'BucketIsUpdated'
        listController.fetchNotificationTeasers (notifications)=>
          noNotification.hide()
          listController.removeAllItems()
          listController.instantiateListItems filterNotifications notifications

    listController.on 'NotificationCountDidChange', (count)=>
      @utils.killWait @notificationsPopup.loaderTimeout
      if count > 0
      then noNotification.hide()
      else noNotification.show()
      @notificationsIcon.updateCount count

  accountChanged:(account)->

    {listController} = @notificationsPopup
    listController.removeAllItems()

    return  unless KD.isLoggedIn()

    # Fetch Notifications
    KD.utils.defer ->
      listController.fetchNotificationTeasers (teasers)->
        listController.instantiateListItems filterNotifications teasers


  filterNotifications=(notifications)->
    activityNameMap = [
      "JNewStatusUpdate"
      "JAccount"
      "JPrivateMessage"
      "JComment"
      "JReview"
      "JGroup"
    ]
    notifications.filter (notification) ->
      return  unless notification.snapshot
      try
        snapshot = JSON.parse Encoder.htmlDecode notification.snapshot
        snapshot.anchor.constructorName in activityNameMap

{'fraction_non_alphanumeric': 0.08736783528102393, 'fraction_numerical': 0.0013912075681691708, 'mean_word_length': 2.474625422909618, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, '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': '3100054', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1894, 'n_words': 415}