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.
This commit is contained in:
Mathias Kresin 2014-12-19 21:58:46 +01:00
parent cd13efeabf
commit 59500bfeb7
3 changed files with 35 additions and 23 deletions

38
assets/js/all.min.js vendored
View File

@ -1,19 +1,19 @@
var g=function(){var e=[];return{j:function(d,a){var b=d.querySelector("span.items-count");if(b){var c=d.getAttribute("data-feed-id"),e=d.querySelector("h2:first-of-type");e.className="loading-icon";var l=new XMLHttpRequest;l.onload=function(){e.className="";d.removeAttribute("data-feed-error");var c=d.querySelector(".feed-last-checked");c&&(c.innerHTML=c.getAttribute("data-after-update"));c=JSON.parse(this.responseText);c.result?b.innerHTML=c.items_count.items_unread+"/"+c.items_count.items_total:
d.setAttribute("data-feed-error","1");a&&a(c)};l.open("POST","?action=refresh-feed&feed_id="+c,!0);l.send()}},k:function(){var d=Array.prototype.slice.call(document.querySelectorAll("article:not([data-feed-disabled])")),a=setInterval(function(){for(;0<d.length&&5>e.length;){var b=d.shift();e.push(parseInt(b.getAttribute("data-feed-id"),10));g.j(b,function(b){b=e.indexOf(b.feed_id);0<=b&&e.splice(b,1);0===d.length&&0===e.length&&(clearInterval(a),window.location.href="?action=unread")})}},100)}}}(),
t=function(){function e(a){return item_id=a.getAttribute("data-item-id")}function d(a){if(a&&a.hasAttribute("data-reverse-label")){var b=a.innerHTML;a.innerHTML=a.getAttribute("data-reverse-label");a.setAttribute("data-reverse-label",b)}}function a(a){"mouse"!==k.b&&m.d();a.parentNode.removeChild(a);r--}function b(){-1<window.location.href.indexOf("nothing_to_read=1")&&0<n?window.location.href="?action=unread":0===r&&window.location.reload();var a=document.getElementById("page-counter");a&&(a.textContent=
r||"");document.getElementById("nav-counter").textContent=n||"";var b=document.querySelector("div.page-header h2:first-of-type");if(b)pageHeading=b.firstChild.nodeValue;else if(b=document.querySelector("article.item h1:first-of-type")){document.title=b.textContent;return}switch(document.querySelector("section.page").getAttribute("data-item-page")){case "unread":document.title="Miniflux ("+n+")";break;case "feed-items":document.title="("+r+") "+pageHeading;break;default:document.title=a?pageHeading+
" ("+r+")":pageHeading}}function c(f){var h=e(f),c=new XMLHttpRequest;c.onload=function(){if(m.a()){if(f.getAttribute("data-hide"))a(f);else{f.setAttribute("data-item-status","read");var c=f.querySelector("a.mark");d(c);(c=f.querySelector("a.mark"))&&c.setAttribute("data-action","mark-unread")}n--;b()}};c.open("POST","?action=mark-item-read&id="+h,!0);c.send()}function v(f){var c=e(f),p=new XMLHttpRequest;p.onload=function(){if(m.a()){if(f.getAttribute("data-hide"))a(f);else{f.setAttribute("data-item-status",
"unread");var c=f.querySelector("a.mark");d(c);(c=f.querySelector("a.mark"))&&c.setAttribute("data-action","mark-read")}n++;b()}};p.open("POST","?action=mark-item-unread&id="+c,!0);p.send()}var l=[],q=!1,n=function(){var a=document.getElementById("nav-counter");if(a)return counter=parseInt(a.textContent,10)||0}(),r=function(){var a=document.getElementById("page-counter");if(a)return counter=parseInt(a.textContent,10)||0}();return{p:c,r:v,q:function(f){var c=e(f),d=new XMLHttpRequest;d.onload=function(){m.a()&&
(a(f),"unread"===f.getAttribute("data-item-status")&&n--,b())};d.open("POST","?action=mark-item-removed&id="+c,!0);d.send()},i:function(c){var h=e(c),p="1"===c.getAttribute("data-item-bookmark")?"0":"1",u=new XMLHttpRequest;u.onload=function(){var h=document.querySelector("section.page");if(m.a()&&"bookmarks"===h.getAttribute("data-item-page"))a(c),b();else if(c.setAttribute("data-item-bookmark",p),m.a())h=c.querySelector("a.bookmark"),d(h);else if((h=c.querySelector("a.bookmark-icon"))&&h.hasAttribute("data-reverse-title")){var e=
h.getAttribute("title");h.setAttribute("title",h.getAttribute("data-reverse-title"));h.setAttribute("data-reverse-title",e)}};u.open("POST","?action=bookmark&id="+h+"&value="+p,!0);u.send()},A:function(a){var b=a.getAttribute("data-item-status");"read"===b?v(a):"unread"===b&&c(a)},v:function(a){(a=a.querySelector("a.show"))&&a.click()},g:function(a){var b=a.querySelector("a.original");b&&("unread"===a.getAttribute("data-item-status")&&c(a),b.removeAttribute("data-action"),"mouse"!==k.b&&b.click())},
e:function(a){var b=document.getElementById("download-item");if(b){b.innerHTML=" "+b.getAttribute("data-before-message");b.className="loading-icon";var c=new XMLHttpRequest;c.onload=function(){var a=JSON.parse(c.responseText);b.className="";if(a.result){var d=document.getElementById("item-content");d&&(d.innerHTML=a.content);b.innerHTML=b.getAttribute("data-after-message")}else b.innerHTML=b.getAttribute("data-failure-message")};a=e(a);c.open("POST","?action=download-item&id="+a,!0);c.send()}},f:function(a){for(var b=
document.getElementsByTagName("article"),c=[],d=0,l=b.length;d<l;d++)c.push(e(b[d]));b=new XMLHttpRequest;b.onload=function(){window.location.href=a};b.open("POST","?action=mark-items-as-read",!0);b.send(JSON.stringify(c))},B:function(){for(var a=["#current-item h1","#item-content","#listing #current-item h2","#listing #current-item .preview"],b=0;b<a.length;b++){var c=document.querySelector(a[b]);c&&(c.dir=""==c.dir?"rtl":"")}},C:function(){return q},c:function(){if(!document.hidden||!q){var a=new XMLHttpRequest;
a.onload=function(){var a=0===l.length,c=!1,d=JSON.parse(this.responseText),e;for(e in d.feeds){var f=d.feeds[e];if(!l.hasOwnProperty(e)||f.time>l[e])l[e]=f.time,"unread"===f.status&&(c=!0)}document.hidden||d.nbUnread===n&&!q?document.hidden&&!a&&c&&(q=!0,document.title="\u21bb "+document.title):(q=!1,n=d.nbUnread,b())};a.open("POST","?action=latest-feeds-items",!0);a.send()}}}}(),k=function(){function e(a){if(63!==a.keyCode&&63!==a.which&&(a.ctrlKey||a.shiftKey||a.altKey||a.metaKey))return!0;a=a.target||
a.srcElement;return"INPUT"===a.tagName||"TEXTAREA"===a.tagName?!0:!1}var d=[];return{b:"",n:function(){document.onclick=function(a){var b=a.target.getAttribute("data-action");b&&"original-link"!==b&&a.preventDefault()};document.onmouseup=function(a){if(2!==a.button)if("INPUT"===a.target.nodeName&&"auto-select"===a.target.className)a.target.select();else{var b=a.target.getAttribute("data-action");if(b){k.b="mouse";var c;a:{for(element=a.target;element&&element.parentNode;)if(element=element.parentNode,
element.tagName&&"article"===element.tagName.toLowerCase()){c=element;break a}c=void 0}switch(b){case "refresh-all":g.k();break;case "refresh-feed":c&&g.j(c);break;case "mark-read":c&&t.p(c);break;case "mark-unread":c&&t.r(c);break;case "mark-removed":c&&t.q(c);break;case "bookmark":c&&t.i(c);break;case "download-item":c&&t.e(c);break;case "original-link":c&&t.g(c);break;case "mark-all-read":t.f("?action=unread");break;case "mark-feed-read":t.f("?action=feed-items&feed_id="+a.target.getAttribute("data-feed-id"))}}}}},
m:function(){document.onkeypress=function(a){if(!e(a))if(k.b="keyboard",d.push(a.keyCode||a.which),103===d[0])switch(d[1]){case void 0:break;case 117:window.location.href="?action=unread";d=[];break;case 98:window.location.href="?action=bookmarks";d=[];break;case 104:window.location.href="?action=history";d=[];break;case 115:window.location.href="?action=feeds";d=[];break;case 112:window.location.href="?action=config";d=[];break;default:d=[]}else{d=[];var b=document.getElementById("current-item");
switch(a.keyCode||a.which){case 100:b&&t.e(b);break;case 112:case 107:m.h();break;case 110:case 106:m.d();break;case 118:b&&t.g(b);break;case 111:b&&t.v(b);break;case 109:b&&t.A(b);break;case 102:b&&t.i(b);break;case 104:m.t();break;case 108:m.s();break;case 114:g.k();break;case 63:m.w();break;case 122:t.B()}}};document.onkeydown=function(a){if(!e(a))switch(k.b="keyboard",a.keyCode||a.which){case 37:m.h();break;case 39:m.d()}}},o:function(){document.addEventListener("visibilitychange",function(){!document.hidden&&
t.C()&&t.c()})}}}(),m=function(){function e(a){var b=pageYOffset+document.documentElement.clientHeight;(0>b-(a.offsetTop+a.offsetHeight)||b-a.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,a.offsetTop-10)}function d(){return document.getElementById("listing")?!0:!1}return{s:function(){var a=document.getElementById("next-page");a&&a.click()},t:function(){var a=document.getElementById("previous-page");a&&a.click()},d:function(){var a=document.getElementById("next-item");if(a)a.click();
else if(d())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var b=0,c=a.length;b<c;b++){if("current-item"===a[b].id){b+1<c&&(a[b].id="item-"+a[b].getAttribute("data-item-id"),a[b+1].id="current-item",e(a[b+1]));break}}else a[0].id="current-item",e(a[0])},h:function(){var a=document.getElementById("previous-item");if(a)a.click();else if(d())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var b=a.length-1;0<=b;b--){if("current-item"===
a[b].id){0<=b-1&&(a[b].id="item-"+a[b].getAttribute("data-item-id"),a[b-1].id="current-item",e(a[b-1]));break}}else a[a.length-1].id="current-item",e(a[a.length-1])},w:function(){open("?action=show-help","Help","width=320,height=450,location=no,scrollbars=no,status=no,toolbar=no")},a:d}}();
({D:function(){},u:function(){k.m();k.n();k.o();this.l()},l:function(){var e=new XMLHttpRequest;e.onload=function(){var d=JSON.parse(this.responseText);0<d.frontend_updatecheck_interval&&(t.c(),setInterval(function(){t.c()},6E4*d.frontend_updatecheck_interval))};e.open("POST","?action=get-config",!0);e.send(JSON.stringify(["frontend_updatecheck_interval"]))}}).u();
var k=function(){var e=[];return{j:function(d,a){var b=d.querySelector("span.items-count");if(b){var c=d.getAttribute("data-feed-id"),e=d.querySelector("h2:first-of-type");e.className="loading-icon";var l=new XMLHttpRequest;l.onload=function(){e.className="";d.removeAttribute("data-feed-error");var c=d.querySelector(".feed-last-checked");c&&(c.innerHTML=c.getAttribute("data-after-update"));c=JSON.parse(this.responseText);c.result?b.innerHTML=c.items_count.items_unread+"/"+c.items_count.items_total:
d.setAttribute("data-feed-error","1");a?a(c):g.a()};l.open("POST","?action=refresh-feed&feed_id="+c,!0);l.send()}},k:function(){var d=Array.prototype.slice.call(document.querySelectorAll("article:not([data-feed-disabled])")),a=setInterval(function(){for(;0<d.length&&5>e.length;){var b=d.shift();e.push(parseInt(b.getAttribute("data-feed-id"),10));k.j(b,function(b){b=e.indexOf(b.feed_id);0<=b&&e.splice(b,1);0===d.length&&0===e.length&&(clearInterval(a),g.a())})}},100)}}}(),g=function(){function e(a){return item_id=
a.getAttribute("data-item-id")}function d(a){if(a&&a.hasAttribute("data-reverse-label")){var b=a.innerHTML;a.innerHTML=a.getAttribute("data-reverse-label");a.setAttribute("data-reverse-label",b)}}function a(a){"mouse"!==m.c&&t.d();a.parentNode.removeChild(a);r--}function b(){-1<window.location.href.indexOf("nothing_to_read=1")&&0<n?window.location.href="?action=unread":0===r&&window.location.reload();var a=document.getElementById("page-counter");a&&(a.textContent=r||"");document.getElementById("nav-counter").textContent=
n||"";var b=document.querySelector("div.page-header h2:first-of-type");if(b)pageHeading=b.firstChild.nodeValue;else if(b=document.querySelector("article.item h1:first-of-type")){document.title=b.textContent;return}switch(document.querySelector("section.page").getAttribute("data-item-page")){case "unread":document.title="Miniflux ("+n+")";break;case "feed-items":document.title="("+r+") "+pageHeading;break;default:document.title=a?pageHeading+" ("+r+")":pageHeading}}function c(f){var h=e(f),c=new XMLHttpRequest;
c.onload=function(){if(t.b()){if(f.getAttribute("data-hide"))a(f);else{f.setAttribute("data-item-status","read");var c=f.querySelector("a.mark");d(c);(c=f.querySelector("a.mark"))&&c.setAttribute("data-action","mark-unread")}n--;b()}};c.open("POST","?action=mark-item-read&id="+h,!0);c.send()}function v(f){var c=e(f),p=new XMLHttpRequest;p.onload=function(){if(t.b()){if(f.getAttribute("data-hide"))a(f);else{f.setAttribute("data-item-status","unread");var c=f.querySelector("a.mark");d(c);(c=f.querySelector("a.mark"))&&
c.setAttribute("data-action","mark-read")}n++;b()}};p.open("POST","?action=mark-item-unread&id="+c,!0);p.send()}var l=[],q=!1,n=function(){var a=document.getElementById("nav-counter");if(a)return counter=parseInt(a.textContent,10)||0}(),r=function(){var a=document.getElementById("page-counter");if(a)return counter=parseInt(a.textContent,10)||0}();return{p:c,r:v,q:function(f){var c=e(f),d=new XMLHttpRequest;d.onload=function(){t.b()&&(a(f),"unread"===f.getAttribute("data-item-status")&&n--,b())};d.open("POST",
"?action=mark-item-removed&id="+c,!0);d.send()},i:function(c){var h=e(c),p="1"===c.getAttribute("data-item-bookmark")?"0":"1",u=new XMLHttpRequest;u.onload=function(){var h=document.querySelector("section.page");if(t.b()&&"bookmarks"===h.getAttribute("data-item-page"))a(c),b();else if(c.setAttribute("data-item-bookmark",p),t.b())h=c.querySelector("a.bookmark"),d(h);else if((h=c.querySelector("a.bookmark-icon"))&&h.hasAttribute("data-reverse-title")){var e=h.getAttribute("title");h.setAttribute("title",
h.getAttribute("data-reverse-title"));h.setAttribute("data-reverse-title",e)}};u.open("POST","?action=bookmark&id="+h+"&value="+p,!0);u.send()},A:function(a){var b=a.getAttribute("data-item-status");"read"===b?v(a):"unread"===b&&c(a)},v:function(a){(a=a.querySelector("a.show"))&&a.click()},g:function(a){var b=a.querySelector("a.original");b&&("unread"===a.getAttribute("data-item-status")&&c(a),b.removeAttribute("data-action"),"mouse"!==m.c&&b.click())},e:function(a){var b=document.getElementById("download-item");
if(b){b.innerHTML=" "+b.getAttribute("data-before-message");b.className="loading-icon";var c=new XMLHttpRequest;c.onload=function(){var a=JSON.parse(c.responseText);b.className="";if(a.result){var d=document.getElementById("item-content");d&&(d.innerHTML=a.content);b.innerHTML=b.getAttribute("data-after-message")}else b.innerHTML=b.getAttribute("data-failure-message")};a=e(a);c.open("POST","?action=download-item&id="+a,!0);c.send()}},f:function(a){for(var b=document.getElementsByTagName("article"),
c=[],d=0,l=b.length;d<l;d++)c.push(e(b[d]));b=new XMLHttpRequest;b.onload=function(){window.location.href=a};b.open("POST","?action=mark-items-as-read",!0);b.send(JSON.stringify(c))},B:function(){for(var a=["#current-item h1","#item-content","#listing #current-item h2","#listing #current-item .preview"],b=0;b<a.length;b++){var c=document.querySelector(a[b]);c&&(c.dir=""==c.dir?"rtl":"")}},C:function(){return q},a:function(){if(!document.hidden||!q){var a=new XMLHttpRequest;a.onload=function(){var a=
0===l.length,c=!1,d=JSON.parse(this.responseText),e;for(e in d.feeds){var f=d.feeds[e];if(!l.hasOwnProperty(e)||f.time>l[e])l[e]=f.time,"unread"===f.status&&(c=!0)}document.hidden||d.nbUnread===n&&!q?document.hidden&&!a&&c&&(q=!0,document.title="\u21bb "+document.title):(q=!1,n=d.nbUnread,b())};a.open("POST","?action=latest-feeds-items",!0);a.send()}}}}(),m=function(){function e(a){if(63!==a.keyCode&&63!==a.which&&(a.ctrlKey||a.shiftKey||a.altKey||a.metaKey))return!0;a=a.target||a.srcElement;return"INPUT"===
a.tagName||"TEXTAREA"===a.tagName?!0:!1}var d=[];return{c:"",n:function(){document.onclick=function(a){var b=a.target.getAttribute("data-action");b&&"original-link"!==b&&a.preventDefault()};document.onmouseup=function(a){if(2!==a.button)if("INPUT"===a.target.nodeName&&"auto-select"===a.target.className)a.target.select();else{var b=a.target.getAttribute("data-action");if(b){m.c="mouse";var c;a:{for(element=a.target;element&&element.parentNode;)if(element=element.parentNode,element.tagName&&"article"===
element.tagName.toLowerCase()){c=element;break a}c=void 0}switch(b){case "refresh-all":k.k();break;case "refresh-feed":c&&k.j(c);break;case "mark-read":c&&g.p(c);break;case "mark-unread":c&&g.r(c);break;case "mark-removed":c&&g.q(c);break;case "bookmark":c&&g.i(c);break;case "download-item":c&&g.e(c);break;case "original-link":c&&g.g(c);break;case "mark-all-read":g.f("?action=unread");break;case "mark-feed-read":g.f("?action=feed-items&feed_id="+a.target.getAttribute("data-feed-id"))}}}}},m:function(){document.onkeypress=
function(a){if(!e(a))if(m.c="keyboard",d.push(a.keyCode||a.which),103===d[0])switch(d[1]){case void 0:break;case 117:window.location.href="?action=unread";d=[];break;case 98:window.location.href="?action=bookmarks";d=[];break;case 104:window.location.href="?action=history";d=[];break;case 115:window.location.href="?action=feeds";d=[];break;case 112:window.location.href="?action=config";d=[];break;default:d=[]}else{d=[];var b=document.getElementById("current-item");switch(a.keyCode||a.which){case 100:b&&
g.e(b);break;case 112:case 107:t.h();break;case 110:case 106:t.d();break;case 118:b&&g.g(b);break;case 111:b&&g.v(b);break;case 109:b&&g.A(b);break;case 102:b&&g.i(b);break;case 104:t.t();break;case 108:t.s();break;case 114:k.k();break;case 63:t.w();break;case 122:g.B()}}};document.onkeydown=function(a){if(!e(a))switch(m.c="keyboard",a.keyCode||a.which){case 37:t.h();break;case 39:t.d()}}},o:function(){document.addEventListener("visibilitychange",function(){!document.hidden&&g.C()&&g.a()})}}}(),t=
function(){function e(a){var b=pageYOffset+document.documentElement.clientHeight;(0>b-(a.offsetTop+a.offsetHeight)||b-a.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,a.offsetTop-10)}function d(){return document.getElementById("listing")?!0:!1}return{s:function(){var a=document.getElementById("next-page");a&&a.click()},t:function(){var a=document.getElementById("previous-page");a&&a.click()},d:function(){var a=document.getElementById("next-item");if(a)a.click();else if(d())if(a=
document.getElementsByTagName("article"),document.getElementById("current-item"))for(var b=0,c=a.length;b<c;b++){if("current-item"===a[b].id){b+1<c&&(a[b].id="item-"+a[b].getAttribute("data-item-id"),a[b+1].id="current-item",e(a[b+1]));break}}else a[0].id="current-item",e(a[0])},h:function(){var a=document.getElementById("previous-item");if(a)a.click();else if(d())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var b=a.length-1;0<=b;b--){if("current-item"===
a[b].id){0<=b-1&&(a[b].id="item-"+a[b].getAttribute("data-item-id"),a[b-1].id="current-item",e(a[b-1]));break}}else a[a.length-1].id="current-item",e(a[a.length-1])},w:function(){open("?action=show-help","Help","width=320,height=450,location=no,scrollbars=no,status=no,toolbar=no")},b:d}}();
({D:function(){},u:function(){m.m();m.n();m.o();this.l()},l:function(){var e=new XMLHttpRequest;e.onload=function(){var d=JSON.parse(this.responseText);0<d.frontend_updatecheck_interval&&(g.a(),setInterval(function(){g.a()},6E4*d.frontend_updatecheck_interval))};e.open("POST","?action=get-config",!0);e.send(JSON.stringify(["frontend_updatecheck_interval"]))}}).u();

View File

@ -34,7 +34,12 @@ Miniflux.Feed = (function() {
feed.setAttribute("data-feed-error", "1");
}
if (callback) callback(response);
if (callback) {
callback(response);
}
else {
Miniflux.Item.CheckForUpdates();
}
};
request.open("POST", "?action=refresh-feed&feed_id=" + feed_id, true);
@ -54,7 +59,7 @@ Miniflux.Feed = (function() {
if (feeds.length === 0 && queue.length === 0) {
clearInterval(interval);
window.location.href = "?action=unread";
Miniflux.Item.CheckForUpdates();
}
});
}

View File

@ -107,12 +107,19 @@ Router\post_action('refresh-feed', function() {
// Display all feeds
Router\get_action('feeds', function() {
$nothing_to_read = Request\int_param('nothing_to_read');
$nb_unread_items = Model\Item\count_by_status('unread');
// possible with remember me function
if ($nothing_to_read === 1 && $nb_unread_items > 0) {
Response\redirect('?action=unread');
}
Response\html(Template\layout('feeds', array(
'favicons' => Model\Feed\get_all_favicons(),
'feeds' => Model\Feed\get_all_item_counts(),
'nothing_to_read' => Request\int_param('nothing_to_read'),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'nothing_to_read' => $nothing_to_read,
'nb_unread_items' => $nb_unread_items,
'nb_failed_feeds' => Model\Feed\count_failed_feeds(),
'menu' => 'feeds',
'title' => t('Subscriptions')