<commit_before>machina                       = require 'machina'
remote                        = require('app/remote').getInstance()
dateFormat                    = require 'dateformat'
sinkrow                       = require 'sinkrow'
globals                       = require 'globals'
kd                            = require 'kd'
KDNotificationView            = kd.NotificationView
nick                          = require 'app/util/nick'
getCollaborativeChannelPrefix = require 'app/util/getCollaborativeChannelPrefix'
showError                     = require 'app/util/showError'
whoami                        = require 'app/util/whoami'
RealtimeManager               = require './realtimemanager'
IDEChatView                   = require './views/chat/idechatview'
IDEMetrics                    = require './idemetrics'
doXhrRequest                  = require 'app/util/doXhrRequest'
realtimeHelpers               = require './collaboration/helpers/realtime'
socialHelpers                 = require './collaboration/helpers/social'

{warn} = kd

# Attn!!
#
# This object is designed to be a mixin for IDEAppController.
#
# @see `IDEAppController`

module.exports =

  # social related

  setSocialChannel: (channel) ->

    @socialChannel = channel

    @socialChannel.on 'AddedToChannel', (socialAccount) =>

      socialHelpers.fetchAccount socialAccount, (account) =>

        return  unless account

        {nickname} = account.profile
        @statusBar.createParticipantAvatar nickname, no
        @watchParticipant nickname


  initPrivateMessage: (callback) ->

    socialHelpers.initChannel (err, channel) =>
      return callback err  if err

      @setSocialChannel channel
      @updateWorkspace { channelId : channel.id }
        .then =>
          @workspaceData.channelId = channel.id
          callback null, channel
          @chat.ready => @chat.emit 'CollaborationNotInitialized'
        .error callback


  fetchSocialChannel: (callback) ->

    return callback null, @socialChannel  if @socialChannel

    id = @channelId or @workspaceData.channelId

    return callback()  unless id

    kd.singletons.socialapi.cacheable 'channel', id, (err, channel) =>
      return callback err  if err

      @setSocialChannel channel

      callback null, @socialChannel


  deletePrivateMessage: (callback = kd.noop) ->

    {channel}    = kd.getSingleton 'socialapi'
    {JWorkspace} = remote.api

    options = channelId: @socialChannel.getId()
    channel.delete options, (err) =>

      return callback err  if err<commit_msg>collaboration: controller add a getSocialChannelId method<commit_after>machina                       = require 'machina'
remote                        = require('app/remote').getInstance()
dateFormat                    = require 'dateformat'
sinkrow                       = require 'sinkrow'
globals                       = require 'globals'
kd                            = require 'kd'
KDNotificationView            = kd.NotificationView
nick                          = require 'app/util/nick'
getCollaborativeChannelPrefix = require 'app/util/getCollaborativeChannelPrefix'
showError                     = require 'app/util/showError'
whoami                        = require 'app/util/whoami'
RealtimeManager               = require './realtimemanager'
IDEChatView                   = require './views/chat/idechatview'
IDEMetrics                    = require './idemetrics'
doXhrRequest                  = require 'app/util/doXhrRequest'
realtimeHelpers               = require './collaboration/helpers/realtime'
socialHelpers                 = require './collaboration/helpers/social'

{warn} = kd

# Attn!!
#
# This object is designed to be a mixin for IDEAppController.
#
# @see `IDEAppController`

module.exports =

  # social related

  setSocialChannel: (channel) ->

    @socialChannel = channel

    @socialChannel.on 'AddedToChannel', (socialAccount) =>

      socialHelpers.fetchAccount socialAccount, (account) =>

        return  unless account

        {nickname} = account.profile
        @statusBar.createParticipantAvatar nickname, no
        @watchParticipant nickname


  initPrivateMessage: (callback) ->

    socialHelpers.initChannel (err, channel) =>
      return callback err  if err

      @setSocialChannel channel
      @updateWorkspace { channelId : channel.id }
        .then =>
          @workspaceData.channelId = channel.id
          callback null, channel
          @chat.ready => @chat.emit 'CollaborationNotInitialized'
        .error callback


  fetchSocialChannel: (callback) ->

    return callback null, @socialChannel  if @socialChannel

    id = @channelId or @workspaceData.channelId

    return callback()  unless id

    kd.singletons.socialapi.cacheable 'channel', id, (err, channel) =>
      return callback err  if err

      @setSocialChannel channel

      callback null, @socialChannel


  getSocialChannelId: ->

    return @socialChannel?.id or @channelId or @workspaceData.channelId


  deletePrivateMessage: (callback = kd.noop) ->

    {channel}    = kd.getSingleton 'socialapi'
    {JWorkspace} = remote.api

    options = channelId: @socialChannel.getId()
    channel.delete options, (err) =>

      return callback err  if err
{'fraction_non_alphanumeric': 0.0875717017208413, 'fraction_numerical': 0.0, 'mean_word_length': 2.2450372208436726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '7049855', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1351, 'n_words': 337}