camper news reply emails go out to original story poster and poster of replied-to comment, works with old stories as well

This commit is contained in:
Michael Q Larson
2015-04-08 13:16:16 -07:00
parent 889de9c875
commit 61e07041a7
2 changed files with 35 additions and 29 deletions

View File

@ -155,7 +155,7 @@ exports.returnIndividualStory = function(req, res, next) {
title: story.headline,
link: story.link,
originalStoryLink: dashedName,
originalStoryAuthorEmail: story.author.email,
originalStoryAuthorEmail: story.author.email || "",
author: story.author,
description: story.description,
rank: story.upVotes.length,
@ -345,7 +345,8 @@ exports.storySubmission = function(req, res, next) {
comments: [],
image: data.image,
storyLink: storyLink,
metaDescription: data.storyMetaDescription
metaDescription: data.storyMetaDescription,
originalStoryAuthorEmail: req.user.email
});
req.user.progressTimestamps.push(Date.now());
@ -449,8 +450,7 @@ function commentSave(comment, Context, res, next) {
if (err) {
return next(err);
}
if (data.originalStoryAuthorEmail !== recipient.email) {
console.log("in mailer", data);
if (data.originalStoryAuthorEmail && (data.originalStoryAuthorEmail !== recipient.email)) {
var transporter = nodemailer.createTransport({
service: 'Mandrill',
auth: {
@ -459,7 +459,7 @@ function commentSave(comment, Context, res, next) {
}
});
var mailOptions = {
to: data.originalStoryAuthorEmail,
to: data.originalStoryAuthorEmail + ',' + recipient.email,
from: 'Team@freecodecamp.com',
subject: associatedStory.author.username + " replied to your post on Camper News",
text: [
@ -470,9 +470,11 @@ function commentSave(comment, Context, res, next) {
].join('\n')
};
transporter.sendMail(mailOptions, function (err) {
if (err) { return err; }
});
if (err) {
return err;
}
});
} else {
var transporter = nodemailer.createTransport({
service: 'Mandrill',
auth: {
@ -492,8 +494,11 @@ function commentSave(comment, Context, res, next) {
].join('\n')
};
transporter.sendMail(mailOptions, function (err) {
if (err) { return err; }
if (err) {
return err;
}
});
}
});
});
} catch (e) {

View File

@ -92,6 +92,7 @@
});
var submitCommentToCommentHandler = function submitCommentToCommentHandler() {
$('#submit-comment-to-comment').unbind('click');
console.log('in comments.jade', originalStoryAuthorEmail);
$.post('/stories/comment/' + commentId + '/comment',
{
data: {