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

pull/320/head
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,
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: [
"<a href='http://freecodecamp.com/stories/" + comment.originalStoryLink + "'>Here.</a>",
'- 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);
}

View File

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

View File

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

View File

@ -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
}
}
})

View File

@ -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
}
}
})

View File

@ -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)};