]> git.wh0rd.org - tt-rss.git/commitdiff
unify counter reply object handling when called from auto refetch and manually
authorAndrew Dolgov <fox@madoka.spb.ru>
Wed, 6 Dec 2006 08:55:58 +0000 (09:55 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Wed, 6 Dec 2006 08:55:58 +0000 (09:55 +0100)
functions.js
tt-rss.js

index 230fe1ab8b3418d3d1a4a3b4c5ca680adab1b995..3fa3d5e5332dacddf61d89425ad9d5ab6e9403cc 100644 (file)
@@ -613,10 +613,59 @@ function parse_counters(reply, scheduled_call) {
        }
 }
 
+function parse_counters_reply(xmlhttp) {
+
+       if (!xmlhttp.responseXML) {
+               notify("refetch_callback: backend did not return valid XML", true, true);
+               return;
+       }
+
+       var reply = xmlhttp.responseXML.firstChild;
+       
+       if (!reply) {
+               notify("refetch_callback: backend did not return expected XML object", true, true);
+               updateTitle("");
+               return;
+       } 
+       
+       var error_code = false;
+       var error_msg = false;
+
+       if (reply.firstChild) {
+               error_code = reply.firstChild.getAttribute("error-code");
+               error_msg = reply.firstChild.getAttribute("error-msg");
+       }
+
+       if (!error_code) {      
+               error_code = reply.getAttribute("error-code");
+               error_msg = reply.getAttribute("error-msg");
+       }
+       
+       if (error_code && error_code != 0) {
+               debug("refetch_callback: got error code " + error_code);
+               return fatalError(error_code, error_msg);
+       }
+
+       var counters = reply.firstChild;
+       
+       parse_counters(counters, true);
+
+       var runtime_info = counters.nextSibling;
+
+       parse_runtime_info(runtime_info);
+
+       if (getInitParam("feeds_sort_by_unread") == 1) {
+                       resort_feedlist();              
+       }       
+
+       hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
+
+}
+
 function all_counters_callback() {
        if (xmlhttp_rpc.readyState == 4) {
                try {
-                       if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
+/*                     if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
                                debug("[all_counters_callback] backend did not return valid XML");
                                return;
                        }
@@ -639,7 +688,11 @@ function all_counters_callback() {
                                resort_feedlist();              
                        }       
 
-                       hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
+                       hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
+                       
+                       debug("in all_counters_callback");
+
+                       parse_counters_reply(xmlhttp_rpc);
 
                } catch (e) {
                        exception_error("all_counters_callback", e);
index b53f9db7c7b292043a3a5d5545b08c50003c1e24..07734bacc1695c97ae36dccdcaef88c71888cce5 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -62,44 +62,7 @@ function refetch_callback() {
 
                        last_refetch = date.getTime() / 1000;
 
-                       if (!xmlhttp_ctr.responseXML) {
-                               notify("refetch_callback: backend did not return valid XML", true, true);
-                               return;
-                       }
-               
-                       var reply = xmlhttp_ctr.responseXML.firstChild;
-       
-                       if (!reply) {
-                               notify("refetch_callback: backend did not return expected XML object", true, true);
-                               updateTitle("");
-                               return;
-                       } 
-       
-                       var error_code = false;
-                       var error_msg = false;
-
-                       if (reply.firstChild) {
-                               error_code = reply.firstChild.getAttribute("error-code");
-                               error_msg = reply.firstChild.getAttribute("error-msg");
-                       }
-
-                       if (!error_code) {      
-                               error_code = reply.getAttribute("error-code");
-                               error_msg = reply.getAttribute("error-msg");
-                       }
-       
-                       if (error_code && error_code != 0) {
-                               debug("refetch_callback: got error code " + error_code);
-                               return fatalError(error_code, error_msg);
-                       }
-
-                       var counters = reply.firstChild;
-       
-                       parse_counters(counters, true);
-
-                       var runtime_info = counters.nextSibling;
-
-                       parse_runtime_info(runtime_info);
+                       parse_counters_reply(xmlhttp_ctr);
 
                        debug("refetch_callback: done");