diff --git a/files/assets/js/default.js b/files/assets/js/default.js index 76c6e36ec..0a12c27a6 100644 --- a/files/assets/js/default.js +++ b/files/assets/js/default.js @@ -150,34 +150,3 @@ function post_toast2(url, button1, button2) { document.getElementById(button1).classList.toggle("d-none"); document.getElementById(button2).classList.toggle("d-none"); } - -/** - * Cleans the expired entries (5 days). It runs every hour. - */ -function cleanCommentsCache() { - const LAST_CACHE_CLEAN_ID = "last-cache-clean" - const EXPIRE_INTERVAL_MILLIS = 5 * 24 * 60 * 60 * 1000 - const CACHE_CLEAN_INTERVAL = 60 * 60 * 1000 // 1 hour - - function cleanCache() { - const lastCacheClean = JSON.parse(localStorage.getItem(LAST_CACHE_CLEAN_ID)) || Date.now() - const now = Date.now() - - if (now - lastCacheClean > CACHE_CLEAN_INTERVAL) { - const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {} - - for (let [key, value] of Object.entries(comments)) { - if (now - value.t > EXPIRE_INTERVAL_MILLIS) { - delete comments[key] - } - } - window.localStorage.setItem(COMMENT_COUNTS_ID, JSON.stringify(comments)) - } - window.localStorage.setItem(LAST_CACHE_CLEAN_ID, JSON.stringify(now)) - } - - // So it does not slow the load of the main page with the clean up - setTimeout(cleanCache, 500) -} - -cleanCommentsCache() diff --git a/files/templates/comments.html b/files/templates/comments.html index 3875c0c21..357e7e6e6 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -9,6 +9,8 @@ {% endif %} +{% include 'embeds/new_comments_count.html' %} + - {% endif %} diff --git a/files/templates/embeds/new_comments_count.html b/files/templates/embeds/new_comments_count.html new file mode 100644 index 000000000..c2adf6acb --- /dev/null +++ b/files/templates/embeds/new_comments_count.html @@ -0,0 +1,80 @@ + diff --git a/files/templates/submission.html b/files/templates/submission.html index e639c5d6f..3585c3535 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -64,6 +64,8 @@ {% endif %} +{% include 'embeds/new_comments_count.html' %} + diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 365d203a2..209f341af 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -15,6 +15,8 @@ }); +{% include 'embeds/new_comments_count.html' %} + {% for p in listing %} {% set ups=p.upvotes %}