miniflux-legacy/assets/js/feed.js
Mathias Kresin 59500bfeb7 update counter/rework redirect to unread on feeds page
The redirect to the unread page after a manual refresh only, if new
items could be fetched and we where redirected to the subscriptions
page because of a former nothing_to_read.

Update the unread counter after refreshing either one feed or all feeds.

Redirect to unread if nothing_to_read is set, but unread items exists.
This could be the situation with the remember me function, when new items
are fetched while the browser was closed.
2015-01-28 05:26:55 +01:00

69 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 = "";
feed.removeAttribute("data-feed-error");
var lastChecked = feed.querySelector(".feed-last-checked");
if (lastChecked) lastChecked.innerHTML = lastChecked.getAttribute("data-after-update");
var response = JSON.parse(this.responseText);
if (response['result']) {
itemsCounter.innerHTML = response['items_count']['items_unread'] + "/" + response['items_count']['items_total'];
} else {
feed.setAttribute("data-feed-error", "1");
}
if (callback) {
callback(response);
}
else {
Miniflux.Item.CheckForUpdates();
}
};
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'), 10));
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);
Miniflux.Item.CheckForUpdates();
}
});
}
}, 100);
}
};
})();