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;
|
|
|
|
|
2014-02-23 03:50:54 +01:00
|
|
|
// Interval reference for the loading icon
|
|
|
|
var icon_interval;
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
// Show the refresh icon when updating a feed
|
|
|
|
function showRefreshIcon(feed_id)
|
|
|
|
{
|
|
|
|
var container = document.getElementById("loading-feed-" + feed_id);
|
|
|
|
|
|
|
|
if (container) {
|
2014-02-23 03:50:54 +01:00
|
|
|
container.appendChild(document.createTextNode("☀"));
|
|
|
|
container.classList.add("loading-icon-blink");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! icon_interval) {
|
|
|
|
icon_interval = setInterval(Miniflux.App.BlinkIcon, 500);
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide the refresh icon after update
|
2014-02-23 01:45:02 +01:00
|
|
|
function hideRefreshIcon(feed_id)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
|
|
|
var container = document.getElementById("loading-feed-" + feed_id);
|
2014-02-23 01:45:02 +01:00
|
|
|
if (container) container.innerHTML = "";
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
var container = document.getElementById("last-checked-feed-" + feed_id);
|
|
|
|
if (container) container.innerHTML = container.getAttribute("data-after-update");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all subscriptions from the feeds page
|
|
|
|
function loadFeeds()
|
|
|
|
{
|
|
|
|
var links = document.getElementsByTagName("a");
|
|
|
|
|
|
|
|
for (var i = 0, ilen = links.length; i < ilen; i++) {
|
|
|
|
var feed_id = links[i].getAttribute('data-feed-id');
|
|
|
|
if (feed_id) feeds.push(parseInt(feed_id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-23 01:45:02 +01:00
|
|
|
// Update the items unread/total count for the feed
|
|
|
|
function updateItemsCounter(feed_id, counts)
|
|
|
|
{
|
|
|
|
var container = document.getElementById("items-count-" + feed_id);
|
|
|
|
if (container) container.innerHTML = "(" + counts["items_unread"] + "/" + counts['items_total'] + ")";
|
|
|
|
}
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
return {
|
|
|
|
Update: function(feed_id, callback) {
|
|
|
|
|
|
|
|
showRefreshIcon(feed_id);
|
|
|
|
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
|
|
|
|
request.onload = function() {
|
|
|
|
|
2014-02-23 01:45:02 +01:00
|
|
|
hideRefreshIcon(feed_id);
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
try {
|
2014-02-22 20:00:49 +01:00
|
|
|
|
2014-02-23 01:45:02 +01:00
|
|
|
var response = JSON.parse(this.responseText);
|
2014-02-22 20:00:49 +01:00
|
|
|
|
2014-02-23 01:45:02 +01:00
|
|
|
if (response.result) updateItemsCounter(feed_id, response.items_count);
|
|
|
|
if (callback) callback(response);
|
2014-02-22 20:00:49 +01:00
|
|
|
}
|
2014-02-23 01:45:02 +01:00
|
|
|
catch (e) {}
|
2013-10-15 04:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
request.open("POST", "?action=refresh-feed&feed_id=" + feed_id, true);
|
|
|
|
request.send();
|
|
|
|
},
|
|
|
|
UpdateAll: function() {
|
|
|
|
|
|
|
|
loadFeeds();
|
|
|
|
|
|
|
|
var interval = setInterval(function() {
|
|
|
|
|
|
|
|
while (feeds.length > 0 && queue.length < queue_length) {
|
|
|
|
|
|
|
|
var feed_id = feeds.shift();
|
|
|
|
queue.push(feed_id);
|
|
|
|
|
|
|
|
Miniflux.Feed.Update(feed_id, 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);
|
2014-02-23 03:50:54 +01:00
|
|
|
clearInterval(icon_interval);
|
2013-10-15 04:38:07 +02:00
|
|
|
window.location.href = "?action=unread";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|