Vulcan/packages/vulcan-comments/lib/schema.js

154 lines
3.3 KiB
JavaScript
Raw Normal View History

2017-03-23 16:27:59 +09:00
import Users from 'meteor/vulcan:users';
2016-06-23 15:00:58 +09:00
/**
* @summary Comments schema
* @type {Object}
2016-06-23 15:00:58 +09:00
*/
const schema = {
2016-06-23 15:00:58 +09:00
/**
ID
*/
_id: {
type: String,
optional: true,
viewableBy: ['guests'],
2016-06-23 15:00:58 +09:00
},
/**
The `_id` of the parent comment, if there is one
*/
parentCommentId: {
type: String,
// regEx: SimpleSchema.RegEx.Id,
max: 500,
viewableBy: ['guests'],
insertableBy: ['members'],
2016-06-23 15:00:58 +09:00
optional: true,
resolveAs: 'parentComment: Comment',
hidden: true // never show this
2016-06-23 15:00:58 +09:00
},
/**
The `_id` of the top-level parent comment, if there is one
*/
topLevelCommentId: {
type: String,
// regEx: SimpleSchema.RegEx.Id,
max: 500,
viewableBy: ['guests'],
insertableBy: ['members'],
2016-06-23 15:00:58 +09:00
optional: true,
resolveAs: 'topLevelComment: Comment',
hidden: true // never show this
2016-06-23 15:00:58 +09:00
},
/**
The timestamp of comment creation
*/
createdAt: {
type: Date,
optional: true,
viewableBy: ['admins'],
autoValue: (documentOrModifier) => {
if (documentOrModifier && !documentOrModifier.$set) return new Date() // if this is an insert, set createdAt to current timestamp
}
2016-06-23 15:00:58 +09:00
},
/**
The timestamp of the comment being posted. For now, comments are always created and posted at the same time
*/
postedAt: {
type: Date,
optional: true,
viewableBy: ['guests'],
autoValue: (documentOrModifier) => {
if (documentOrModifier && !documentOrModifier.$set) return new Date() // if this is an insert, set createdAt to current timestamp
}
2016-06-23 15:00:58 +09:00
},
/**
The comment body (Markdown)
*/
body: {
type: String,
max: 3000,
viewableBy: ['guests'],
insertableBy: ['members'],
editableBy: ['members'],
2016-06-23 15:00:58 +09:00
control: "textarea"
},
/**
The HTML version of the comment body
*/
htmlBody: {
type: String,
optional: true,
viewableBy: ['guests'],
2016-06-23 15:00:58 +09:00
},
/**
The comment author's name
*/
author: {
type: String,
optional: true,
viewableBy: ['guests'],
autoValue: (documentOrModifier) => {
// if userId is changing, change the author name too
const userId = documentOrModifier.userId || documentOrModifier.$set && documentOrModifier.$set.userId
if (userId) return Users.getDisplayNameById(userId)
}
2016-06-23 15:00:58 +09:00
},
/**
Whether the comment is inactive. Inactive comments' scores gets recalculated less often
*/
inactive: {
type: Boolean,
optional: true,
viewableBy: ['guests'],
2016-06-23 15:00:58 +09:00
},
/**
The post's `_id`
*/
postId: {
type: String,
optional: true,
viewableBy: ['guests'],
insertableBy: ['members'],
2016-06-23 15:00:58 +09:00
// regEx: SimpleSchema.RegEx.Id,
max: 500,
resolveAs: 'post: Post',
hidden: true // never show this
2016-06-23 15:00:58 +09:00
},
/**
The comment author's `_id`
*/
userId: {
type: String,
optional: true,
viewableBy: ['guests'],
insertableBy: ['members'],
hidden: true,
resolveAs: 'user: User',
2016-06-23 15:00:58 +09:00
},
/**
Whether the comment is deleted. Delete comments' content doesn't appear on the site.
2016-06-23 15:00:58 +09:00
*/
isDeleted: {
type: Boolean,
optional: true,
viewableBy: ['guests'],
2016-06-23 15:00:58 +09:00
},
userIP: {
type: String,
optional: true,
viewableBy: ['admins'],
2016-06-23 15:00:58 +09:00
},
userAgent: {
type: String,
optional: true,
viewableBy: ['admins'],
2016-06-23 15:00:58 +09:00
},
referrer: {
type: String,
optional: true,
viewableBy: ['admins'],
2016-06-23 15:00:58 +09:00
}
};
2016-06-23 15:00:58 +09:00
export default schema;