fix duplicate ~new~
indicators being sent (#642)
we also make the JS we're generating about 7% the size it was before.
This commit is contained in:
parent
2541737833
commit
a5a344f084
3 changed files with 54 additions and 36 deletions
|
@ -57,3 +57,21 @@ function expandMarkdown(t,id) {
|
||||||
if (val.innerHTML == 'View source') val.innerHTML = 'Hide source'
|
if (val.innerHTML == 'View source') val.innerHTML = 'Hide source'
|
||||||
else val.innerHTML = 'View source'
|
else val.innerHTML = 'View source'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function commentsAddUnreadIndicator(commentIds) {
|
||||||
|
commentIds.forEach(element => {
|
||||||
|
const commentOnly = document.getElementById(`comment-${element}-only`);
|
||||||
|
if (!commentOnly) {
|
||||||
|
console.warn(`Couldn't find comment (comment ID ${element}) in page while attempting to add an unread indicator.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (commentOnly.classList.contains("unread")) return;
|
||||||
|
commentOnly.classList.add("unread");
|
||||||
|
const commentUserInfo = document.getElementById(`comment-${element}`)?.querySelector(".comment-user-info");
|
||||||
|
if (!commentUserInfo) {
|
||||||
|
console.warn(`Couldn't find comment user info (comment ID ${element}) in page while attempting to add an unread indicator.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commentUserInfo.innerHTML += "<span class=\"new-indicator\">~new~</span>";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -201,23 +201,23 @@
|
||||||
<script src="{{ 'js/comments+submission_listing.js' | asset }}"></script>
|
<script src="{{ 'js/comments+submission_listing.js' | asset }}"></script>
|
||||||
<script src="{{ 'js/comments.js' | asset }}"></script>
|
<script src="{{ 'js/comments.js' | asset }}"></script>
|
||||||
|
|
||||||
|
{# See https://github.com/themotte/rDrama/pull/642#issuecomment-1646649781 for info on this section of the code #}
|
||||||
<script>
|
<script>
|
||||||
{% if p and (not v or v.highlightcomments) %}
|
{% if p and (not v or v.highlightcomments) %}
|
||||||
comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
||||||
lastCount = comments['{{p.id}}']
|
lastCount = comments['{{p.id}}']
|
||||||
if (lastCount)
|
var commentsToCheck = [
|
||||||
{
|
{% for c in p.comments -%}
|
||||||
{% for c in p.comments %}
|
{%- if not (v and v.id==c.author_id) and not c.voted %}
|
||||||
{% if not (v and v.id==c.author_id) and not c.voted %}
|
[{{c.id}}, {{c.created_utc * 1000}}],
|
||||||
if ({{c.created_utc*1000}} > lastCount.t)
|
{%- endif -%}
|
||||||
try {
|
|
||||||
document.getElementById("comment-{{c.id}}-only").classList.add('unread')
|
|
||||||
document.getElementById("comment-{{c.id}}").querySelector(".comment-user-info").innerHTML += "<span>~new~</span>";
|
|
||||||
}
|
|
||||||
catch(e) {}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
];
|
||||||
|
|
||||||
|
commentsToCheck = commentsToCheck.filter(comment => comment[1] > lastCount.t)
|
||||||
|
.map(comment => comment[0]);
|
||||||
|
|
||||||
|
if (lastCount) commentsAddUnreadIndicator(commentsToCheck);
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if p and not (request.values and ('context' in request.values)) %}
|
{% if p and not (request.values and ('context' in request.values)) %}
|
||||||
|
@ -250,19 +250,19 @@
|
||||||
{% if p %}
|
{% if p %}
|
||||||
comments = JSON.parse(localStorage.getItem("old-comment-counts")) || {}
|
comments = JSON.parse(localStorage.getItem("old-comment-counts")) || {}
|
||||||
lastCount = comments['{{p.id}}']
|
lastCount = comments['{{p.id}}']
|
||||||
if (lastCount)
|
|
||||||
{
|
var commentsToCheck = [
|
||||||
{% for c in p.comments %}
|
{% for c in p.comments -%}
|
||||||
{% if not (v and v.id==c.author_id) and not c.voted %}
|
{%- if not (v and v.id==c.author_id) and not c.voted %}
|
||||||
if ({{c.created_utc*1000}} > lastCount.t)
|
[{{c.id}}, {{c.created_utc * 1000}}],
|
||||||
try {
|
{%- endif -%}
|
||||||
document.getElementById("comment-{{c.id}}-only").classList.add('unread')
|
|
||||||
document.getElementById("comment-{{c.id}}").querySelector(".comment-user-info").innerHTML += "<span>~new~</span>";
|
|
||||||
}
|
|
||||||
catch(e) {}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
];
|
||||||
|
|
||||||
|
commentsToCheck = commentsToCheck.filter(comment => comment[1] > lastCount.t)
|
||||||
|
.map(comment => comment[0]);
|
||||||
|
|
||||||
|
if (lastCount) commentsAddUnreadIndicator(commentsToCheck);
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
|
|
|
@ -489,19 +489,19 @@
|
||||||
|
|
||||||
comments = JSON.parse(localStorage.getItem("old-comment-counts")) || {}
|
comments = JSON.parse(localStorage.getItem("old-comment-counts")) || {}
|
||||||
lastCount = comments['{{p.id}}']
|
lastCount = comments['{{p.id}}']
|
||||||
if (lastCount)
|
|
||||||
{
|
var commentsToCheck = [
|
||||||
{% for c in p.comments %}
|
{% for c in p.comments -%}
|
||||||
{% if not (v and v.id==c.author_id) and not c.voted %}
|
{% if not (v and v.id==c.author_id) and not c.voted %}
|
||||||
if ({{c.created_utc*1000}} > lastCount.t)
|
[{{c.id}}, {{c.created_utc * 1000}}],
|
||||||
try {
|
{%- endif -%}
|
||||||
document.getElementById("comment-{{c.id}}-only").classList.add('unread')
|
|
||||||
document.getElementById("comment-{{c.id}}").querySelector(".comment-user-info").innerHTML += "<span>~new~</span>";
|
|
||||||
}
|
|
||||||
catch(e) {}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
];
|
||||||
|
|
||||||
|
commentsToCheck = commentsToCheck.filter(comment => comment[1] > lastCount.t)
|
||||||
|
.map(comment => comment[0]);
|
||||||
|
|
||||||
|
if (lastCount) commentsAddUnreadIndicator(commentsToCheck);
|
||||||
|
|
||||||
collapsedCommentStorageApply();
|
collapsedCommentStorageApply();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue