diff --git a/app.js b/app.js index 004465f..bfdd898 100644 --- a/app.js +++ b/app.js @@ -131,6 +131,12 @@ const preferencesMiddleware = (req, res, next) => { } } + let collapseChildComments = req.query.collapse_child_comments + if(collapseChildComments) { + req.cookies.collapse_child_comments = collapseChildComments + res.cookie('collapse_child_comments', collapseChildComments, { maxAge: 31536000, httpOnly: true }) + } + next() } diff --git a/inc/compilePostComments.js b/inc/compilePostComments.js index 1f0da40..2f21e79 100644 --- a/inc/compilePostComments.js +++ b/inc/compilePostComments.js @@ -1,5 +1,5 @@ module.exports = function() { - this.compilePostCommentsHtml = (comments, next_comment, post_id, post_url, morechildren_ids, post_author, viewing_comment) => { + this.compilePostCommentsHtml = (comments, next_comment, post_id, post_url, morechildren_ids, post_author, viewing_comment, user_preferences) => { return new Promise((resolve, reject) => { (async () => { let comments_html @@ -10,6 +10,9 @@ module.exports = function() { else return `${comment.author}${submitter || ''}${moderator || ''}` } + + if(!user_preferences) + user_preferences = {} if(comments.author !== undefined && comments.body_html !== undefined) { let classlist = [] @@ -42,7 +45,7 @@ module.exports = function() { } comments_html = `
${commentAuthor(comments, classlist, submitter && submitter_link, moderator && moderator_badge)}
${ups}
@@ -138,7 +141,7 @@ module.exports = function() { } comments_html += `${commentAuthor(comment, classlist, submitter && submitter_link, moderator && moderator_badge)}
${ups}
@@ -164,7 +167,7 @@ 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, viewing_comment) + replies_html += await compilePostCommentsHtml(comment.replies[j], next_reply, post_id, post_url, null, post_author, viewing_comment, user_preferences) } } } diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index 9906181..0909246 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -198,7 +198,7 @@ module.exports = function(fetch) { }) } - this.finalizeJsonPost = async (processed_json, post_id, post_url, morechildren_ids, viewing_comment) => { + this.finalizeJsonPost = async (processed_json, post_id, post_url, morechildren_ids, viewing_comment, user_preferences) => { let comments_html = `