<commit_before>jraphical = require 'jraphical'

JAccount = require '../account'
JComment = require './comment'

JTag = require '../tag'
CActivity = require '../activity'
CRepliesActivity = require '../activity/repliesactivity'

KodingError = require '../../error'

module.exports = class JPost extends jraphical.Message

  @trait __dirname, '../../traits/followable'
  @trait __dirname, '../../traits/taggable'
  @trait __dirname, '../../traits/notifying'
  @trait __dirname, '../../traits/flaggable'
  @trait __dirname, '../../traits/likeable'
  @trait __dirname, '../../traits/protected'
  @trait __dirname, '../../traits/slugifiable'
  @trait __dirname, '../../traits/restrictedquery'

  {Base,ObjectRef,dash,daisy} = require 'bongo'
  {Relationship} = jraphical
  {extend} = require 'underscore'

  {log} = console

  Validators = require '../group/validators'
  {permit}   = require '../group/permissionset'

  schema = extend {}, jraphical.Message.schema, {
    isLowQuality  : Boolean
    slug          : String
    slug_         : String # this is necessary, because $exists
                           #operator won't work with a sparse index.
    group         : String 
    counts        :
      followers   :
        type      : Number
        default   : 0
      following   :
        type      : Number
        default   : 0
  }

  # TODO: these relationships may not be abstract enough to belong to JPost.
  @set
    softDelete  : no
    slugifyFrom : 'title'
    slugTemplate: ->
      """
      #{if @group is 'koding' then '' else "#{@group}/"}Activity/\#{slug}
      """
    indexes     :
      slug      : 'unique'
      group     : 'sparse'
    permissions :
      'read posts'        : ['member', 'moderator']
      'create posts'      : ['member', 'moderator']
      'edit posts'        : ['moderator']
      'delete posts'      : ['moderator']
      'edit own posts'    : ['member', 'moderator']
      'delete own posts'  : ['member', 'moderator']
      'reply to posts'    : ['member', 'moderator']
      'like posts'        : ['member', 'moderator']
      'pin posts'         : ['member', 'moderator']
    emitFollowingActivities: yes
    taggedContentRole : 'post'
    tagRole           : 'tag'
    schema            : schema<commit_msg>Social:  add new permission rules for private message<commit_after>jraphical = require 'jraphical'

JAccount = require '../account'
JComment = require './comment'

JTag = require '../tag'
CActivity = require '../activity'
CRepliesActivity = require '../activity/repliesactivity'

KodingError = require '../../error'

module.exports = class JPost extends jraphical.Message

  @trait __dirname, '../../traits/followable'
  @trait __dirname, '../../traits/taggable'
  @trait __dirname, '../../traits/notifying'
  @trait __dirname, '../../traits/flaggable'
  @trait __dirname, '../../traits/likeable'
  @trait __dirname, '../../traits/protected'
  @trait __dirname, '../../traits/slugifiable'
  @trait __dirname, '../../traits/restrictedquery'

  {Base,ObjectRef,dash,daisy} = require 'bongo'
  {Relationship} = jraphical
  {extend} = require 'underscore'

  {log} = console

  Validators = require '../group/validators'
  {permit}   = require '../group/permissionset'

  schema = extend {}, jraphical.Message.schema, {
    isLowQuality  : Boolean
    slug          : String
    slug_         : String # this is necessary, because $exists
                           #operator won't work with a sparse index.
    group         : String 
    counts        :
      followers   :
        type      : Number
        default   : 0
      following   :
        type      : Number
        default   : 0
  }

  # TODO: these relationships may not be abstract enough to belong to JPost.
  @set
    softDelete  : no
    slugifyFrom : 'title'
    slugTemplate: ->
      """
      #{if @group is 'koding' then '' else "#{@group}/"}Activity/\#{slug}
      """
    indexes     :
      slug      : 'unique'
      group     : 'sparse'
    permissions :
      'read posts'        : ['member', 'moderator']
      'create posts'      : ['member', 'moderator']
      'edit posts'        : ['moderator']
      'delete posts'      : ['moderator']
      'edit own posts'    : ['member', 'moderator']
      'delete own posts'  : ['member', 'moderator']
      'reply to posts'    : ['member', 'moderator']
      'like posts'        : ['member', 'moderator']
      'pin posts'         : ['member', 'moderator']
      'send private message' : ['member', 'moderator']
      'list private messages' : ['member', 'moderator']
    emitFollowingActivities: yes
    taggedContentRole : 'post'
    tagRole           : 'tag'
    schema            : schema
{'fraction_non_alphanumeric': 0.14731665597605303, 'fraction_numerical': 0.0008552490912978405, 'mean_word_length': 2.197539302802461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6609788', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1411, 'n_words': 368}