2015-04-22 07:50:11 +09:00
|
|
|
getUnsubscribeLink = function(user){
|
2015-05-06 12:16:50 +09:00
|
|
|
return Telescope.utils.getRouteUrl('unsubscribe', {hash: user.telescope.emailHash});
|
2015-04-22 07:50:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
// given a notification, return the correct subject and html to send an email
|
|
|
|
buildEmailNotification = function (notification) {
|
|
|
|
|
|
|
|
var subject,
|
|
|
|
template,
|
|
|
|
post = notification.data.post,
|
|
|
|
comment = notification.data.comment;
|
|
|
|
|
|
|
|
switch(notification.courier){
|
|
|
|
|
|
|
|
case 'newComment':
|
|
|
|
subject = notification.author()+' left a new comment on your post "' + post.title + '"';
|
|
|
|
template = 'emailNewComment';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'newReply':
|
|
|
|
subject = notification.author()+' replied to your comment on "'+post.title+'"';
|
|
|
|
template = 'emailNewReply';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'newCommentSubscribed':
|
|
|
|
subject = notification.author()+' left a new comment on "' + post.title + '"';
|
|
|
|
template = 'emailNewComment';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var emailProperties = _.extend(notification.data, {
|
|
|
|
body: marked(comment.body),
|
|
|
|
profileUrl: Users.getProfileUrlBySlugOrId(comment.userId),
|
|
|
|
postCommentUrl: Telescope.utils.getPostCommentUrl(post._id, comment._id),
|
|
|
|
postLink: Posts.getLink(post)
|
|
|
|
});
|
|
|
|
|
|
|
|
// console.log(emailProperties)
|
|
|
|
|
|
|
|
var notificationHtml = getEmailTemplate(template)(emailProperties);
|
|
|
|
var html = buildEmailTemplate(notificationHtml);
|
|
|
|
|
|
|
|
return {
|
|
|
|
subject: subject,
|
|
|
|
html: html
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
Meteor.methods({
|
|
|
|
unsubscribeUser : function(hash){
|
|
|
|
// 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
|
2015-05-06 12:16:50 +09:00
|
|
|
var user = Meteor.users.findOne({"telescope.emailHash": hash});
|
2015-04-22 07:50:11 +09:00
|
|
|
if(user){
|
2015-05-01 18:22:00 +02:00
|
|
|
Meteor.users.update(user._id, {
|
2015-04-22 07:50:11 +09:00
|
|
|
$set: {
|
|
|
|
'profile.notifications.users' : 0,
|
|
|
|
'profile.notifications.posts' : 0,
|
|
|
|
'profile.notifications.comments' : 0,
|
|
|
|
'profile.notifications.replies' : 0
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|