Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request VulcanJS#214 from yeputons/safe-notifications-209
Browse files Browse the repository at this point in the history
For for VulcanJS#209: createNotifications() is a server-side function now
  • Loading branch information
SachaG committed Jan 5, 2014
2 parents 1a72e0e + 2f2b5d4 commit c536750
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 62 deletions.
69 changes: 36 additions & 33 deletions collections/comments.js
Expand Up @@ -81,41 +81,44 @@ Meteor.methods({
properties.parentAuthorId = parentComment.userId; properties.parentAuthorId = parentComment.userId;
properties.parentAuthorName = getDisplayName(parentUser); properties.parentAuthorName = getDisplayName(parentUser);


// reply notification if(!this.isSimulation){
// do not notify users of their own actions (i.e. they're replying to themselves) // reply notification
if(parentUser._id != user._id){ // do not notify users of their own actions (i.e. they're replying to themselves)
Meteor.call('createNotification', { if(parentUser._id != user._id){
event: 'newReply', createNotification({
properties: properties, event: 'newReply',
userToNotify: parentUser, properties: properties,
userDoingAction: user, userToNotify: parentUser,
sendEmail: getUserSetting('notifications.replies', false, parentUser) userDoingAction: user,
}); sendEmail: getUserSetting('notifications.replies', false, parentUser)
});
}

// comment notification
// if the original poster is different from the author of the parent comment, notify them too
if(postUser._id != user._id && parentComment.userId != post.userId){
createNotification({
event: 'newComment',
properties: properties,
userToNotify: postUser,
userDoingAction: user,
sendEmail: getUserSetting('notifications.comments', false, postUser)
});
}
} }

// comment notification
// if the original poster is different from the author of the parent comment, notify them too
if(postUser._id != user._id && parentComment.userId != post.userId){
Meteor.call('createNotification', {
event: 'newComment',
properties: properties,
userToNotify: postUser,
userDoingAction: user,
sendEmail: getUserSetting('notifications.comments', false, postUser)
});
}

}else{ }else{
// root comment if(!this.isSimulation){
// don't notify users of their own comments // root comment
if(postUser._id != user._id){ // don't notify users of their own comments
Meteor.call('createNotification', { if(postUser._id != user._id){
event: 'newComment', createNotification({
properties: properties, event: 'newComment',
userToNotify: postUser, properties: properties,
userDoingAction: Meteor.user(), userToNotify: postUser,
sendEmail: getUserSetting('notifications.comments', false, postUser) userDoingAction: Meteor.user(),
}); sendEmail: getUserSetting('notifications.comments', false, postUser)
});
}
} }
} }
} }
Expand Down
2 changes: 1 addition & 1 deletion server/invites.js
Expand Up @@ -24,7 +24,7 @@ Meteor.methods({
}}); }});
console.log(a) console.log(a)


Meteor.call('createNotification', { createNotification({
event: 'accountApproved', event: 'accountApproved',
properties: {}, properties: {},
userToNotify: invitedUser, userToNotify: invitedUser,
Expand Down
57 changes: 29 additions & 28 deletions server/notifications.js
Expand Up @@ -2,35 +2,36 @@ getUnsubscribeLink = function(user){
return Meteor.absoluteUrl()+'unsubscribe/'+user.email_hash; return Meteor.absoluteUrl()+'unsubscribe/'+user.email_hash;
}; };


Meteor.methods({ createNotification = function(options) {
createNotification: function(options){ var event = options.event,
var event = options.event, properties = options.properties,
properties = options.properties, userToNotify = options.userToNotify,
userToNotify = options.userToNotify, userDoingAction = options.userDoingAction,
userDoingAction = options.userDoingAction, sendEmail = options.sendEmail;
sendEmail = options.sendEmail; // console.log('adding new notification for:'+getDisplayName(userToNotify)+', for event:'+event);
// console.log('adding new notification for:'+getDisplayName(userToNotify)+', for event:'+event); // console.log(userToNotify);
// console.log(userToNotify); // console.log(userDoingAction);
// console.log(userDoingAction); // console.log(properties);
// console.log(properties); // console.log(sendEmail);
// console.log(sendEmail); var notification = {
var notification = { timestamp: new Date().getTime(),
timestamp: new Date().getTime(), userId: userToNotify._id,
userId: userToNotify._id, event: event,
event: event, properties: properties,
properties: properties, read: false
read: false }
} var newNotificationId=Notifications.insert(notification);
var newNotificationId=Notifications.insert(notification);


// send the notification if notifications are activated, // send the notification if notifications are activated,
// the notificationsFrequency is set to 1, or if it's undefined (legacy compatibility) // the notificationsFrequency is set to 1, or if it's undefined (legacy compatibility)
if(sendEmail){ if(sendEmail){
// get specific notification content for "email" context // get specific notification content for "email" context
var contents = getNotificationContents(notification, 'email'); var contents = getNotificationContents(notification, 'email');
sendNotification(contents); sendNotification(contents);
} }
}, }

Meteor.methods({
unsubscribeUser : function(hash){ unsubscribeUser : function(hash){
// TO-DO: currently, if you have somebody's email you can unsubscribe them // TO-DO: currently, if you have somebody's email you can unsubscribe them
// A user-specific salt should be added to the hashing method to prevent this // A user-specific salt should be added to the hashing method to prevent this
Expand Down

0 comments on commit c536750

Please sign in to comment.