<commit_before>class ActivitySidebar extends KDCustomScrollView


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


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


  revive = (data) ->

    return switch data.typeConstant
      when 'post' then (KD.singleton 'socialapi').message.revive message: data
      when 'topic' then (KD.singleton 'socialapi').mapChannel data
      else data


  constructor: ->

    super

    {
      notificationController
      socialapi
    } = KD.singletons

    @sections     = {}
    @selectedItem = null

    notificationController
      .on 'AddedToChannel',            @bound 'addToChannel'
      .on 'RemovedFromChannel',        @bound 'removeFromChannel'
      .on 'ChannelUpdateHappened',     @bound 'notificationHasArrived'
      .on 'NotificationHasArrived',    @bound 'notificationHasArrived'


  addToChannel: (channel) ->

    data           = revive channel
    listController = @getListController data.typeConstant

    return  if listController.itemForId data.id

    listController.addItem data
    @updateTopicFollowButtons data


  removeFromChannel: (channel) ->

    channel        = revive channel
    listController = @getListController channel.typeConstant
    item           = listController.itemForId channel.getId()
    listController.removeItem item
    @updateTopicFollowButtons channel


  notificationHasArrived: (update) ->

    log 'notificationHasArrived', update

    switch update.event
      when 'MessageAddedToChannel'     then return @addToChannel update.channelMessage
      when 'MessageRemovedFromChannel' then return @removeFromChannel update.channelMessage

    {unreadCount, channel} = update
    {typeConstant, id}     = channel

    listController = @getListController typeConstant
    item = listController.itemForId id
    item.setUnreadCount unreadCount  if item?.unreadCount


  getListController: (type) -><commit_msg>activity: set channel unread count if event contains a channel<commit_after>class ActivitySidebar extends KDCustomScrollView


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


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


  revive = (data) ->

    return switch data.typeConstant
      when 'post' then (KD.singleton 'socialapi').message.revive message: data
      when 'topic' then (KD.singleton 'socialapi').mapChannel data
      else data


  constructor: ->

    super

    {
      notificationController
      socialapi
    } = KD.singletons

    @sections     = {}
    @selectedItem = null

    notificationController
      .on 'AddedToChannel',            @bound 'addToChannel'
      .on 'RemovedFromChannel',        @bound 'removeFromChannel'
      .on 'ChannelUpdateHappened',     @bound 'notificationHasArrived'
      .on 'NotificationHasArrived',    @bound 'notificationHasArrived'


  addToChannel: (channel) ->

    data           = revive channel
    listController = @getListController data.typeConstant

    return  if listController.itemForId data.id

    listController.addItem data
    @updateTopicFollowButtons data


  removeFromChannel: (channel) ->

    channel        = revive channel
    listController = @getListController channel.typeConstant
    item           = listController.itemForId channel.getId()
    listController.removeItem item
    @updateTopicFollowButtons channel


  notificationHasArrived: (update) ->

    log 'notificationHasArrived', update

    switch update.event
      when 'MessageAddedToChannel'     then return @addToChannel update.channelMessage
      when 'MessageRemovedFromChannel' then return @removeFromChannel update.channelMessage

    @setChannelUnreadCount update  if update.channel


  setChannelUnreadCount: ({unreadCount, channel}) ->

    return  unless channel

    {typeConstant, id} = channel

    listController = @getListController typeConstant
    item = listController.itemForId id
    item.setUnreadCount unreadCount  if item?.unreadCount


  getListController: (type) ->
{'fraction_non_alphanumeric': 0.07583052479537795, 'fraction_numerical': 0.0, 'mean_word_length': 2.9161168708765315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '411305', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1083, 'n_words': 278}