Skip to content

Commit

Permalink
update email notification logic for new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jshimko committed Jun 6, 2015
1 parent e501f4a commit bb4bafa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/telescope-email/lib/server/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function adminUserCreationNotification (user) {
// send notifications to admins
var admins = Users.adminUsers();
admins.forEach(function(admin){
if(Users.getUserSetting('notifications.users', false, admin)){
if (admin.telescope.notifications.users) {
var emailProperties = {
profileUrl: Users.getProfileUrl(user),
username: Users.getUserName(user)
Expand Down
24 changes: 15 additions & 9 deletions packages/telescope-notifications/lib/notifications.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// add new post notification callback on post submit
function postSubmitNotification (post) {

var adminIds = _.pluck(Meteor.users.find({'isAdmin': true}, {fields: {_id:1}}).fetch(), '_id');
var notifiedUserIds = _.pluck(Meteor.users.find({'profile.notifications.posts': 1}, {fields: {_id:1}}).fetch(), '_id');
var adminIds = _.pluck(Users.find({'isAdmin': true}, {fields: {_id:1}}).fetch(), '_id');
var notifiedUserIds = _.pluck(Users.find({'telescope.notifications.posts': true}, {fields: {_id:1}}).fetch(), '_id');

// remove post author ID from arrays
var adminIds = _.without(adminIds, post.userId);
Expand Down Expand Up @@ -36,11 +36,12 @@ function addCommentNotification (comment) {
comment: _.pick(comment, '_id', 'userId', 'author', 'body'),
post: _.pick(post, '_id', 'userId', 'title', 'url')
},
postAuthor = Users.findOne(post.userId),
userIdsNotified = [];

// 1. Notify author of post
// do not notify author of post if they're the ones posting the comment
if (comment.userId !== 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 (!!postAuthor.telescope.notifications.comments && comment.userId !== postAuthor._id) {

Herald.createNotification(post.userId, {courier: 'newComment', data: notificationData});
userIdsNotified.push(post.userId);
Expand All @@ -56,12 +57,17 @@ function addCommentNotification (comment) {
// (someone could be replying to their own comment)
if (parentComment.userId !== post.userId && parentComment.userId !== comment.userId) {

// add parent comment to notification data
notificationData.parentComment = _.pick(parentComment, '_id', 'userId', 'author');
var parentCommentAuthor = Users.findOne(parentComment.userId);

Herald.createNotification(parentComment.userId, {courier: 'newReply', data: notificationData});
userIdsNotified.push(parentComment.userId);
// do not notify parent comment author if they have reply notifications turned off
if (!!parentCommentAuthor.telescope.notifications.replies) {

// add parent comment to notification data
notificationData.parentComment = _.pick(parentComment, '_id', 'userId', 'author');

Herald.createNotification(parentComment.userId, {courier: 'newReply', data: notificationData});
userIdsNotified.push(parentComment.userId);
}
}

}
Expand Down

0 comments on commit bb4bafa

Please sign in to comment.