From ad125a592b8a71db4ffd4ff117d5f36614ec2097 Mon Sep 17 00:00:00 2001 From: teddit Date: Sun, 22 Nov 2020 19:57:17 +0100 Subject: [PATCH] add [score hidden] feature for comments --- inc/compilePostComments.js | 23 +++++++++++++++++------ inc/processJsonPost.js | 4 ++++ routes.js | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/inc/compilePostComments.js b/inc/compilePostComments.js index 37d940c..930613e 100644 --- a/inc/compilePostComments.js +++ b/inc/compilePostComments.js @@ -19,18 +19,23 @@ module.exports = function() { moderator_badge = ` [M]` moderator = true } + if(comments.score_hidden) { + ups = `[score hidden]` + } else { + ups = `${kFormatter(comments.ups)} points` + } comments_html = `
${comments.author}${moderator ? moderator_badge : ''} -

${kFormatter(comments.ups)} points

+

${ups}

${timeDifference(comments.created)}

${comments.stickied ? 'stickied comment' : ''}

${comments.author}${submitter ? submitter_link : ''}${moderator ? moderator_badge : ''}

-

${kFormatter(comments.ups)} points

+

${ups}

${timeDifference(comments.created)}

@@ -84,29 +89,35 @@ module.exports = function() { let submitter_link = '' let moderator = false let submitter = false - + let ups = '' + if(post_author === comment.author) { classlist.push('submitter') submitter_link = `[S]` submitter = true } - if(comments.distinguished === 'moderator') { + if(comment.distinguished === 'moderator') { classlist.push('green') moderator_badge = ` [M]` moderator = true } + if(comment.score_hidden) { + ups = `[score hidden]` + } else { + ups = `${kFormatter(comment.ups)} points` + } comments_html += `
${comment.author}${moderator ? moderator_badge : ''} -

${kFormatter(comment.ups)} points

+

${ups}

${timeDifference(comment.created)}

${comment.stickied ? 'stickied comment' : ''}

${comment.author}${submitter ? submitter_link : ''}${moderator ? moderator_badge : ''}

-

${kFormatter(comment.ups)} points

+

${ups}

${timeDifference(comment.created)}

diff --git a/inc/processJsonPost.js b/inc/processJsonPost.js index 3e79f90..f03f387 100644 --- a/inc/processJsonPost.js +++ b/inc/processJsonPost.js @@ -138,6 +138,7 @@ module.exports = function(fetch) { permalink: comment.permalink, stickied: comment.stickied, distinguished: comment.distinguished, + score_hidden: comment.score_hidden, replies: [] } } else { @@ -212,6 +213,7 @@ module.exports = function(fetch) { permalink: reply.permalink, stickied: reply.stickied, distinguished: reply.distinguished, + score_hidden: reply.score_hidden, replies: [] } } else { @@ -243,6 +245,8 @@ module.exports = function(fetch) { ups: comment.ups, id: comment.id, permalink: comment.permalink, + score_hidden: comment.score_hidden, + distinguished: comment.distinguished, replies: [] } } else { diff --git a/routes.js b/routes.js index dd99d88..c0a2ca2 100644 --- a/routes.js +++ b/routes.js @@ -342,7 +342,7 @@ module.exports = (app, redis, fetch, RedditAPI) => { } } - let key = `${subreddit}:${after}:${before}:sort:${sortby}:past:${past}` + let key = `${subreddit.toLowerCase()}:${after}:${before}:sort:${sortby}:past:${past}` redis.get(key, (error, json) => { if(error) { console.error(`Error getting the ${subreddit} key from redis.`, error)