sfd
This commit is contained in:
parent
e72e66df15
commit
0ae2464d99
2 changed files with 6 additions and 8 deletions
|
@ -2,13 +2,11 @@
|
|||
if (typeof showNewCommentCounts === 'undefined') {
|
||||
|
||||
// localstorage comment counts format: {"<postId>": {c: <totalComments>, t: <timestampUpdated>}}
|
||||
const COMMENT_COUNTS_ID = "comment-counts"
|
||||
|
||||
/**
|
||||
* Display the number of new comments present since the last time the post was opened
|
||||
*/
|
||||
function showNewCommentCounts(postId, newTotal) {
|
||||
const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {}
|
||||
const comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
||||
|
||||
const lastCount = comments[postId]
|
||||
if (lastCount) {
|
||||
|
@ -29,13 +27,13 @@ if (typeof showNewCommentCounts === 'undefined') {
|
|||
* @param lastTotalComs The new amount, If null it will just increment the previous amount
|
||||
*/
|
||||
function saveCommentsCount(postId, lastTotalComs = null) {
|
||||
const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {}
|
||||
const comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
||||
|
||||
const newTotal = lastTotalComs || ((comments[postId] || { c: 0 }).c + 1)
|
||||
|
||||
comments[postId] = { c: newTotal, t: Date.now() }
|
||||
|
||||
window.localStorage.setItem(COMMENT_COUNTS_ID, JSON.stringify(comments))
|
||||
window.localStorage.setItem("comment-counts", JSON.stringify(comments))
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,14 +50,14 @@ if (typeof showNewCommentCounts === 'undefined') {
|
|||
const now = Date.now()
|
||||
|
||||
if (now - lastCacheClean > CACHE_CLEAN_INTERVAL) {
|
||||
const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {}
|
||||
const comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
||||
|
||||
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("comment-counts", JSON.stringify(comments))
|
||||
}
|
||||
window.localStorage.setItem(LAST_CACHE_CLEAN_ID, JSON.stringify(now))
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@
|
|||
|
||||
{% if p and not (v and v.id==c.author_id) and (not v or v.highlightcomments) %}
|
||||
<script>
|
||||
comments = JSON.parse(localStorage.getItem({{c.id}})) || {}
|
||||
comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
||||
lastCount = comments['{{p.id}}']
|
||||
if (lastCount && {{c.created_utc}} > lastCount.t) {
|
||||
document.getElementsById("reddot-{{c.id}}").innerHTML = '<i style="color:red !important" class="text-admin fas fa-circle" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Unread"></i>'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue