Vulcan/lib/comment.js
Tom Coleman 3d7f2b4afd Moved post creation logic to the server side.
Also made it + commenting latency compensated.
2012-10-04 11:45:12 +10:00

30 lines
808 B
JavaScript

Meteor.methods({
comment: function(postId, parentCommentId, text){
var user = Meteor.users.findOne(this.userId());
var comment = {
post: postId
, body: text
, userId: user._id
, submitted: new Date().getTime()
, author: getDisplayName(user)
};
if(parentCommentId)
comment.parent = parentCommentId;
var newCommentId=Comments.insert(comment);
Posts.update(postId, {$inc: {comments: 1}});
Meteor.call('upvoteComment', newCommentId);
return newCommentId;
},
removeComment: function(commentId){
var comment=Comments.findOne(commentId);
// decrement post comment count
Posts.update(comment.post, {$inc: {comments: -1}});
// note: should we also decrease user's comment karma ?
Comments.remove(commentId);
}
});