<commit_before># this file was once nice and tidy (see https://github.com/koding/koding/blob/dd4e70d88795fe6d0ea0bfbb2ef0e4a573c08999/client/Social/Activity/sidebar/activitysidebar.coffee)
# once we merged two sidebars into one
# activity sidebar became the mainsidebar
# and unfortunately we have too mcuh goin on here right now.
# vm menu and activity menu should be separated,
# needs a little refactor. - SY

class ActivitySidebar extends KDCustomHTMLView

  typeMap =
    privatemessage : 'Message'
    topic          : 'Topic'
    post           : 'Post'
    chat           : 'Chat'

  slugProps =
    SocialMessage : 'slug'
    SocialChannel : 'name'

  revive = (data) ->

    return switch data.typeConstant
      when 'post'  then KD.singletons.socialapi.message.revive message: data  #mapActivity
      when 'topic' then KD.singletons.socialapi.channel.revive data
      else data


  constructor: (options = {}) ->

    options.cssClass  = 'activity-sidebar'

    super options

    {
      notificationController
      computeController
      socialapi
      router
    } = KD.singletons

    @sections     = {}
    @itemsById    = {}
    @itemsBySlug  = {}
    @itemsByName  = {}
    @selectedItem = null

    @workspaceItemChannelMap = {}

    # @appsList = new DockController

    router
      .on "RouteInfoHandled",          @bound 'deselectAllItems'

    notificationController
      .on 'AddedToChannel',            @bound 'accountAddedToChannel'
      .on 'RemovedFromChannel',        @bound 'accountRemovedFromChannel'
      .on 'MessageAddedToChannel',     @bound 'messageAddedToChannel'
      .on 'MessageRemovedFromChannel', @bound 'messageRemovedFromChannel'
      .on 'ReplyAdded',                @bound 'replyAdded'

      .on 'MessageListUpdated',        @bound 'setPostUnreadCount'
      .on 'ParticipantUpdated',        @bound 'handleGlanced'
      # .on 'ReplyRemoved',              (update) -> log update.event, update
      # .on 'ChannelUpdateHappened',     @bound 'channelUpdateHappened'

    computeController
      .on 'MachineDataModified',       @bound 'updateMachineTree'
      .on 'RenderMachines',            @bound 'renderMachines'
      .on 'MachineBeingDestroyed',     @bound 'invalidateWorkspaces'

    @on 'MoreWorkspaceModalRequested', @bound 'handleMoreWorkspacesClick'

  # event handling

  messageAddedToChannel: (update) ->
    switch update.channel.typeConstant
      when 'pinnedactivity' then @replyAdded update
      else  @handleFollowedFeedUpdate update


  messageRemovedFromChannel: (update) ->

    {id} = update.channelMessage

    @removeItem id


  handleGlanced: (update) -> @selectedItem?.setUnreadCount? update.unreadCount

  setUnreadCount: (item, data, unreadCount) ->

    return  unless item

    {windowController, appManager} = KD.singletons

    app = appManager.getFrontApp()

    if app?.getOption('name') is 'Activity'
      pane    = app.getView().tabs.getActivePane()
      channel = pane.getData()

      return  unless channel

      inCurrentPane = channel.id is data.id

      if inCurrentPane and windowController.isFocused() and pane.isPageAtBottom()
        return pane.glance()
      else
        pane.putNewMessageIndicator()

    item.setUnreadCount? unreadCount

    @setUnreadCountForWorkspace data, unreadCount  if @workspaceItemChannelMap[data._id]


  setUnreadCountForWorkspace: (data, unreadCount) ->

    workspaceItem = @workspaceItemChannelMap[data._id]

    workspaceItem.child.setUnreadCount unreadCount



  handleFollowedFeedUpdate: (update) ->

    # WARNING: WRONG NAMING ON THE METHODS
    # these are the situations where we end up here
    #
    # when a REPLY is added to a PRIVATE MESSAGE<commit_msg>sidebar: change method name to be more consistent<commit_after># this file was once nice and tidy (see https://github.com/koding/koding/blob/dd4e70d88795fe6d0ea0bfbb2ef0e4a573c08999/client/Social/Activity/sidebar/activitysidebar.coffee)
# once we merged two sidebars into one
# activity sidebar became the mainsidebar
# and unfortunately we have too mcuh goin on here right now.
# vm menu and activity menu should be separated,
# needs a little refactor. - SY

class ActivitySidebar extends KDCustomHTMLView

  typeMap =
    privatemessage : 'Message'
    topic          : 'Topic'
    post           : 'Post'
    chat           : 'Chat'

  slugProps =
    SocialMessage : 'slug'
    SocialChannel : 'name'

  revive = (data) ->

    return switch data.typeConstant
      when 'post'  then KD.singletons.socialapi.message.revive message: data  #mapActivity
      when 'topic' then KD.singletons.socialapi.channel.revive data
      else data


  constructor: (options = {}) ->

    options.cssClass  = 'activity-sidebar'

    super options

    {
      notificationController
      computeController
      socialapi
      router
    } = KD.singletons

    @sections     = {}
    @itemsById    = {}
    @itemsBySlug  = {}
    @itemsByName  = {}
    @selectedItem = null

    @workspaceItemChannelMap = {}

    # @appsList = new DockController

    router
      .on "RouteInfoHandled",          @bound 'deselectAllItems'

    notificationController
      .on 'AddedToChannel',            @bound 'accountAddedToChannel'
      .on 'RemovedFromChannel',        @bound 'accountRemovedFromChannel'
      .on 'MessageAddedToChannel',     @bound 'messageAddedToChannel'
      .on 'MessageRemovedFromChannel', @bound 'messageRemovedFromChannel'
      .on 'ReplyAdded',                @bound 'replyAdded'

      .on 'MessageListUpdated',        @bound 'setPostUnreadCount'
      .on 'ParticipantUpdated',        @bound 'handleGlanced'
      # .on 'ReplyRemoved',              (update) -> log update.event, update
      # .on 'ChannelUpdateHappened',     @bound 'channelUpdateHappened'

    computeController
      .on 'MachineDataModified',       @bound 'updateMachineTree'
      .on 'RenderMachines',            @bound 'renderMachines'
      .on 'MachineBeingDestroyed',     @bound 'invalidateWorkspaces'

    @on 'MoreWorkspaceModalRequested', @bound 'handleMoreWorkspacesClick'

  # event handling

  messageAddedToChannel: (update) ->
    switch update.channel.typeConstant
      when 'pinnedactivity' then @replyAdded update
      else  @handleFollowedFeedUpdate update


  messageRemovedFromChannel: (update) ->

    {id} = update.channelMessage

    @removeItem id


  handleGlanced: (update) -> @selectedItem?.setUnreadCount? update.unreadCount

  setUnreadCount: (item, data, unreadCount) ->

    return  unless item

    {windowController, appManager} = KD.singletons

    app = appManager.getFrontApp()

    if app?.getOption('name') is 'Activity'
      pane    = app.getView().tabs.getActivePane()
      channel = pane.getData()

      return  unless channel

      inCurrentPane = channel.id is data.id

      if inCurrentPane and windowController.isFocused() and pane.isPageAtBottom()
        return pane.glance()
      else
        pane.putNewMessageIndicator()

    item.setUnreadCount? unreadCount

    @setWorkspaceUnreadCount data, unreadCount  if @workspaceItemChannelMap[data._id]


  setWorkspaceUnreadCount: (data, unreadCount) ->

    workspaceItem = @workspaceItemChannelMap[data._id]

    workspaceItem.child.setUnreadCount unreadCount



  handleFollowedFeedUpdate: (update) ->

    # WARNING: WRONG NAMING ON THE METHODS
    # these are the situations where we end up here
    #
    # when a REPLY is added to a PRIVATE MESSAGE
{'fraction_non_alphanumeric': 0.0881405956533405, 'fraction_numerical': 0.0059028709417762275, 'mean_word_length': 2.948622881355932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '5039787', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2124, 'n_words': 538}