From 61e07041a749c4e00c2ea7185bd0dbac087f547b Mon Sep 17 00:00:00 2001 From: Michael Q Larson Date: Wed, 8 Apr 2015 13:16:16 -0700 Subject: [PATCH] camper news reply emails go out to original story poster and poster of replied-to comment, works with old stories as well --- controllers/story.js | 63 ++++++++++++++++++++----------------- views/stories/comments.jade | 1 + 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/controllers/story.js b/controllers/story.js index c0eb5cfa8d..15c14b97cf 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -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,41 +459,46 @@ 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: [ "Just a quick heads-up: " + associatedStory.author.username + " replied to you on Camper News.", "You can keep this conversation going.", - "Just head back to the discussion here: http://freecodecamp.com/stories/"+ comment.originalStoryLink, + "Just head back to the discussion here: http://freecodecamp.com/stories/" + comment.originalStoryLink, '- the Free Code Camp Volunteer Team' ].join('\n') }; - transporter.sendMail(mailOptions, function(err) { - if (err) { return err; } + transporter.sendMail(mailOptions, function (err) { + if (err) { + return err; + } }); - } - var transporter = nodemailer.createTransport({ - service: 'Mandrill', - auth: { - user: secrets.mandrill.user, - pass: secrets.mandrill.password + } else { + var transporter = nodemailer.createTransport({ + service: 'Mandrill', + auth: { + user: secrets.mandrill.user, + pass: secrets.mandrill.password + } + }); + var mailOptions = { + to: recipient.email, + from: 'Team@freecodecamp.com', + subject: associatedStory.author.username + " replied to your post on Camper News", + text: [ + "Just a quick heads-up: " + associatedStory.author.username + " replied to you on Camper News.", + "You can keep this conversation going.", + "Just head back to the discussion here: http://freecodecamp.com/stories/" + comment.originalStoryLink, + '- the Free Code Camp Volunteer Team' + ].join('\n') + }; + transporter.sendMail(mailOptions, function (err) { + if (err) { + return err; + } + }); } - }); - var mailOptions = { - to: recipient.email, - from: 'Team@freecodecamp.com', - subject: associatedStory.author.username + " replied to your post on Camper News", - text: [ - "Just a quick heads-up: " + associatedStory.author.username + " replied to you on Camper News.", - "You can keep this conversation going.", - "Just head back to the discussion here: http://freecodecamp.com/stories/"+ comment.originalStoryLink, - '- the Free Code Camp Volunteer Team' - ].join('\n') - }; - transporter.sendMail(mailOptions, function(err) { - if (err) { return err; } - }); }); }); } catch (e) { diff --git a/views/stories/comments.jade b/views/stories/comments.jade index a5df2c97ed..f21f43ac3a 100644 --- a/views/stories/comments.jade +++ b/views/stories/comments.jade @@ -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: {