fix #74
This commit is contained in:
parent
74b6e76619
commit
0ce28e6d05
|
@ -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 = `
|
||||
<div class="load-more-comments">
|
||||
<a href="${parent_id}">load more comments (${comments.count})</a>
|
||||
<a href="${load_comms_href}">load more comments (${comments.count})</a>
|
||||
</div>
|
||||
`
|
||||
} 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 + '</details></div>'
|
||||
} 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 += `
|
||||
<div class="load-more-comments">
|
||||
<a href="${parent_id}">load more comments (${comment.count})</a>
|
||||
<a href="${load_comms_href}">load more comments (${comment.count})</a>
|
||||
</div>
|
||||
`
|
||||
} else {
|
||||
|
|
|
@ -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 = `<div class="comments">`
|
||||
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 += `</div>`
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue