diff --git a/collections/comments.js b/collections/comments.js index 4eb9d9132..cb56662d4 100644 --- a/collections/comments.js +++ b/collections/comments.js @@ -147,16 +147,20 @@ Meteor.methods({ // -------------------------------- Insert ------------------------------- // - var newCommentId=Comments.insert(comment); + comment._id = Comments.insert(comment); + + // ------------------------------ Callbacks ------------------------------ // + + // run all post submit server callbacks on comment object successively + comment = commentAfterSubmitMethodCallbacks.reduce(function(result, currentFunction) { + return currentFunction(result); + }, comment); // increment comment count Meteor.users.update({_id: user._id}, { $inc: {'data.commentsCount': 1} }); - // extend comment with newly created _id - comment = _.extend(comment, {_id: newCommentId}); - Posts.update(postId, { $inc: {commentsCount: 1}, $set: {lastCommentedAt: now}, diff --git a/collections/posts.js b/collections/posts.js index 80ffd7450..4f19ed331 100644 --- a/collections/posts.js +++ b/collections/posts.js @@ -265,6 +265,13 @@ Meteor.methods({ // console.log(post) post._id = Posts.insert(post); + // ------------------------------ Callbacks ------------------------------ // + + // run all post submit server callbacks on post object successively + post = postAfterSubmitMethodCallbacks.reduce(function(result, currentFunction) { + return currentFunction(result); + }, post); + // ------------------------------ Post-Insert ------------------------------ // // increment posts count diff --git a/packages/telescope-base/lib/base.js b/packages/telescope-base/lib/base.js index 53279aa12..cc547df20 100644 --- a/packages/telescope-base/lib/base.js +++ b/packages/telescope-base/lib/base.js @@ -148,18 +148,22 @@ postMeta = [ postSubmitRenderedCallbacks = []; postSubmitClientCallbacks = []; postSubmitMethodCallbacks = []; +postAfterSubmitMethodCallbacks = []; postEditRenderedCallbacks = []; postEditClientCallbacks = []; postEditMethodCallbacks = []; // not used yet +postAfterMethodCallbacks = []; // not used yet commentSubmitRenderedCallbacks = []; commentSubmitClientCallbacks = []; commentSubmitMethodCallbacks = []; +commentAfterSubmitMethodCallbacks = []; commentEditRenderedCallbacks = []; commentEditClientCallbacks = []; commentEditMethodCallbacks = []; // not used yet +commentAfterEditMethodCallbacks = []; // not used yet // ------------------------------ Dynamic Templates ------------------------------ // diff --git a/packages/telescope-base/package.js b/packages/telescope-base/package.js index 50f164880..080e02859 100644 --- a/packages/telescope-base/package.js +++ b/packages/telescope-base/package.js @@ -28,18 +28,22 @@ Package.onUse(function (api) { 'postSubmitRenderedCallbacks', 'postSubmitClientCallbacks', 'postSubmitMethodCallbacks', + 'postAfterSubmitMethodCallbacks', 'postEditRenderedCallbacks', 'postEditClientCallbacks', 'postEditMethodCallbacks', + 'postAfterEditMethodCallbacks', 'commentSubmitRenderedCallbacks', 'commentSubmitClientCallbacks', 'commentSubmitMethodCallbacks', + 'commentAfterSubmitMethodCallbacks', 'commentEditRenderedCallbacks', 'commentEditClientCallbacks', 'commentEditMethodCallbacks', + 'commentAfterEditMethodCallbacks', 'getTemplate', 'templates', diff --git a/packages/telescope-notifications/lib/notifications.js b/packages/telescope-notifications/lib/notifications.js index 5a392d859..fbac625d5 100644 --- a/packages/telescope-notifications/lib/notifications.js +++ b/packages/telescope-notifications/lib/notifications.js @@ -100,7 +100,7 @@ Meteor.methods({ }); // add new post notification callback on post submit -postSubmitMethodCallbacks.push(function (post) { +postAfterSubmitMethodCallbacks.push(function (post) { if(Meteor.isServer && !!getSetting('emailNotifications', false)){ // we don't want emails to hold up the post submission, so we make the whole thing async with setTimeout Meteor.setTimeout(function () { @@ -111,12 +111,14 @@ postSubmitMethodCallbacks.push(function (post) { }); // add new comment notification callback on comment submit -commentSubmitMethodCallbacks.push(function (comment) { +commentAfterSubmitMethodCallbacks.push(function (comment) { if(Meteor.isServer){ - var post = Posts.findOne(comment.postId); var parentCommentId = comment.parentCommentId; - + var user = Meteor.user(); + var post = Posts.findOne(comment.postId); + var postUser = Meteor.users.findOne(post.userId); + var notificationProperties = { comment: _.pick(comment, '_id', 'userId', 'author', 'body'), post: _.pick(post, '_id', 'title', 'url') @@ -146,4 +148,6 @@ commentSubmitMethodCallbacks.push(function (comment) { createNotification('newComment', notificationProperties, postUser); } } + + return comment; }); \ No newline at end of file