From c33b13809ef4e1941d3655479db8c5fcf5731013 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 13 Feb 2014 19:51:38 +0100 Subject: Add a "locker" to mark_read action In order to prevent multiple requests while another one is still pending. It is based on a list of pending actions (in fact, in a list of pending feeds) Fix #423 --- p/scripts/main.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index 8cda62d26..e94df2a39 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1,6 +1,7 @@ "use strict"; var $stream = null, - isCollapsed = true; + isCollapsed = true, + pending_feed = []; function is_normal_mode() { return $stream.hasClass('normal'); @@ -107,7 +108,8 @@ function incUnreadsFeed(article, feed_id, nb) { } function mark_read(active, only_not_read) { - if (active.length === 0 || (only_not_read === true && !active.hasClass("not_read"))) { + if (active.length === 0 || + (only_not_read === true && !active.hasClass("not_read"))) { return false; } @@ -116,6 +118,16 @@ function mark_read(active, only_not_read) { return false; } + var feed_url = active.find(".website>a").attr("href"), + feed_id = feed_url.substr(feed_url.lastIndexOf('f_')), + index_pending = pending_feed.indexOf(feed_id); + + if (index_pending !== -1) { + return false; + } + + pending_feed.push(feed_id); + $.ajax({ type: 'POST', url: url, @@ -132,9 +144,9 @@ function mark_read(active, only_not_read) { } $r.find('.icon').replaceWith(data.icon); - var feed_url = active.find(".website>a").attr("href"), - feed_id = feed_url.substr(feed_url.lastIndexOf('f_')); incUnreadsFeed(active, feed_id, inc); + + pending_feed.splice(index_pending, 1); }); } -- cgit v1.2.3