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!
pull/573/head
Marien Fressinaud 10 years ago
parent 773d73314b
commit 80e7e15e3f
  1. 16
      p/scripts/main.js

@ -769,8 +769,7 @@ function init_notifications() {
// </notification> // </notification>
// <notifs html5> // <notifs html5>
var notifs_html5_permission = 'denied', var notifs_html5_permission = 'denied';
notifs_html5_shown = false;
function notifs_html5_is_supported() { function notifs_html5_is_supported() {
return window.Notification !== undefined; return window.Notification !== undefined;
@ -783,7 +782,7 @@ function notifs_html5_ask_permission() {
} }
function notifs_html5_show(nb) { function notifs_html5_show(nb) {
if (notifs_html5_permission !== "granted" || notifs_html5_shown) { if (notifs_html5_permission !== "granted") {
return return
} }
@ -795,8 +794,6 @@ function notifs_html5_show(nb) {
notification.onclick = function() { notification.onclick = function() {
window.location.reload(); window.location.reload();
} }
notifs_html5_shown = true;
} }
function init_notifs_html5() { function init_notifs_html5() {
@ -810,19 +807,24 @@ function init_notifs_html5() {
function refreshUnreads() { function refreshUnreads() {
$.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { $.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) { $.each(data, function(feed_id, nbUnreads) {
feed_id = 'f_' + feed_id; feed_id = 'f_' + feed_id;
var elem = $('#' + feed_id + '>.feed').get(0), var elem = $('#' + feed_id + '>.feed').get(0),
feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0; feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view? if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view?
(nbUnreads - feed_unreads > 0)) { (nbUnreads - feed_unreads > 0)) {
$('#new-article').show(); $('#new-article').show();
new_articles = true;
}; };
}); });
var nb_unreads = str2int($('.category.all>a').attr('data-unread')); var nb_unreads = str2int($('.category.all>a').attr('data-unread'));
if (nb_unreads > 0) {
if (nb_unreads > 0 && new_articles) {
faviconNbUnread(nb_unreads); faviconNbUnread(nb_unreads);
notifs_html5_show(nb_unreads); notifs_html5_show(nb_unreads);
} }

Loading…
Cancel
Save