forked from rDrama/rDrama
1
0
Fork 0

Only show the new comments if the highlight new comments flag is active

Other small fixes
master
Yo Mama 2021-09-27 20:40:13 +02:00
parent 5b65ea121b
commit faab316e37
3 changed files with 9 additions and 13 deletions

View File

@ -210,24 +210,20 @@
// New comment counts
// comment counts format: {"123412": {c: 12, t: 23532456263}}
// 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, 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()
</script>

View File

@ -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}})
})()

View File

@ -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 %}
})()
</script>