From 6242f322d7bcca743448ef6be7898138d8b1d47c Mon Sep 17 00:00:00 2001 From: Michael Q Larson Date: Wed, 8 Apr 2015 00:30:51 -0700 Subject: [PATCH] still working on passing original author email all the way down the comment chain --- controllers/story.js | 40 +++++++++++++++++++++++++++++++------ models/Comment.js | 4 ++++ models/Story.js | 4 ++++ public/js/main.js | 6 +++++- views/stories/comments.jade | 4 +++- views/stories/show.jade | 1 + 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/controllers/story.js b/controllers/story.js index 02ff3f2493b..c0eb5cfa8dc 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -155,6 +155,7 @@ exports.returnIndividualStory = function(req, res, next) { title: story.headline, link: story.link, originalStoryLink: dashedName, + originalStoryAuthorEmail: story.author.email, author: story.author, description: story.description, rank: story.upVotes.length, @@ -378,7 +379,8 @@ exports.commentSubmit = function(req, res, next) { } var comment = new Comment({ associatedPost: data.associatedPost, - originalStoryLink: originalStoryLink, + originalStoryLink: data.originalStoryLink, + originalStoryAuthorEmail: data.originalStoryAuthorEmail, body: sanitizedBody, rank: 0, upvotes: 0, @@ -414,6 +416,7 @@ exports.commentOnCommentSubmit = function(req, res, next) { rank: 0, upvotes: 0, originalStoryLink: data.originalStoryLink, + originalStoryAuthorEmail: data.originalStoryAuthorEmail, author: data.author, comments: [], topLevel: false, @@ -446,6 +449,30 @@ function commentSave(comment, Context, res, next) { if (err) { return next(err); } + if (data.originalStoryAuthorEmail !== recipient.email) { + console.log("in mailer", data); + var transporter = nodemailer.createTransport({ + service: 'Mandrill', + auth: { + user: secrets.mandrill.user, + pass: secrets.mandrill.password + } + }); + var mailOptions = { + to: data.originalStoryAuthorEmail, + 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 transporter = nodemailer.createTransport({ service: 'Mandrill', auth: { @@ -456,11 +483,13 @@ function commentSave(comment, Context, res, next) { var mailOptions = { to: recipient.email, from: 'Team@freecodecamp.com', - subject: associatedStory.author.username + " replied to you on Camper News!", + subject: associatedStory.author.username + " replied to your post on Camper News", text: [ - "Here.", - '- the Volunteer Camp Counselor Team' - ].join('') + "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; } @@ -468,7 +497,6 @@ function commentSave(comment, Context, res, next) { }); }); } catch (e) { - debug('hey there\'s error'); // delete comment return next(err); } diff --git a/models/Comment.js b/models/Comment.js index fc805594f7a..4a1e15506df 100644 --- a/models/Comment.js +++ b/models/Comment.js @@ -10,6 +10,10 @@ var commentSchema = new mongoose.Schema({ type: String, default: '' }, + originalStoryAuthorEmail: { + type: String, + default: '' + }, body: { type: String, default: '' diff --git a/models/Story.js b/models/Story.js index 13f279de18d..7b60674845d 100644 --- a/models/Story.js +++ b/models/Story.js @@ -23,6 +23,10 @@ var storySchema = new mongoose.Schema({ type: String, unique: false }, + originalStoryAuthorEmail: { + type: String, + default: '' + }, rank: { type: Number, default: -Infinity diff --git a/public/js/main.js b/public/js/main.js index 9773a633a59..00081f0f4b7 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -250,10 +250,12 @@ $(document).ready(function() { timePosted: Date.now(), description: description, storyMetaDescription: storyMetaDescription, + originalStoryAuthorEmail: user.email, rank: 1, upVotes: [userDataForUpvote], author: { picture: user.profile.picture, + email: user.email, userId: user._id, username: user.profile.username }, @@ -282,11 +284,13 @@ $(document).ready(function() { data: { associatedPost: storyId, originalStoryLink: originalStoryLink, + originalStoryAuthorEmail: originalStoryAuthorEmail, body: data, author: { picture: user.profile.picture, userId: user._id, - username: user.profile.username + username: user.profile.username, + email: user.email } } }) diff --git a/views/stories/comments.jade b/views/stories/comments.jade index b122fcb6b64..a5df2c97edd 100644 --- a/views/stories/comments.jade +++ b/views/stories/comments.jade @@ -97,11 +97,13 @@ data: { associatedPost: commentId, originalStoryLink: originalStoryLink, + originalStoryAuthorEmail: originalStoryAuthorEmail, body: $('#comment-to-comment-textinput').val(), author: { picture: user.profile.picture, userId: user._id, - username: user.profile.username + username: user.profile.username, + email: user.email } } }) diff --git a/views/stories/show.jade b/views/stories/show.jade index 0d0cf9539a9..0d093775c19 100644 --- a/views/stories/show.jade +++ b/views/stories/show.jade @@ -2,6 +2,7 @@ script. var storyId = !{JSON.stringify(id)}; var originalStoryLink = !{JSON.stringify(originalStoryLink)}; + var originalStoryAuthorEmail = !{JSON.stringify(originalStoryAuthorEmail)}; var comments = !{JSON.stringify(comments)}; var upVotes = !{JSON.stringify(upVotes)}; var image = !{JSON.stringify(image)};