2015-04-23 16:53:20 +09:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------- //
|
|
|
|
// ------------------------------------------ Hooks ------------------------------------------ //
|
|
|
|
// ------------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
Comments.before.insert(function (userId, doc) {
|
|
|
|
// note: only actually sanitizes on the server
|
|
|
|
doc.htmlBody = Telescope.utils.sanitize(marked(doc.body));
|
|
|
|
});
|
|
|
|
|
2015-05-01 18:22:00 +02:00
|
|
|
Comments.before.update(function (userId, doc, fieldNames, modifier) {
|
2015-04-23 16:53:20 +09:00
|
|
|
// if body is being modified, update htmlBody too
|
|
|
|
if (Meteor.isServer && modifier.$set && modifier.$set.body) {
|
|
|
|
modifier.$set = modifier.$set || {};
|
|
|
|
modifier.$set.htmlBody = Telescope.utils.sanitize(marked(modifier.$set.body));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function afterCommentOperations (comment) {
|
|
|
|
|
2015-06-21 11:58:46 +09:00
|
|
|
var userId = comment.userId;
|
2015-04-23 16:53:20 +09:00
|
|
|
|
|
|
|
// increment comment count
|
|
|
|
Meteor.users.update({_id: userId}, {
|
2015-04-28 10:12:35 +09:00
|
|
|
$inc: {'telescope.commentCount': 1}
|
2015-04-23 16:53:20 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// update post
|
|
|
|
Posts.update(comment.postId, {
|
|
|
|
$inc: {commentCount: 1},
|
|
|
|
$set: {lastCommentedAt: new Date()},
|
|
|
|
$addToSet: {commenters: userId}
|
|
|
|
});
|
|
|
|
|
2015-06-21 11:58:46 +09:00
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
Telescope.callbacks.add("commentSubmitAsync", afterCommentOperations);
|
|
|
|
|
|
|
|
function upvoteOwnComment (comment) {
|
|
|
|
|
|
|
|
var commentAuthor = Meteor.users.findOne(comment.userId);
|
|
|
|
|
2015-04-23 16:53:20 +09:00
|
|
|
// upvote comment
|
|
|
|
Telescope.upvoteItem(Comments, comment, commentAuthor);
|
|
|
|
|
|
|
|
return comment;
|
2015-05-01 18:22:00 +02:00
|
|
|
}
|
2015-06-24 15:38:14 +09:00
|
|
|
Telescope.callbacks.add("commentSubmitAsync", upvoteOwnComment);
|