2015-04-24 09:28:50 +09:00
|
|
|
/**
|
|
|
|
* The global namespace for Comments.
|
|
|
|
* @namespace Comments
|
|
|
|
*/
|
|
|
|
Comments = new Mongo.Collection("comments");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comments schema
|
|
|
|
* @type {SimpleSchema}
|
|
|
|
*/
|
2015-05-11 12:15:10 +09:00
|
|
|
Comments.schema = new SimpleSchema({
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
ID
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
_id: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The `_id` of the parent comment, if there is one
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
parentCommentId: {
|
|
|
|
type: String,
|
2015-05-03 21:22:21 -04:00
|
|
|
editableBy: ["member", "admin"],
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
omit: true // never show this
|
|
|
|
}
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The `_id` of the top-level parent comment, if there is one
|
|
|
|
*/
|
2015-05-05 16:45:53 -07:00
|
|
|
topLevelCommentId: {
|
|
|
|
type: String,
|
|
|
|
editableBy: ["member", "admin"],
|
2015-05-05 17:10:19 -07:00
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
omit: true // never show this
|
|
|
|
}
|
2015-05-05 16:45:53 -07:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The timestamp of comment creation
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
createdAt: {
|
|
|
|
type: Date,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The timestamp of the comment being posted. For now, comments are always created and posted at the same time
|
|
|
|
*/
|
|
|
|
postedAt: {
|
2015-04-22 07:50:26 +09:00
|
|
|
type: Date,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The comment body (Markdown)
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
body: {
|
|
|
|
type: String,
|
2015-04-28 17:15:53 +09:00
|
|
|
editableBy: ["member", "admin"],
|
2015-04-28 09:44:43 +09:00
|
|
|
autoform: {
|
|
|
|
rows: 5
|
|
|
|
}
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The HTML version of the comment body
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
htmlBody: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The comment's base score (doesn't factor in comment age)
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
baseScore: {
|
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The comment's current score (factors in comment age)
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
score: {
|
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The number of upvotes the comment has received
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
upvotes: {
|
|
|
|
type: Number,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
An array containing the `_id`s of upvoters
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
upvoters: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: [String],
|
2015-04-22 07:50:26 +09:00
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The number of downvotes the comment has received
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
downvotes: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: Number,
|
|
|
|
optional: true
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
An array containing the `_id`s of downvoters
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
downvoters: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: [String],
|
2015-04-22 07:50:26 +09:00
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The comment author's name
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
author: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Whether the comment is inactive. Inactive comments' scores gets recalculated less often
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
inactive: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The post's `_id`
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
postId: {
|
2015-04-28 09:44:43 +09:00
|
|
|
type: String,
|
2015-04-28 15:54:19 +09:00
|
|
|
optional: true,
|
2015-04-28 17:15:53 +09:00
|
|
|
editableBy: ["member", "admin"], // TODO: should users be able to set postId, but not modify it?
|
2015-04-28 15:54:19 +09:00
|
|
|
autoform: {
|
|
|
|
omit: true // never show this
|
|
|
|
}
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The comment author's `_id`
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
userId: {
|
2015-04-28 09:44:43 +09:00
|
|
|
type: String,
|
2015-04-22 07:50:26 +09:00
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Whether the comment is deleted. Delete comments' content doesn't appear on the site.
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
isDeleted: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-11 12:15:10 +09:00
|
|
|
Comments.schema.internationalize();
|
|
|
|
Comments.attachSchema(Comments.schema);
|
2015-04-25 13:03:04 +09:00
|
|
|
|
2015-04-22 07:50:26 +09:00
|
|
|
Comments.allow({
|
2015-04-28 17:15:53 +09:00
|
|
|
update: _.partial(Telescope.allowCheck, Comments),
|
|
|
|
remove: _.partial(Telescope.allowCheck, Comments)
|
2015-05-03 21:22:21 -04:00
|
|
|
});
|