From 10c772efade6e80df0ea1d936437d368975d561e Mon Sep 17 00:00:00 2001 From: discomrade Date: Fri, 15 Oct 2021 00:09:00 +0000 Subject: [PATCH] Fix notifications --- js/mod/recent-posts-auto-reload.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/js/mod/recent-posts-auto-reload.js b/js/mod/recent-posts-auto-reload.js index 90ba9fdb..e2d661d2 100644 --- a/js/mod/recent-posts-auto-reload.js +++ b/js/mod/recent-posts-auto-reload.js @@ -116,7 +116,7 @@ $(document).ready(function(){ var title = document.title; if (typeof update_title == "undefined") { - var update_title = function() { + var update_title = function() { if (new_posts) { document.title = "("+new_posts+") "+title; } else { @@ -134,6 +134,7 @@ $(document).ready(function(){ var window_active = true; $(window).focus(function() { window_active = true; + recheck_activated(); // Reset the delay if needed if(settings.get('reset_focus', true)) { @@ -155,7 +156,6 @@ $(document).ready(function(){ }); - var decrement_timer = function() { poll_current_time = poll_current_time - 1000; $('#update_secs').text(poll_current_time/1000); @@ -165,6 +165,16 @@ $(document).ready(function(){ } } + var recheck_activated = function() { + if (new_posts && window_active && + $(window).scrollTop() <= + $('header').position().top + $('header').outerHeight(true)) { + new_posts = 0; + } + update_title(); + first_new_post = null; + }; + // automatically updates the thread after a specified delay var auto_update = function(delay) { clearInterval(countdown_interval); @@ -207,11 +217,11 @@ $(document).ready(function(){ if($('#' + id).length == 0) { if (!new_posts) { first_new_post = this; - makeIcon('reply'); - if (notify === "all") { - var body = $(this).children('.body').html().replace(//gi, "\n"); - var n = new Notification("New reply to "+$('title').text(), {body: $('
').html(body).text()}); - } + } + // Notify on all posts, not just the first unread + if (notify === "all") { + var body = $(this).children('.body').html().replace(//gi, "\n"); + var n = new Notification("New reply to "+$('title').text(), {body: $('
').html(body).text()}); } if ($("div.post,div.thread").length > 1){ $(this).parent().insertBefore($($('div.post,div.thread').not('.post-hover').first()).parent()); @@ -222,6 +232,7 @@ $(document).ready(function(){ new_posts++; loaded_posts++; $(document).trigger('new_post', this); + recheck_activated(); } }); @@ -279,6 +290,9 @@ $(document).ready(function(){ return false; }; + $(window).scrollStopped(function() { + recheck_activated(); + }); $('#update_thread').on('click', function() { poll(manualUpdate = true); return false; });