2013-10-15 04:38:07 +02:00
|
|
|
Miniflux.Feed = (function() {
|
|
|
|
|
|
|
|
// List of subscriptions
|
|
|
|
var feeds = [];
|
|
|
|
|
|
|
|
// List of feeds currently updating
|
|
|
|
var queue = [];
|
|
|
|
|
|
|
|
// Number of concurrent requests when updating all feeds
|
|
|
|
var queue_length = 5;
|
|
|
|
|
|
|
|
return {
|
2014-12-31 13:43:05 +01:00
|
|
|
Update: function(feed, callback) {
|
|
|
|
var itemsCounter = feed.querySelector("span.items-count");
|
|
|
|
if (! itemsCounter) return;
|
|
|
|
|
|
|
|
var feed_id = feed.getAttribute("data-feed-id")
|
|
|
|
|
|
|
|
var heading = feed.querySelector("h2:first-of-type");
|
|
|
|
heading.className = "loading-icon";
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.onload = function() {
|
2014-12-31 13:43:05 +01:00
|
|
|
heading.className = "";
|
|
|
|
|
|
|
|
var lastChecked = feed.querySelector(".feed-last-checked");
|
|
|
|
if (lastChecked) lastChecked.innerHTML = lastChecked.getAttribute("data-after-update");
|
|
|
|
|
|
|
|
var feedParsingError = feed.querySelector(".feed-parsing-error");
|
|
|
|
if (feedParsingError) feedParsingError.innerHTML = "";
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-12-02 16:29:00 +01:00
|
|
|
var response = JSON.parse(this.responseText);
|
2014-12-31 13:43:05 +01:00
|
|
|
if (response.result) {
|
|
|
|
itemsCounter.innerHTML = response.items_count["items_unread"] + "/" + response.items_count['items_total'];
|
|
|
|
} else {
|
|
|
|
if (feedParsingError) feedParsingError.innerHTML = feedParsingError.getAttribute("data-after-error");
|
|
|
|
}
|
|
|
|
|
2014-12-02 16:29:00 +01:00
|
|
|
if (callback) callback(response);
|
2013-10-15 04:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
request.open("POST", "?action=refresh-feed&feed_id=" + feed_id, true);
|
|
|
|
request.send();
|
|
|
|
},
|
|
|
|
UpdateAll: function() {
|
2014-12-31 13:43:05 +01:00
|
|
|
var feeds = Array.prototype.slice.call(document.querySelectorAll("article:not([data-feed-disabled])"));
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
var interval = setInterval(function() {
|
|
|
|
while (feeds.length > 0 && queue.length < queue_length) {
|
2014-12-31 13:43:05 +01:00
|
|
|
var feed = feeds.shift();
|
|
|
|
queue.push(parseInt(feed.getAttribute('data-feed-id')));
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-12-31 13:43:05 +01:00
|
|
|
Miniflux.Feed.Update(feed, function(response) {
|
2013-10-15 04:38:07 +02:00
|
|
|
var index = queue.indexOf(response.feed_id);
|
|
|
|
if (index >= 0) queue.splice(index, 1);
|
|
|
|
|
2014-12-02 16:29:00 +01:00
|
|
|
if (feeds.length === 0 && queue.length === 0) {
|
2013-10-15 04:38:07 +02:00
|
|
|
clearInterval(interval);
|
|
|
|
window.location.href = "?action=unread";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|