From 80e7e15e3f619408db1752a3899ff708bc7bcc93 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 9 Aug 2014 11:50:13 +0200 Subject: [PATCH] Show notification only for new articles Now, notifications are shown only if there are new articles not shown on the page yet. Before, at the first loading of the page, if there were unread articles, a notification appeared after two minutes! --- p/scripts/main.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index 8274d411e..a91e23400 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -769,8 +769,7 @@ function init_notifications() { // // -var notifs_html5_permission = 'denied', - notifs_html5_shown = false; +var notifs_html5_permission = 'denied'; function notifs_html5_is_supported() { return window.Notification !== undefined; @@ -783,7 +782,7 @@ function notifs_html5_ask_permission() { } function notifs_html5_show(nb) { - if (notifs_html5_permission !== "granted" || notifs_html5_shown) { + if (notifs_html5_permission !== "granted") { return } @@ -795,8 +794,6 @@ function notifs_html5_show(nb) { notification.onclick = function() { window.location.reload(); } - - notifs_html5_shown = true; } function init_notifs_html5() { @@ -810,19 +807,24 @@ function init_notifs_html5() { function refreshUnreads() { $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { - var isAll = $('.category.all > .active').length > 0; + var isAll = $('.category.all > .active').length > 0, + new_articles = false; + $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0; + if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view? (nbUnreads - feed_unreads > 0)) { $('#new-article').show(); + new_articles = true; }; }); var nb_unreads = str2int($('.category.all>a').attr('data-unread')); - if (nb_unreads > 0) { + + if (nb_unreads > 0 && new_articles) { faviconNbUnread(nb_unreads); notifs_html5_show(nb_unreads); }