mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Renaming callbacks and adding new ones
This commit is contained in:
parent
2a911217e9
commit
8625e06045
5 changed files with 31 additions and 8 deletions
|
@ -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},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ------------------------------ //
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
});
|
Loading…
Add table
Reference in a new issue