<commit_before>class ActivitySidebar extends KDCustomScrollView


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


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


  # @getRoute = (data) ->

  #   {typeConstant} = data
  #   groupName      = KD.getGroup().slug
  #   groupName      = ''  if groupName is 'koding'
  #   slugProp       = slugProps[data.bongo_.constructorName]

  #   return "#{groupName}/Activity/#{typeMap[typeConstant]}/#{data[slugProp]}"


  # sanitize = (allItems) ->

  #   sanitized = []
  #   for own title, items of allItems
  #     header = new KDObject { title }
  #     items.forEach (item) ->
  #       obj = new KDObject {}, item
  #       obj.parentId = header.getId()
  #       sanitized.push obj
  #     sanitized.push header

  #   return sanitized.reverse()


  constructor: ->

    super

    {
      notificationController
      socialapi
    } = KD.singletons

    @sections     = {}
    @selectedItem = null

    notificationController.on 'AddedToChannel', (channel) =>

      [topic] = socialapi.mapChannels channel

      @sections.followedTopics.listController.addItem topic


    notificationController.on 'RemovedFromChannel', (channel) =>

      {listController} = @sections.followedTopics

      [topic] = socialapi.mapChannels channel
      item    = listController.itemsIndexed[topic.id]

      listController.removeItem item


  # fixme:
  # this item selection is a bit tricky
  # depends on multiple parts:
  # - sidebaritem's lastTimestamp
  # - the item which is being clicked
  # - and what the route suggests
  # needs to be simplified
  selectItemByRouteOptions: (type, slug) ->

    @deselectAllItems()

    if type is 'public'
    then return @public.setClass 'selected'
    else @public.unsetClass 'selected'

    type = 'privatemessage' if type is 'message'

    candidateItems = []
    for own name, {listController} of @sections

      for item in listController.itemsOrdered
        data = item.getData()
        if data.typeConstant is type and (data.id is slug or data.name is slug or data.slug is slug)
          candidateItems.push item

    candidateItems.sort (a, b) -> a.lastClickedTimestamp < b.lastClickedTimestamp

    if candidateItems.first
      listController.selectSingleItem candidateItems.first
      @selectedItem = candidateItems.first


  deselectAllItems: ->

    for own name, {listController} of @sections

      listController.deselectAllItems()


  # getItemById: (id) ->

  #   item = null
  #   for own name, section of @sections

  #     item = section.listController.itemsIndexed[id]
  #     break  if item

  #   return item


  getItemByRouteParams: (type, slug) ->

    typeConstant = k for own k, v of typeMap when v = type

    itemWeWant = null
    for own name, section of @sections

      section.listController.itemsOrdered.forEach (item)->
        if item.typeConstant is typeConstant
          slugProp = slugProps[item.bongo_.constructorName]
          itemWeWant = item[slugProp] is slug

    return itemWeWant


  viewAppended: ->

    super

    @addPublicFeedLink()
    @addHotTopics()
    @addFollowedTopics()
    @addFollowedPosts()
    @addMessages()
    # @addChat()


  addPublicFeedLink: ->

    {activityController} = KD.singletons

    @wrapper.addSubView @public = new CustomLinkView
      title    : 'PUBLIC FEED'
      href     : '/Activity/Public'
      cssClass : 'kdlistitemview-sidebar-item public-feed-link'
    ,
      name     : 'koding_public_feed'
      id       : KD.getGroup().socialApiChannelId ? '1'

    @public.addSubView new KDCustomHTMLView
      cssClass : 'count hidden'
      tagName  : 'cite'
      partial  : '1'
<commit_msg>activity: add name, group name and type constant properties to public feed link view data<commit_after>class ActivitySidebar extends KDCustomScrollView


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


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


  # @getRoute = (data) ->

  #   {typeConstant} = data
  #   groupName      = KD.getGroup().slug
  #   groupName      = ''  if groupName is 'koding'
  #   slugProp       = slugProps[data.bongo_.constructorName]

  #   return "#{groupName}/Activity/#{typeMap[typeConstant]}/#{data[slugProp]}"


  # sanitize = (allItems) ->

  #   sanitized = []
  #   for own title, items of allItems
  #     header = new KDObject { title }
  #     items.forEach (item) ->
  #       obj = new KDObject {}, item
  #       obj.parentId = header.getId()
  #       sanitized.push obj
  #     sanitized.push header

  #   return sanitized.reverse()


  constructor: ->

    super

    {
      notificationController
      socialapi
    } = KD.singletons

    @sections     = {}
    @selectedItem = null

    notificationController.on 'AddedToChannel', (channel) =>

      [topic] = socialapi.mapChannels channel

      @sections.followedTopics.listController.addItem topic


    notificationController.on 'RemovedFromChannel', (channel) =>

      {listController} = @sections.followedTopics

      [topic] = socialapi.mapChannels channel
      item    = listController.itemsIndexed[topic.id]

      listController.removeItem item


  # fixme:
  # this item selection is a bit tricky
  # depends on multiple parts:
  # - sidebaritem's lastTimestamp
  # - the item which is being clicked
  # - and what the route suggests
  # needs to be simplified
  selectItemByRouteOptions: (type, slug) ->

    @deselectAllItems()

    if type is 'public'
    then return @public.setClass 'selected'
    else @public.unsetClass 'selected'

    type = 'privatemessage' if type is 'message'

    candidateItems = []
    for own name, {listController} of @sections

      for item in listController.itemsOrdered
        data = item.getData()
        if data.typeConstant is type and (data.id is slug or data.name is slug or data.slug is slug)
          candidateItems.push item

    candidateItems.sort (a, b) -> a.lastClickedTimestamp < b.lastClickedTimestamp

    if candidateItems.first
      listController.selectSingleItem candidateItems.first
      @selectedItem = candidateItems.first


  deselectAllItems: ->

    for own name, {listController} of @sections

      listController.deselectAllItems()


  # getItemById: (id) ->

  #   item = null
  #   for own name, section of @sections

  #     item = section.listController.itemsIndexed[id]
  #     break  if item

  #   return item


  getItemByRouteParams: (type, slug) ->

    typeConstant = k for own k, v of typeMap when v = type

    itemWeWant = null
    for own name, section of @sections

      section.listController.itemsOrdered.forEach (item)->
        if item.typeConstant is typeConstant
          slugProp = slugProps[item.bongo_.constructorName]
          itemWeWant = item[slugProp] is slug

    return itemWeWant


  viewAppended: ->

    super

    @addPublicFeedLink()
    @addHotTopics()
    @addFollowedTopics()
    @addFollowedPosts()
    @addMessages()
    # @addChat()


  addPublicFeedLink: ->

    {activityController} = KD.singletons
    {slug, socialApiChannelId} = KD.getGroup()

    @wrapper.addSubView @public = new CustomLinkView
      title    : 'PUBLIC FEED'
      href     : '/Activity/Public'
      cssClass : 'kdlistitemview-sidebar-item public-feed-link'
    ,
      name         : slug
      typeConstant : 'group'
      groupName    : slug
      id           : socialApiChannelId ? '1'

    @public.addSubView new KDCustomHTMLView
      cssClass : 'count hidden'
      tagName  : 'cite'
      partial  : '1'

{'fraction_non_alphanumeric': 0.09534339229968783, 'fraction_numerical': 0.0005202913631633715, 'mean_word_length': 2.5547850208044385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '7482686', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2266, 'n_words': 579}