<commit_before>jraphical = require 'jraphical'

KodingError = require '../error'

module.exports = class JAccount extends jraphical.Module
  log4js          = require "log4js"
  log             = log4js.getLogger("[JAccount]")

  @trait __dirname, '../traits/followable'
  @trait __dirname, '../traits/filterable'
  @trait __dirname, '../traits/taggable'
  @trait __dirname, '../traits/notifiable'
  @trait __dirname, '../traits/flaggable'

  JAppStorage = require './appstorage'

  @getFlagRole = 'content'

  {ObjectId, Register, secure, race, dash} = require 'bongo'
  {Relationship} = jraphical
  @share()
  Experience =
    company           : String
    website           : String
    position          : String
    type              : String
    fromDate          : String
    toDate            : String
    description       : String
    # endorsements      : [
    #       endorser    : String
    #       title       : String
    #       text        : String
    #     ]
  @set
    emitFollowingActivities : yes # create buckets for follower / followees
    tagRole             : 'skill'
    taggedContentRole   : 'developer'
    indexes:
      'profile.nickname' : 'unique'
    sharedMethods :
      static      : [
        'one', 'some', 'someWithRelationship'
        'someData', 'getAutoCompleteData', 'count'
        'byRelevance'
      ]
      instance    : [
        'on','modify','follow','unfollow','fetchFollowersWithRelationship'
        'fetchFollowingWithRelationship',
        'fetchMounts','fetchActivityTeasers','fetchRepos','fetchDatabases'
        'fetchMail','fetchNotificationsTimeline','fetchActivities'
        'fetchStorage','count','addTags','fetchLimit'
        'fetchFollowedTopics', 'fetchKiteChannelId', 'setEmailPreferences'
        'fetchNonces', 'glanceMessages', 'glanceActivities', 'fetchRole'
        'fetchAllKites','flagAccount','unflagAccount'
      ]
    schema                  :
      skillTags             : [String]
      locationTags          : [String]
      systemInfo            :
        defaultToLastUsedEnvironment :
          type              : Boolean
          default           : yes
      # counts                : Followable.schema.counts
      counts                :
        followers           :
          type              : Number
          default           : 0
        following           :
          type              : Number
          default           : 0
        topics              :
          type              : Number
          default           : 0
      environmentIsCreated  : Boolean
      profile               :
        about               : String
        nickname            :
          type              : String
          validate          : (value)->
            3 < value.length < 26 and /^[a-z0-9][a-z0-9-]+$/.test value
          set               : (value)-> value.toLowerCase()
        hash                :
          type              : String
          # email             : yes
        ircNickname         : String
        firstName           :
          type              : String
          required          : yes

        lastName            :
          type              : String
          default           : ''
        description         : String
        avatar              : String
        status              : String
        experience          : String
        experiencePoints    :
          type              : Number
          default           : 0
        lastStatusUpdate    : String
      globalFlags           : [String]
      meta                  : require 'bongo/bundles/meta'
    relationships           :

      mount         :
        as          : 'owner'
        targetType  : "JMount"

      repo          :
        as          : 'owner'
        targetType  : "JRepo"

      # database      :
      #   as          : 'owner'
      #   targetType  : JDatabase

      follower      :
        as          : 'follower'
        targetType  : "JAccount"

      followee      :
        as          : 'followee'
        targetType  : JAccount

      activity      :
        as          : 'activity'
        targetType  : "CActivity"

      privateMessage:
        as          : ['recipient','sender']
        targetType  : 'JPrivateMessage'

      appStorage    :
        as          : 'appStorage'
        targetType  : "JAppStorage"

      limit:
        as          : 'invite'
        targetType  : "JLimit"

      tag:
        as          : 'skill'
        targetType  : "JTag"

      content       :
        as          : 'creator'
        targetType  : ["CActivity", "JStatusUpdate", "JCodeSnip", "JComment"]

      feed         :
        as          : "owner"
        targetType  : "JFeed"

  @findSuggestions = (seed, options, callback)->
    {limit, blacklist, skip}  = options
    @some {
      $or : [
          ( 'profile.nickname'  : seed )
          ( 'profile.firstName' : seed )
          ( 'profile.lastName'  : seed )
        ],
      _id     :
        $nin  : blacklist
    },{
      skip
      limit
      sort    : 'profile.firstName' : 1
    }, callback

  @getAutoCompleteData = (fieldString, queryString, callback)->
    query = {}
    desiredData = {}
    query[fieldString] = RegExp queryString, 'i'
    desiredData[fieldString] = yes
    @someData query, desiredData, (err, cursor)->
      cursor.toArray (err, docs)->
        results = []
        for doc in docs
          results.push doc.profile.fullname
        callback err, results

  setEmailPreferences: secure (client, prefs, callback)->
    JUser.fetchUser client, (err, user)->
      if err
        callback err
      else
        Object.keys(prefs).forEach (granularity)->
          prefs[granularity] = if prefs[granularity] then 'instant' else 'never'<commit_msg>Require JUser<commit_after>jraphical = require 'jraphical'

KodingError = require '../error'

module.exports = class JAccount extends jraphical.Module
  log4js          = require "log4js"
  log             = log4js.getLogger("[JAccount]")

  @trait __dirname, '../traits/followable'
  @trait __dirname, '../traits/filterable'
  @trait __dirname, '../traits/taggable'
  @trait __dirname, '../traits/notifiable'
  @trait __dirname, '../traits/flaggable'

  JAppStorage = require './appstorage'

  @getFlagRole = 'content'

  {ObjectId, Register, secure, race, dash} = require 'bongo'
  {Relationship} = jraphical
  @share()
  Experience =
    company           : String
    website           : String
    position          : String
    type              : String
    fromDate          : String
    toDate            : String
    description       : String
    # endorsements      : [
    #       endorser    : String
    #       title       : String
    #       text        : String
    #     ]
  @set
    emitFollowingActivities : yes # create buckets for follower / followees
    tagRole             : 'skill'
    taggedContentRole   : 'developer'
    indexes:
      'profile.nickname' : 'unique'
    sharedMethods :
      static      : [
        'one', 'some', 'someWithRelationship'
        'someData', 'getAutoCompleteData', 'count'
        'byRelevance'
      ]
      instance    : [
        'on','modify','follow','unfollow','fetchFollowersWithRelationship'
        'fetchFollowingWithRelationship',
        'fetchMounts','fetchActivityTeasers','fetchRepos','fetchDatabases'
        'fetchMail','fetchNotificationsTimeline','fetchActivities'
        'fetchStorage','count','addTags','fetchLimit'
        'fetchFollowedTopics', 'fetchKiteChannelId', 'setEmailPreferences'
        'fetchNonces', 'glanceMessages', 'glanceActivities', 'fetchRole'
        'fetchAllKites','flagAccount','unflagAccount'
      ]
    schema                  :
      skillTags             : [String]
      locationTags          : [String]
      systemInfo            :
        defaultToLastUsedEnvironment :
          type              : Boolean
          default           : yes
      # counts                : Followable.schema.counts
      counts                :
        followers           :
          type              : Number
          default           : 0
        following           :
          type              : Number
          default           : 0
        topics              :
          type              : Number
          default           : 0
      environmentIsCreated  : Boolean
      profile               :
        about               : String
        nickname            :
          type              : String
          validate          : (value)->
            3 < value.length < 26 and /^[a-z0-9][a-z0-9-]+$/.test value
          set               : (value)-> value.toLowerCase()
        hash                :
          type              : String
          # email             : yes
        ircNickname         : String
        firstName           :
          type              : String
          required          : yes

        lastName            :
          type              : String
          default           : ''
        description         : String
        avatar              : String
        status              : String
        experience          : String
        experiencePoints    :
          type              : Number
          default           : 0
        lastStatusUpdate    : String
      globalFlags           : [String]
      meta                  : require 'bongo/bundles/meta'
    relationships           :

      mount         :
        as          : 'owner'
        targetType  : "JMount"

      repo          :
        as          : 'owner'
        targetType  : "JRepo"

      # database      :
      #   as          : 'owner'
      #   targetType  : JDatabase

      follower      :
        as          : 'follower'
        targetType  : "JAccount"

      followee      :
        as          : 'followee'
        targetType  : JAccount

      activity      :
        as          : 'activity'
        targetType  : "CActivity"

      privateMessage:
        as          : ['recipient','sender']
        targetType  : 'JPrivateMessage'

      appStorage    :
        as          : 'appStorage'
        targetType  : "JAppStorage"

      limit:
        as          : 'invite'
        targetType  : "JLimit"

      tag:
        as          : 'skill'
        targetType  : "JTag"

      content       :
        as          : 'creator'
        targetType  : ["CActivity", "JStatusUpdate", "JCodeSnip", "JComment"]

      feed         :
        as          : "owner"
        targetType  : "JFeed"

  @findSuggestions = (seed, options, callback)->
    {limit, blacklist, skip}  = options
    @some {
      $or : [
          ( 'profile.nickname'  : seed )
          ( 'profile.firstName' : seed )
          ( 'profile.lastName'  : seed )
        ],
      _id     :
        $nin  : blacklist
    },{
      skip
      limit
      sort    : 'profile.firstName' : 1
    }, callback

  @getAutoCompleteData = (fieldString, queryString, callback)->
    query = {}
    desiredData = {}
    query[fieldString] = RegExp queryString, 'i'
    desiredData[fieldString] = yes
    @someData query, desiredData, (err, cursor)->
      cursor.toArray (err, docs)->
        results = []
        for doc in docs
          results.push doc.profile.fullname
        callback err, results

  setEmailPreferences: secure (client, prefs, callback)->
    JUser = require './user'
    JUser.fetchUser client, (err, user)->
      if err
        callback err
      else
        Object.keys(prefs).forEach (granularity)->
          prefs[granularity] = if prefs[granularity] then 'instant' else 'never'
{'fraction_non_alphanumeric': 0.0938768460143363, 'fraction_numerical': 0.0025908973141031176, 'mean_word_length': 1.3215717722534082, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '3393515', 'n_tokens_mistral': 3108, 'n_tokens_neox': 3029, 'n_words': 667}