2013-02-22 15:41:15 +09:00
|
|
|
getUnsubscribeLink = function(user){
|
2014-12-09 09:29:17 -08:00
|
|
|
return getRouteUrl('unsubscribe', {hash: user.email_hash});
|
2013-02-22 15:41:15 +09:00
|
|
|
};
|
|
|
|
|
2014-08-04 10:04:50 +09:00
|
|
|
// given a notification, return the correct subject and html to send an email
|
2014-08-03 11:50:10 +09:00
|
|
|
buildEmailNotification = function (notification) {
|
2014-12-03 00:06:00 -08:00
|
|
|
|
2015-01-20 11:59:40 +09:00
|
|
|
var subject,
|
|
|
|
template,
|
|
|
|
post = notification.data.post,
|
|
|
|
comment = notification.data.comment;
|
2014-12-03 00:06:00 -08:00
|
|
|
|
2014-10-02 16:42:31 -04:00
|
|
|
switch(notification.courier){
|
2015-01-20 11:59:40 +09:00
|
|
|
|
|
|
|
case 'newComment':
|
|
|
|
subject = 'A new comment on your post "' + post.title + '"';
|
|
|
|
template = 'emailNewComment';
|
|
|
|
break;
|
|
|
|
|
2014-08-03 11:50:10 +09:00
|
|
|
case 'newReply':
|
2014-08-04 11:22:43 +09:00
|
|
|
subject = 'Someone replied to your comment on "'+post.title+'"';
|
2014-08-04 09:47:10 +09:00
|
|
|
template = 'emailNewReply';
|
2014-08-03 11:50:10 +09:00
|
|
|
break;
|
|
|
|
|
2015-01-20 11:59:40 +09:00
|
|
|
case 'newCommentSubscribed':
|
|
|
|
subject = 'A new comment on "' + post.title + '"';
|
2014-08-04 09:47:10 +09:00
|
|
|
template = 'emailNewComment';
|
2014-12-03 00:06:00 -08:00
|
|
|
break;
|
2014-08-03 11:50:10 +09:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-02 16:42:31 -04:00
|
|
|
var emailProperties = _.extend(notification.data, {
|
2014-08-04 11:22:43 +09:00
|
|
|
body: marked(comment.body),
|
2014-12-03 00:06:00 -08:00
|
|
|
profileUrl: getProfileUrlBySlugOrId(comment.userId),
|
2014-08-04 11:22:43 +09:00
|
|
|
postCommentUrl: getPostCommentUrl(post._id, comment._id),
|
|
|
|
postLink: getPostLink(post)
|
2014-08-04 09:47:10 +09:00
|
|
|
});
|
2014-08-03 11:50:10 +09:00
|
|
|
|
2014-08-04 11:22:43 +09:00
|
|
|
// console.log(emailProperties)
|
2014-08-03 11:50:10 +09:00
|
|
|
|
2014-08-29 10:23:11 +09:00
|
|
|
var notificationHtml = getEmailTemplate(template)(emailProperties);
|
2014-08-04 09:47:10 +09:00
|
|
|
var html = buildEmailTemplate(notificationHtml);
|
|
|
|
|
|
|
|
return {
|
|
|
|
subject: subject,
|
|
|
|
html: html
|
|
|
|
}
|
2014-09-16 15:18:27 -04:00
|
|
|
};
|
2014-08-03 11:50:10 +09:00
|
|
|
|
2014-01-05 18:44:13 +02:00
|
|
|
Meteor.methods({
|
2013-01-19 21:37:46 +09:00
|
|
|
unsubscribeUser : function(hash){
|
|
|
|
// TO-DO: currently, if you have somebody's email you can unsubscribe them
|
2013-11-18 11:30:58 +09:00
|
|
|
// A user-specific salt should be added to the hashing method to prevent this
|
2013-01-19 21:37:46 +09:00
|
|
|
var user = Meteor.users.findOne({email_hash: hash});
|
|
|
|
if(user){
|
2013-01-19 21:55:10 +09:00
|
|
|
var update = Meteor.users.update(user._id, {
|
2013-11-18 11:30:58 +09:00
|
|
|
$set: {
|
|
|
|
'profile.notifications.users' : 0,
|
|
|
|
'profile.notifications.posts' : 0,
|
|
|
|
'profile.notifications.comments' : 0,
|
|
|
|
'profile.notifications.replies' : 0
|
|
|
|
}
|
2013-01-19 21:37:46 +09:00
|
|
|
});
|
2013-01-19 21:55:10 +09:00
|
|
|
return true;
|
2013-01-19 21:37:46 +09:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-11 23:19:32 +02:00
|
|
|
});
|
2013-11-18 11:30:58 +09:00
|
|
|
|