From faab316e37677891aba1a3c058f62a2d325e26df Mon Sep 17 00:00:00 2001 From: Yo Mama Date: Mon, 27 Sep 2021 20:40:13 +0200 Subject: [PATCH] Only show the new comments if the highlight new comments flag is active Other small fixes --- files/templates/default.html | 14 +++----------- files/templates/submission.html | 4 +++- files/templates/submission_listing.html | 4 +++- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/files/templates/default.html b/files/templates/default.html index 6cd578455..9ceccaa0d 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -210,24 +210,20 @@ // New comment counts - // comment counts format: {"123412": {c: 12, t: 23532456263}} + // comment counts format: {"": {c: , t: }} const COMMENT_COUNTS_ID = "comment-counts" /** * Display the number of new comments present since the last time the post was opened */ - function showNewCommentCounts(postId, lastTotalComs) { + function showNewCommentCounts(postId, newTotal) { const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {} - console.log(postId) const lastCount = comments[postId] - console.log(lastCount) if (lastCount) { - const newComments = lastTotalComs - lastCount.c - console.log('new:', newComments) + const newComments = newTotal - lastCount.c if (newComments > 0) { document.querySelectorAll(`#post-${postId} .new-comments`).forEach(elem => { - console.log(elem) elem.textContent = ` (+${newComments})` elem.classList.remove("d-none") }) @@ -250,12 +246,9 @@ const newTotal = lastTotalComs || ((comments[postId] || { c: 0 }).c + 1) - console.log(newTotal) comments[postId] = { c: newTotal, t: Date.now() } window.localStorage.setItem(COMMENT_COUNTS_ID, JSON.stringify(comments)) - - //TODO: restrict on display unread comments flag } /** @@ -286,7 +279,6 @@ // So it does not slow the load of the main page with the clean up setTimeout(cleanCache, 500) } - cleanCommentsCache() diff --git a/files/templates/submission.html b/files/templates/submission.html index 010cc6158..4325c6245 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -747,7 +747,9 @@ document.getElementById('edited_timestamp').title = dateEdited.toString(); {% endif %} - showNewCommentCounts('{{p.id}}', {{p.comment_count}}) + {% if (not v or v.highlightcomments) %} + showNewCommentCounts('{{p.id}}', {{p.comment_count}}) + {% endif %} saveCommentsCount('{{p.id}}', {{p.comment_count}}) })() diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index c17027d7d..76b6c6620 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -408,7 +408,9 @@ document.getElementById('edited_timestamp-{{p.id}}').title = dateEdited.toString(); {% endif %} - showNewCommentCounts('{{p.id}}', {{p.comment_count}}) + {% if (not v or v.highlightcomments) %} + showNewCommentCounts('{{p.id}}', {{p.comment_count}}) + {% endif %} })()