miniflux-legacy/assets/js/feed.js
Mathias Kresin 9d31eb1a01 Fix feed-last-checked update after refresh-all
I've dropped it accidentally with my last commit. Furthermore I moved
the data-feed-id definition to the article element and dropped multiple
references of the feed id. That's similar to what I've done before with
the data-item-id in 3dae99ac.

The article element holds the information whether a feed is disabled now.

Now it is shown if a feed had errors while updating.
2014-12-31 17:14:19 +01:00

66 lines
2.5 KiB
JavaScript

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 {
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";
var request = new XMLHttpRequest();
request.onload = function() {
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 = "";
var response = JSON.parse(this.responseText);
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");
}
if (callback) callback(response);
};
request.open("POST", "?action=refresh-feed&feed_id=" + feed_id, true);
request.send();
},
UpdateAll: function() {
var feeds = Array.prototype.slice.call(document.querySelectorAll("article:not([data-feed-disabled])"));
var interval = setInterval(function() {
while (feeds.length > 0 && queue.length < queue_length) {
var feed = feeds.shift();
queue.push(parseInt(feed.getAttribute('data-feed-id')));
Miniflux.Feed.Update(feed, function(response) {
var index = queue.indexOf(response.feed_id);
if (index >= 0) queue.splice(index, 1);
if (feeds.length === 0 && queue.length === 0) {
clearInterval(interval);
window.location.href = "?action=unread";
}
});
}
}, 100);
}
};
})();