still working on passing original author email all the way down the comment chain

This commit is contained in:
Michael Q Larson
2015-04-08 00:30:51 -07:00
parent 1c7d0b11b6
commit 6242f322d7
6 changed files with 51 additions and 8 deletions

View File

@ -155,6 +155,7 @@ exports.returnIndividualStory = function(req, res, next) {
title: story.headline, title: story.headline,
link: story.link, link: story.link,
originalStoryLink: dashedName, originalStoryLink: dashedName,
originalStoryAuthorEmail: story.author.email,
author: story.author, author: story.author,
description: story.description, description: story.description,
rank: story.upVotes.length, rank: story.upVotes.length,
@ -378,7 +379,8 @@ exports.commentSubmit = function(req, res, next) {
} }
var comment = new Comment({ var comment = new Comment({
associatedPost: data.associatedPost, associatedPost: data.associatedPost,
originalStoryLink: originalStoryLink, originalStoryLink: data.originalStoryLink,
originalStoryAuthorEmail: data.originalStoryAuthorEmail,
body: sanitizedBody, body: sanitizedBody,
rank: 0, rank: 0,
upvotes: 0, upvotes: 0,
@ -414,6 +416,7 @@ exports.commentOnCommentSubmit = function(req, res, next) {
rank: 0, rank: 0,
upvotes: 0, upvotes: 0,
originalStoryLink: data.originalStoryLink, originalStoryLink: data.originalStoryLink,
originalStoryAuthorEmail: data.originalStoryAuthorEmail,
author: data.author, author: data.author,
comments: [], comments: [],
topLevel: false, topLevel: false,
@ -446,6 +449,30 @@ function commentSave(comment, Context, res, next) {
if (err) { if (err) {
return next(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({ var transporter = nodemailer.createTransport({
service: 'Mandrill', service: 'Mandrill',
auth: { auth: {
@ -456,11 +483,13 @@ function commentSave(comment, Context, res, next) {
var mailOptions = { var mailOptions = {
to: recipient.email, to: recipient.email,
from: 'Team@freecodecamp.com', 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: [ text: [
"<a href='http://freecodecamp.com/stories/" + comment.originalStoryLink + "'>Here.</a>", "Just a quick heads-up: " + associatedStory.author.username + " replied to you on Camper News.",
'- the Volunteer Camp Counselor Team' "You can keep this conversation going.",
].join('') "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) { transporter.sendMail(mailOptions, function(err) {
if (err) { return err; } if (err) { return err; }
@ -468,7 +497,6 @@ function commentSave(comment, Context, res, next) {
}); });
}); });
} catch (e) { } catch (e) {
debug('hey there\'s error');
// delete comment // delete comment
return next(err); return next(err);
} }

View File

@ -10,6 +10,10 @@ var commentSchema = new mongoose.Schema({
type: String, type: String,
default: '' default: ''
}, },
originalStoryAuthorEmail: {
type: String,
default: ''
},
body: { body: {
type: String, type: String,
default: '' default: ''

View File

@ -23,6 +23,10 @@ var storySchema = new mongoose.Schema({
type: String, type: String,
unique: false unique: false
}, },
originalStoryAuthorEmail: {
type: String,
default: ''
},
rank: { rank: {
type: Number, type: Number,
default: -Infinity default: -Infinity

View File

@ -250,10 +250,12 @@ $(document).ready(function() {
timePosted: Date.now(), timePosted: Date.now(),
description: description, description: description,
storyMetaDescription: storyMetaDescription, storyMetaDescription: storyMetaDescription,
originalStoryAuthorEmail: user.email,
rank: 1, rank: 1,
upVotes: [userDataForUpvote], upVotes: [userDataForUpvote],
author: { author: {
picture: user.profile.picture, picture: user.profile.picture,
email: user.email,
userId: user._id, userId: user._id,
username: user.profile.username username: user.profile.username
}, },
@ -282,11 +284,13 @@ $(document).ready(function() {
data: { data: {
associatedPost: storyId, associatedPost: storyId,
originalStoryLink: originalStoryLink, originalStoryLink: originalStoryLink,
originalStoryAuthorEmail: originalStoryAuthorEmail,
body: data, body: data,
author: { author: {
picture: user.profile.picture, picture: user.profile.picture,
userId: user._id, userId: user._id,
username: user.profile.username username: user.profile.username,
email: user.email
} }
} }
}) })

View File

@ -97,11 +97,13 @@
data: { data: {
associatedPost: commentId, associatedPost: commentId,
originalStoryLink: originalStoryLink, originalStoryLink: originalStoryLink,
originalStoryAuthorEmail: originalStoryAuthorEmail,
body: $('#comment-to-comment-textinput').val(), body: $('#comment-to-comment-textinput').val(),
author: { author: {
picture: user.profile.picture, picture: user.profile.picture,
userId: user._id, userId: user._id,
username: user.profile.username username: user.profile.username,
email: user.email
} }
} }
}) })

View File

@ -2,6 +2,7 @@
script. script.
var storyId = !{JSON.stringify(id)}; var storyId = !{JSON.stringify(id)};
var originalStoryLink = !{JSON.stringify(originalStoryLink)}; var originalStoryLink = !{JSON.stringify(originalStoryLink)};
var originalStoryAuthorEmail = !{JSON.stringify(originalStoryAuthorEmail)};
var comments = !{JSON.stringify(comments)}; var comments = !{JSON.stringify(comments)};
var upVotes = !{JSON.stringify(upVotes)}; var upVotes = !{JSON.stringify(upVotes)};
var image = !{JSON.stringify(image)}; var image = !{JSON.stringify(image)};