diff --git a/controllers/resources.js b/controllers/resources.js index ec1d7466f2..f4db69018f 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -291,11 +291,6 @@ module.exports = { }) }, - getAllCourses: function() { - "use strict"; - return coursewares; - }, - allCoursewareIds: function() { return coursewares.map(function(elem) { return { diff --git a/controllers/story.js b/controllers/story.js index f788670330..02ff3f2493 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -154,6 +154,7 @@ exports.returnIndividualStory = function(req, res, next) { res.render('stories/index', { title: story.headline, link: story.link, + originalStoryLink: dashedName, author: story.author, description: story.description, rank: story.upVotes.length, @@ -377,6 +378,7 @@ exports.commentSubmit = function(req, res, next) { } var comment = new Comment({ associatedPost: data.associatedPost, + originalStoryLink: originalStoryLink, body: sanitizedBody, rank: 0, upvotes: 0, @@ -391,7 +393,6 @@ exports.commentSubmit = function(req, res, next) { exports.commentOnCommentSubmit = function(req, res, next) { var data = req.body.data; - if (req.user._id.toString() !== data.author.userId.toString()) { return next(new Error('Not authorized')); } @@ -412,6 +413,7 @@ exports.commentOnCommentSubmit = function(req, res, next) { body: sanitizedBody, rank: 0, upvotes: 0, + originalStoryLink: data.originalStoryLink, author: data.author, comments: [], topLevel: false, @@ -444,66 +446,25 @@ function commentSave(comment, Context, res, next) { 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) { - return next(err); - } - 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: [ - "Here.", - '- the Volunteer Camp Counselor Team' - ].join('') - }; - console.log('2!'); - transporter.sendMail(mailOptions, function(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: [ - "Here.", - '- the Volunteer Camp Counselor Team' - ].join('') - }; - console.log('2!'); - transporter.sendMail(mailOptions, function(err) { - if (err) { return err; } - done(null, null); - }); + 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 you on Camper News!", + text: [ + "Here.", + '- the Volunteer Camp Counselor Team' + ].join('') + }; + transporter.sendMail(mailOptions, function(err) { + if (err) { return err; } + }); }); }); } catch (e) { diff --git a/models/Comment.js b/models/Comment.js index a3a35fe6fd..fc805594f7 100644 --- a/models/Comment.js +++ b/models/Comment.js @@ -6,6 +6,10 @@ var commentSchema = new mongoose.Schema({ type: String, required: true }, + originalStoryLink: { + type: String, + default: '' + }, body: { type: String, default: '' @@ -36,4 +40,4 @@ module.exports = mongoose.model('Comment', commentSchema); type: mongoose.Schema.Types.ObjectId, ref: 'User' }, - */ \ No newline at end of file + */ diff --git a/public/js/main.js b/public/js/main.js index 5d2fc5e571..9773a633a5 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -281,6 +281,7 @@ $(document).ready(function() { { data: { associatedPost: storyId, + originalStoryLink: originalStoryLink, body: data, author: { picture: user.profile.picture, @@ -295,7 +296,6 @@ $(document).ready(function() { .done(function (data, textStatus, xhr) { window.location.reload(); }); - }; $('#comment-button').on('click', commentSubmitButtonHandler); diff --git a/views/partials/wikis.jade b/views/partials/wikis.jade index 705d2a5683..6e6d817fd1 100644 --- a/views/partials/wikis.jade +++ b/views/partials/wikis.jade @@ -16,6 +16,7 @@ h3 var docfrag = document.createDocumentFragment(); for (var i = 0; i < data.wikiList.length; i++) { var li = document.createElement("li"); + // strike through wikis previously read var linkedName = getLinkedName(data.wikiList[i].name); if (data.completedWikis.indexOf(data.wikiIds[i]) > -1) { $(li).html("" + data.wikiList[i].name + ""); diff --git a/views/stories/comments.jade b/views/stories/comments.jade index 546d843a28..b122fcb6b6 100644 --- a/views/stories/comments.jade +++ b/views/stories/comments.jade @@ -96,6 +96,7 @@ { data: { associatedPost: commentId, + originalStoryLink: originalStoryLink, body: $('#comment-to-comment-textinput').val(), author: { picture: user.profile.picture, diff --git a/views/stories/show.jade b/views/stories/show.jade index dac2842b0b..0d0cf9539a 100644 --- a/views/stories/show.jade +++ b/views/stories/show.jade @@ -1,6 +1,7 @@ .spacer script. var storyId = !{JSON.stringify(id)}; + var originalStoryLink = !{JSON.stringify(originalStoryLink)}; var comments = !{JSON.stringify(comments)}; var upVotes = !{JSON.stringify(upVotes)}; var image = !{JSON.stringify(image)};