From 0ce28e6d0532209968d08d1e3c62d750d48a4ddd Mon Sep 17 00:00:00 2001 From: teddit Date: Wed, 23 Dec 2020 19:42:53 +0100 Subject: [PATCH] fix #74 --- inc/compilePostComments.js | 21 +++++++++++++++------ inc/processJsonPost.js | 4 ++-- routes.js | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/inc/compilePostComments.js b/inc/compilePostComments.js index dcab27d..d014c9b 100644 --- a/inc/compilePostComments.js +++ b/inc/compilePostComments.js @@ -1,9 +1,8 @@ module.exports = function() { - this.compilePostCommentsHtml = (comments, next_comment, post_id, post_url, morechildren_ids, post_author) => { + this.compilePostCommentsHtml = (comments, next_comment, post_id, post_url, morechildren_ids, post_author, viewing_comment) => { return new Promise((resolve, reject) => { (async () => { let comments_html - function commentAuthor(comment, classlist, submitter, moderator) { let classes = classlist.join(' ') if (comment.author === '[deleted]') @@ -71,9 +70,14 @@ module.exports = function() { ` } else { if(!morechildren_ids) { + let load_comms_href = parent_id + + if(viewing_comment) + load_comms_href = '../' + parent_id + comments_html = `
- load more comments (${comments.count}) + load more comments (${comments.count})
` } else { @@ -152,17 +156,22 @@ module.exports = function() { if(comment.replies[j+1]) { next_reply = comment.replies[j+1] } - replies_html += await compilePostCommentsHtml(comment.replies[j], next_reply, post_id, post_url, null, post_author) + replies_html += await compilePostCommentsHtml(comment.replies[j], next_reply, post_id, post_url, null, post_author, viewing_comment) } } } comments_html += replies_html + '' } else { if(comment.children.length > 0) { - let parent_id = comment.parent_id.split('_')[1] + let parent_id = comment.parent_id.split('_')[1] + let load_comms_href = parent_id + + if(viewing_comment) + load_comms_href = '../' + parent_id + comments_html += `
- load more comments (${comment.count}) + load more comments (${comment.count})
` } else { diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index b9f7e24..baa503c 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -186,7 +186,7 @@ module.exports = function(fetch) { }) } - this.finalizeJsonPost = async (processed_json, post_id, post_url, morechildren_ids) => { + this.finalizeJsonPost = async (processed_json, post_id, post_url, morechildren_ids, viewing_comment) => { let comments_html = `
` let comments = processed_json.comments for(var i = 0; i < comments.length; i++) { @@ -194,7 +194,7 @@ module.exports = function(fetch) { if(comments[i+1]) { next_comment = comments[i+1] } - comments_html += await compilePostCommentsHtml(comments[i], next_comment, post_id, post_url, morechildren_ids, processed_json.author) + comments_html += await compilePostCommentsHtml(comments[i], next_comment, post_id, post_url, morechildren_ids, processed_json.author, viewing_comment) } comments_html += `
` diff --git a/routes.js b/routes.js index b511427..60024c0 100644 --- a/routes.js +++ b/routes.js @@ -493,7 +493,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { (async () => { if(!more_comments_cursor) { let processed_json = await processJsonPost(json, false) - let finalized_json = await finalizeJsonPost(processed_json, id, post_url) + let finalized_json = await finalizeJsonPost(processed_json, id, post_url, null, viewing_comment) return res.render('post', { post: finalized_json.post_data, comments: finalized_json.comments, @@ -558,7 +558,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { console.log(`Fetched the JSON from reddit.com${comments_url}.`); (async () => { let processed_json = await processJsonPost(json, true) - let finalized_json = await finalizeJsonPost(processed_json, id, post_url) + let finalized_json = await finalizeJsonPost(processed_json, id, post_url, null, viewing_comment) return res.render('post', { post: finalized_json.post_data, comments: finalized_json.comments,