]> git.wh0rd.org - tt-rss.git/blobdiff - js/feedlist.js
fix infinite scrolling for search results
[tt-rss.git] / js / feedlist.js
index aeb1ac18a10c0311ac56768fa1662e2480286c81..b737ba84a1ad899090bcd3fed3bc42912d8c73de 100644 (file)
@@ -19,9 +19,9 @@ function loadMoreHeadlines() {
                var offset = 0;
 
                var view_mode = document.forms["main_toolbar_form"].view_mode.value;
-               var num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat());
                var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
                var num_all = $$("#headlines-frame > div[id*=RROW]").length;
+               var num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat());
 
                // TODO implement marked & published
 
@@ -32,7 +32,9 @@ function loadMoreHeadlines() {
                        console.warn("loadMoreHeadlines: published is not implemented, falling back.");
                        offset = num_all;
                } else if (view_mode == "unread") {
-                       offset = num_unread;
+                       offset = unread_in_buffer;
+               } else if (_search_query) {
+                       offset = num_all;
                } else if (view_mode == "adaptive") {
                        if (num_unread > 0)
                                offset = unread_in_buffer;
@@ -42,6 +44,8 @@ function loadMoreHeadlines() {
                        offset = num_all;
                }
 
+               console.log("offset: " + offset);
+
                viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true);
 
        } catch (e) {
@@ -71,6 +75,8 @@ function viewfeed(feed, method, is_cat, offset, background, infscroll_req) {
                } else {
                        cached_headlines = cache_get("feed:" + feed + ":" + is_cat);
 
+                       if (_search_query) _search_query = false;
+
                        // switching to a different feed, we might as well catchup stuff visible
                        // in headlines buffer (if any)
                        // disabled for now because this behavior is considered confusing -fox
@@ -149,7 +155,7 @@ function viewfeed(feed, method, is_cat, offset, background, infscroll_req) {
                        if (_search_query) {
                                force_nocache = true;
                                query = query + "&" + _search_query;
-                               _search_query = false;
+                               //_search_query = false;
                        }
 
                        if (offset != 0) {
@@ -310,8 +316,11 @@ function parse_counters(elems, scheduled_call) {
                                displayNewContentPrompt(id);
                        }
 
-                       if (getFeedUnread(id, (kind == "cat")) != ctr)
+                       if (getFeedUnread(id, (kind == "cat")) != ctr ||
+                                       (kind == "cat" && getCatParam(id) != child_unread)) {
+
                                cache_delete("feed:" + id + ":" + (kind == "cat"));
+                       }
 
                        setFeedUnread(id, (kind == "cat"), ctr);
 
@@ -430,6 +439,14 @@ function setCatParam(cat, value) {
        }
 }
 
+function getCatParam(cat) {
+       try {
+               return getFeedValue(cat, true, "child_unread");
+       } catch (e) {
+               //
+       }
+}
+
 
 function selectFeed(feed, is_cat) {
        try {
@@ -564,6 +581,11 @@ function catchupFeed(feed, is_cat) {
 
 function decrementFeedCounter(feed, is_cat) {
        try {
+               // we have subcats, no way to figure out if this article is
+               // actually from this category
+               if (is_cat && getCatParam(feed) > 0)
+                       return;
+
                var ctr = getFeedUnread(feed, is_cat);
 
                if (ctr > 0) {