mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Use function foo() {} syntax for all callback functions so they have names
This commit is contained in:
parent
f9386a07bd
commit
193b0a2895
7 changed files with 86 additions and 82 deletions
|
@ -3,7 +3,7 @@ import Posts from "meteor/vulcan:posts";
|
|||
import Comments from '../collection.js';
|
||||
import Users from 'meteor/vulcan:users';
|
||||
|
||||
const CommentsRemovePostCommenters = (comment, currentUser) => {
|
||||
function CommentsRemovePostCommenters (comment, currentUser) {
|
||||
const { userId, postId } = comment;
|
||||
|
||||
// dec user's comment count
|
||||
|
@ -23,11 +23,11 @@ const CommentsRemovePostCommenters = (comment, currentUser) => {
|
|||
});
|
||||
|
||||
return comment;
|
||||
};
|
||||
}
|
||||
|
||||
addCallback("comments.remove.async", CommentsRemovePostCommenters);
|
||||
|
||||
const CommentsRemoveChildrenComments = (comment, currentUser) => {
|
||||
function CommentsRemoveChildrenComments (comment, currentUser) {
|
||||
|
||||
const childrenComments = Comments.find({parentCommentId: comment._id}).fetch();
|
||||
|
||||
|
@ -42,6 +42,6 @@ const CommentsRemoveChildrenComments = (comment, currentUser) => {
|
|||
});
|
||||
|
||||
return comment;
|
||||
};
|
||||
}
|
||||
|
||||
addCallback("comments.remove.async", CommentsRemoveChildrenComments);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { addCallback } from 'meteor/vulcan:core';
|
||||
|
||||
// limit the number of items that can be requested at once
|
||||
const CommentsMaxLimit = (parameters, terms) => {
|
||||
function CommentsMaxLimit (parameters, terms) {
|
||||
var maxLimit = 1000;
|
||||
// if a limit was provided with the terms, add it too (note: limit=0 means "no limit")
|
||||
if (typeof terms.limit !== 'undefined') {
|
||||
|
|
|
@ -11,13 +11,13 @@ import Events from './collection.js';
|
|||
|
||||
*/
|
||||
|
||||
export const sendGoogleAnalyticsRequest = () => {
|
||||
export function sendGoogleAnalyticsRequest () {
|
||||
if (window && window.ga) {
|
||||
window.ga('send', 'pageview', {
|
||||
'page': window.location.pathname
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const initGoogleAnalytics = () => {
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ export const Callbacks = {};
|
|||
*/
|
||||
export const addCallback = function (hook, callback) {
|
||||
|
||||
if (!callback.name) {
|
||||
console.log(`// Warning! You are adding an unnamed callback to ${hook}. Please use the function foo () {} syntax.`);
|
||||
}
|
||||
|
||||
// if callback array doesn't exist yet, initialize it
|
||||
if (typeof Callbacks[hook] === "undefined") {
|
||||
Callbacks[hook] = [];
|
||||
|
|
|
@ -6,96 +6,96 @@ import { createNotification } from './notifications.js';
|
|||
const Comments = Package['vulcan:comments'] ? Package['vulcan:comments'].default : null;
|
||||
const Posts = Package['vulcan:posts'] ? Package['vulcan:posts'].default : null;
|
||||
|
||||
/**
|
||||
* @summary Add notification callback when a post is approved
|
||||
*/
|
||||
function PostsApprovedNotification (post) {
|
||||
const notificationData = {
|
||||
post: _.pick(post, '_id', 'userId', 'title', 'url')
|
||||
};
|
||||
createNotification(post.userId, 'postApproved', notificationData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Add new post notification callback on post submit
|
||||
*/
|
||||
function PostsNewNotifications (post) {
|
||||
|
||||
let adminIds = _.pluck(Users.adminUsers({fields: {_id:1}}), '_id');
|
||||
let notifiedUserIds = _.pluck(Users.find({'notifications_posts': true}, {fields: {_id:1}}).fetch(), '_id');
|
||||
|
||||
const notificationData = {
|
||||
post: _.pick(post, '_id', 'userId', 'title', 'url', 'slug')
|
||||
};
|
||||
|
||||
// remove post author ID from arrays
|
||||
adminIds = _.without(adminIds, post.userId);
|
||||
notifiedUserIds = _.without(notifiedUserIds, post.userId);
|
||||
|
||||
if (post.status === Posts.config.STATUS_PENDING && !!adminIds.length) {
|
||||
// if post is pending, only notify admins
|
||||
createNotification(adminIds, 'newPendingPost', notificationData);
|
||||
} else if (!!notifiedUserIds.length) {
|
||||
// if post is approved, notify everybody
|
||||
createNotification(notifiedUserIds, 'newPost', notificationData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!!Posts) {
|
||||
/**
|
||||
* @summary Add notification callback when a post is approved
|
||||
*/
|
||||
const PostsApprovedNotification = (post) => {
|
||||
const notificationData = {
|
||||
post: _.pick(post, '_id', 'userId', 'title', 'url')
|
||||
};
|
||||
|
||||
createNotification(post.userId, 'postApproved', notificationData);
|
||||
}
|
||||
addCallback("posts.approve.async", PostsApprovedNotification);
|
||||
|
||||
/**
|
||||
* @summary Add new post notification callback on post submit
|
||||
*/
|
||||
const PostsNewNotifications = (post) => {
|
||||
|
||||
let adminIds = _.pluck(Users.adminUsers({fields: {_id:1}}), '_id');
|
||||
let notifiedUserIds = _.pluck(Users.find({'notifications_posts': true}, {fields: {_id:1}}).fetch(), '_id');
|
||||
|
||||
const notificationData = {
|
||||
post: _.pick(post, '_id', 'userId', 'title', 'url', 'slug')
|
||||
};
|
||||
|
||||
// remove post author ID from arrays
|
||||
adminIds = _.without(adminIds, post.userId);
|
||||
notifiedUserIds = _.without(notifiedUserIds, post.userId);
|
||||
|
||||
if (post.status === Posts.config.STATUS_PENDING && !!adminIds.length) {
|
||||
// if post is pending, only notify admins
|
||||
createNotification(adminIds, 'newPendingPost', notificationData);
|
||||
} else if (!!notifiedUserIds.length) {
|
||||
// if post is approved, notify everybody
|
||||
createNotification(notifiedUserIds, 'newPost', notificationData);
|
||||
}
|
||||
|
||||
}
|
||||
addCallback("posts.new.async", PostsNewNotifications);
|
||||
}
|
||||
|
||||
if (!!Comments) {
|
||||
// add new comment notification callback on comment submit
|
||||
const CommentsNewNotifications = (comment) => {
|
||||
// add new comment notification callback on comment submit
|
||||
function CommentsNewNotifications (comment) {
|
||||
|
||||
// note: dummy content has disableNotifications set to true
|
||||
if(Meteor.isServer && !comment.disableNotifications) {
|
||||
// note: dummy content has disableNotifications set to true
|
||||
if(Meteor.isServer && !comment.disableNotifications) {
|
||||
|
||||
const post = Posts.findOne(comment.postId);
|
||||
const postAuthor = Users.findOne(post.userId);
|
||||
const notificationData = {
|
||||
comment: _.pick(comment, '_id', 'userId', 'author', 'htmlBody', 'postId'),
|
||||
post: _.pick(post, '_id', 'userId', 'title', 'url')
|
||||
};
|
||||
const post = Posts.findOne(comment.postId);
|
||||
const postAuthor = Users.findOne(post.userId);
|
||||
const notificationData = {
|
||||
comment: _.pick(comment, '_id', 'userId', 'author', 'htmlBody', 'postId'),
|
||||
post: _.pick(post, '_id', 'userId', 'title', 'url')
|
||||
};
|
||||
|
||||
let userIdsNotified = [];
|
||||
let userIdsNotified = [];
|
||||
|
||||
// 1. Notify author of post (if they have new comment notifications turned on)
|
||||
// but do not notify author of post if they're the ones posting the comment
|
||||
if (Users.getSetting(postAuthor, "notifications_comments", false) && comment.userId !== postAuthor._id) {
|
||||
createNotification(post.userId, 'newComment', notificationData);
|
||||
userIdsNotified.push(post.userId);
|
||||
}
|
||||
// 1. Notify author of post (if they have new comment notifications turned on)
|
||||
// but do not notify author of post if they're the ones posting the comment
|
||||
if (Users.getSetting(postAuthor, "notifications_comments", false) && comment.userId !== postAuthor._id) {
|
||||
createNotification(post.userId, 'newComment', notificationData);
|
||||
userIdsNotified.push(post.userId);
|
||||
}
|
||||
|
||||
// 2. Notify author of comment being replied to
|
||||
if (!!comment.parentCommentId) {
|
||||
// 2. Notify author of comment being replied to
|
||||
if (!!comment.parentCommentId) {
|
||||
|
||||
const parentComment = Comments.findOne(comment.parentCommentId);
|
||||
const parentComment = Comments.findOne(comment.parentCommentId);
|
||||
|
||||
// do not notify author of parent comment if they're also post author or comment author
|
||||
// (someone could be replying to their own comment)
|
||||
if (parentComment.userId !== post.userId && parentComment.userId !== comment.userId) {
|
||||
// do not notify author of parent comment if they're also post author or comment author
|
||||
// (someone could be replying to their own comment)
|
||||
if (parentComment.userId !== post.userId && parentComment.userId !== comment.userId) {
|
||||
|
||||
const parentCommentAuthor = Users.findOne(parentComment.userId);
|
||||
const parentCommentAuthor = Users.findOne(parentComment.userId);
|
||||
|
||||
// do not notify parent comment author if they have reply notifications turned off
|
||||
if (Users.getSetting(parentCommentAuthor, "notifications_replies", false)) {
|
||||
// do not notify parent comment author if they have reply notifications turned off
|
||||
if (Users.getSetting(parentCommentAuthor, "notifications_replies", false)) {
|
||||
|
||||
// add parent comment to notification data
|
||||
notificationData.parentComment = _.pick(parentComment, '_id', 'userId', 'author', 'htmlBody');
|
||||
// add parent comment to notification data
|
||||
notificationData.parentComment = _.pick(parentComment, '_id', 'userId', 'author', 'htmlBody');
|
||||
|
||||
createNotification(parentComment.userId, 'newReply', notificationData);
|
||||
userIdsNotified.push(parentComment.userId);
|
||||
}
|
||||
createNotification(parentComment.userId, 'newReply', notificationData);
|
||||
userIdsNotified.push(parentComment.userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!!Comments) {
|
||||
addCallback("comments.new.async", CommentsNewNotifications);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import { runCallbacksAsync, addCallback, getSetting, Utils } from 'meteor/vulcan
|
|||
/**
|
||||
* @summary Check for duplicate links
|
||||
*/
|
||||
const PostsEditDuplicateLinksCheck = (modifier, post) => {
|
||||
function PostsEditDuplicateLinksCheck (modifier, post) {
|
||||
if(post.url !== modifier.$set.url && !!modifier.$set.url) {
|
||||
Posts.checkForSameUrl(modifier.$set.url);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ addCallback("posts.edit.sync", PostsEditRunPostApprovedSyncCallbacks);
|
|||
/**
|
||||
* @summary If title is changing, return new slug
|
||||
*/
|
||||
const PostsEditSlugify = (modifier, post) => {
|
||||
function PostsEditSlugify (modifier, post) {
|
||||
if (modifier.$set && modifier.$set.title) {
|
||||
modifier.$set.slug = Utils.slugify(modifier.$set.title);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ addCallback("posts.edit.sync", PostsEditSlugify);
|
|||
/**
|
||||
* @summary If body is changing, update related fields (htmlBody & excerpt)
|
||||
*/
|
||||
const PostsEditHTMLContent = (modifier, post) => {
|
||||
function PostsEditHTMLContent (modifier, post) {
|
||||
if (modifier.$set && typeof modifier.$set.body !== 'undefined') {
|
||||
// excerpt length is configurable via the settings (30 words by default, ~255 characters)
|
||||
const excerptLength = getSetting('postExcerptLength', 30);
|
||||
|
|
|
@ -71,7 +71,7 @@ addCallback("posts.new.sync", PostsNewSetFuture);
|
|||
/**
|
||||
* @summary Set the post's slug based on its title
|
||||
*/
|
||||
const PostsNewSlugify = post => {
|
||||
function PostsNewSlugify (post) {
|
||||
post.slug = Utils.slugify(post.title);
|
||||
return post;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ addCallback("posts.new.sync", PostsNewSlugify);
|
|||
/**
|
||||
* @summary Set the post's HTML content & the excerpt based on its possible body
|
||||
*/
|
||||
const PostsNewHTMLContent = post => {
|
||||
function PostsNewHTMLContent (post) {
|
||||
if (post.body) {
|
||||
// excerpt length is configurable via the settings (30 words by default, ~255 characters)
|
||||
const excerptLength = getSetting('postExcerptLength', 30);
|
||||
|
|
Loading…
Add table
Reference in a new issue