pass the original story URL to all comments for notification email
This commit is contained in:
@ -291,11 +291,6 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getAllCourses: function() {
|
|
||||||
"use strict";
|
|
||||||
return coursewares;
|
|
||||||
},
|
|
||||||
|
|
||||||
allCoursewareIds: function() {
|
allCoursewareIds: function() {
|
||||||
return coursewares.map(function(elem) {
|
return coursewares.map(function(elem) {
|
||||||
return {
|
return {
|
||||||
|
@ -154,6 +154,7 @@ exports.returnIndividualStory = function(req, res, next) {
|
|||||||
res.render('stories/index', {
|
res.render('stories/index', {
|
||||||
title: story.headline,
|
title: story.headline,
|
||||||
link: story.link,
|
link: story.link,
|
||||||
|
originalStoryLink: dashedName,
|
||||||
author: story.author,
|
author: story.author,
|
||||||
description: story.description,
|
description: story.description,
|
||||||
rank: story.upVotes.length,
|
rank: story.upVotes.length,
|
||||||
@ -377,6 +378,7 @@ exports.commentSubmit = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
var comment = new Comment({
|
var comment = new Comment({
|
||||||
associatedPost: data.associatedPost,
|
associatedPost: data.associatedPost,
|
||||||
|
originalStoryLink: originalStoryLink,
|
||||||
body: sanitizedBody,
|
body: sanitizedBody,
|
||||||
rank: 0,
|
rank: 0,
|
||||||
upvotes: 0,
|
upvotes: 0,
|
||||||
@ -391,7 +393,6 @@ exports.commentSubmit = function(req, res, next) {
|
|||||||
|
|
||||||
exports.commentOnCommentSubmit = function(req, res, next) {
|
exports.commentOnCommentSubmit = function(req, res, next) {
|
||||||
var data = req.body.data;
|
var data = req.body.data;
|
||||||
|
|
||||||
if (req.user._id.toString() !== data.author.userId.toString()) {
|
if (req.user._id.toString() !== data.author.userId.toString()) {
|
||||||
return next(new Error('Not authorized'));
|
return next(new Error('Not authorized'));
|
||||||
}
|
}
|
||||||
@ -412,6 +413,7 @@ exports.commentOnCommentSubmit = function(req, res, next) {
|
|||||||
body: sanitizedBody,
|
body: sanitizedBody,
|
||||||
rank: 0,
|
rank: 0,
|
||||||
upvotes: 0,
|
upvotes: 0,
|
||||||
|
originalStoryLink: data.originalStoryLink,
|
||||||
author: data.author,
|
author: data.author,
|
||||||
comments: [],
|
comments: [],
|
||||||
topLevel: false,
|
topLevel: false,
|
||||||
@ -441,17 +443,6 @@ function commentSave(comment, Context, res, next) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
User.findOne({'profile.username': associatedStory.author.username}, function(err, recipient) {
|
User.findOne({'profile.username': associatedStory.author.username}, function(err, recipient) {
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
Comment.findById(associatedStory._id, function(err, originalStory) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
debug('is it a comment?', originalStory);
|
|
||||||
if (!originalStory) {
|
|
||||||
Story.findById(associatedStory.associatedPost, function(err, originalStory) {
|
|
||||||
debug('is it a story?', originalStory);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
@ -462,47 +453,17 @@ function commentSave(comment, Context, res, next) {
|
|||||||
pass: secrets.mandrill.password
|
pass: secrets.mandrill.password
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log('1!');
|
|
||||||
var mailOptions = {
|
var mailOptions = {
|
||||||
to: recipient.email,
|
to: recipient.email,
|
||||||
from: 'Team@freecodecamp.com',
|
from: 'Team@freecodecamp.com',
|
||||||
subject: originalStory.author.username + " replied to you on Camper News!",
|
subject: associatedStory.author.username + " replied to you on Camper News!",
|
||||||
text: [
|
text: [
|
||||||
"<a href='http://freecodecamp.com/stories/" + originalStory.storyLink + "'>Here.</a>",
|
"<a href='http://freecodecamp.com/stories/" + comment.originalStoryLink + "'>Here.</a>",
|
||||||
'- the Volunteer Camp Counselor Team'
|
'- the Volunteer Camp Counselor Team'
|
||||||
].join('')
|
].join('')
|
||||||
};
|
};
|
||||||
console.log('2!');
|
|
||||||
transporter.sendMail(mailOptions, function(err) {
|
transporter.sendMail(mailOptions, function(err) {
|
||||||
if (err) { return err; }
|
if (err) { return err; }
|
||||||
done(null, null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log('definitely a comment');
|
|
||||||
var transporter = nodemailer.createTransport({
|
|
||||||
service: 'Mandrill',
|
|
||||||
auth: {
|
|
||||||
user: secrets.mandrill.user,
|
|
||||||
pass: secrets.mandrill.password
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log('1!');
|
|
||||||
var mailOptions = {
|
|
||||||
to: recipient.email,
|
|
||||||
from: 'Team@freecodecamp.com',
|
|
||||||
subject: originalStory.author.username + " replied to you on Camper News!",
|
|
||||||
text: [
|
|
||||||
"<a href='http://freecodecamp.com/stories/" + originalStory.storyLink + "'>Here.</a>",
|
|
||||||
'- the Volunteer Camp Counselor Team'
|
|
||||||
].join('')
|
|
||||||
};
|
|
||||||
console.log('2!');
|
|
||||||
transporter.sendMail(mailOptions, function(err) {
|
|
||||||
if (err) { return err; }
|
|
||||||
done(null, null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,10 @@ var commentSchema = new mongoose.Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
originalStoryLink: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
body: {
|
body: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
|
@ -281,6 +281,7 @@ $(document).ready(function() {
|
|||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
associatedPost: storyId,
|
associatedPost: storyId,
|
||||||
|
originalStoryLink: originalStoryLink,
|
||||||
body: data,
|
body: data,
|
||||||
author: {
|
author: {
|
||||||
picture: user.profile.picture,
|
picture: user.profile.picture,
|
||||||
@ -295,7 +296,6 @@ $(document).ready(function() {
|
|||||||
.done(function (data, textStatus, xhr) {
|
.done(function (data, textStatus, xhr) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#comment-button').on('click', commentSubmitButtonHandler);
|
$('#comment-button').on('click', commentSubmitButtonHandler);
|
||||||
|
@ -16,6 +16,7 @@ h3
|
|||||||
var docfrag = document.createDocumentFragment();
|
var docfrag = document.createDocumentFragment();
|
||||||
for (var i = 0; i < data.wikiList.length; i++) {
|
for (var i = 0; i < data.wikiList.length; i++) {
|
||||||
var li = document.createElement("li");
|
var li = document.createElement("li");
|
||||||
|
// strike through wikis previously read
|
||||||
var linkedName = getLinkedName(data.wikiList[i].name);
|
var linkedName = getLinkedName(data.wikiList[i].name);
|
||||||
if (data.completedWikis.indexOf(data.wikiIds[i]) > -1) {
|
if (data.completedWikis.indexOf(data.wikiIds[i]) > -1) {
|
||||||
$(li).html("<a class='strikethrough' href='/wiki/" + linkedName + "'>" + data.wikiList[i].name + "</a></li>");
|
$(li).html("<a class='strikethrough' href='/wiki/" + linkedName + "'>" + data.wikiList[i].name + "</a></li>");
|
||||||
|
@ -96,6 +96,7 @@
|
|||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
associatedPost: commentId,
|
associatedPost: commentId,
|
||||||
|
originalStoryLink: originalStoryLink,
|
||||||
body: $('#comment-to-comment-textinput').val(),
|
body: $('#comment-to-comment-textinput').val(),
|
||||||
author: {
|
author: {
|
||||||
picture: user.profile.picture,
|
picture: user.profile.picture,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
.spacer
|
.spacer
|
||||||
script.
|
script.
|
||||||
var storyId = !{JSON.stringify(id)};
|
var storyId = !{JSON.stringify(id)};
|
||||||
|
var originalStoryLink = !{JSON.stringify(originalStoryLink)};
|
||||||
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)};
|
||||||
|
Reference in New Issue
Block a user