       # channelId for mapping social API
       # to internal usage
       socialApiChannelId: String
+      socialApiDefaultChannelId: String
       avatar        : String
       slug          :
         type        : String

        callback()

  createSocialApiChannelId: (callback) ->
    return callback null, @socialApiChannelId  if @socialApiChannelId
    @fetchOwner (err, owner)=>
      return callback err if err
      unless owner

        # required data for creating a channel
        privacy = if @slug is "koding" then "public" else "private"

        options =
          creatorId: socialApiId
          privacyConstant: privacy

        @createDefaultChannel options, (err, defaultChannelId) =>
          return callback err if err
          @createGroupChannel options, (err, groupChannelId) =>
            return callback err if err
            return callback null, groupChannelId

  createDefaultChannel:(options, callback)->
    options.varName = "socialApiDefaultChannelId"
    options.typeConstant = "default"

    return @createSocialAPIChannel options, callback


  createGroupChannel:(options, callback)->
    options.name = "public"
    options.varName = "socialApiChannelId"
    options.typeConstant = "group"

    return @createSocialAPIChannel options, callback

  createSocialAPIChannel:(options, callback)->
    {varName, name, typeConstant, creatorId, privacyConstant} = options

    return @[varName]  if @[varName]

    defaultChannel =
      name            : name or @slug
      creatorId       : creatorId
      groupName       : @slug
      typeConstant    : typeConstant
      privacyConstant : privacyConstant

    {createChannel} = require '../socialapi/requests'
    createChannel defaultChannel, (err, channel)=>
      return callback err if err

      op = $set:{}
      op.$set[varName] = channel.id

      @update op, (err)->
        return callback err if err
        return callback null, channel.id

