Vulcan/lib/comment.js

31 lines
808 B
JavaScript
Raw Normal View History

2012-08-31 19:41:54 -04:00
Meteor.methods({
comment: function(postId, parentCommentId, text){
2012-08-31 19:41:54 -04:00
var user = Meteor.users.findOne(this.userId());
var comment = {
post: postId
2012-08-31 19:41:54 -04:00
, body: text
2012-10-01 16:08:30 +09:00
, userId: user._id
2012-08-31 19:41:54 -04:00
, submitted: new Date().getTime()
2012-10-01 16:08:30 +09:00
, author: getDisplayName(user)
2012-08-31 19:41:54 -04:00
};
if(parentCommentId)
comment.parent = parentCommentId;
2012-08-31 19:41:54 -04:00
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);
2012-08-31 19:41:54 -04:00
}
});