aboutsummaryrefslogtreecommitdiff
path: root/p/scripts
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-08-09 11:50:13 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-08-09 11:50:13 +0200
commit80e7e15e3f619408db1752a3899ff708bc7bcc93 (patch)
tree9d1dd491497fffdb6998f96dbce28a07242d0830 /p/scripts
parent773d73314bf1f6e6c2ddec33a324d0aef6e8155b (diff)
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!
Diffstat (limited to 'p/scripts')
-rw-r--r--p/scripts/main.js16
1 files 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() {
// </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);
}