소스 검색

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!
Marien Fressinaud 12 년 전
부모
커밋
80e7e15e3f
1개의 변경된 파일9개의 추가작업 그리고 7개의 파일을 삭제
  1. 9 7
      p/scripts/main.js

+ 9 - 7
p/scripts/main.js

@@ -769,8 +769,7 @@ function init_notifications() {
 // </notification>
 
 // <notifs html5>
-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);
 		}