]> git.wh0rd.org Git - tt-rss.git/commitdiff
asynchronous feed updating
authorAndrew Dolgov <fox@madoka.spb.ru>
Tue, 23 Aug 2005 06:13:28 +0000 (07:13 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Tue, 23 Aug 2005 06:13:28 +0000 (07:13 +0100)
backend.php
tt-rss.js

index 012396182eab6dd298ea1b824b7d264be468a1f6..0a91a641229e8c2a8075492fd797ecc8b38e6521 100644 (file)
 
                $subop = $_GET["subop"];
 
-               if ($subop == "forceUpdateAll") {
-                       update_all_feeds($link, true);
+               if ($subop == "forceUpdateAllFeeds") {
+                       print "[rpc] forceUpdateAll";
+                       update_all_feeds($link, true);                  
                }
 
-               if ($subop == "updateAll") {
+               if ($subop == "updateAllFeeds") {
+                       print "[rpc] updateAll";
                        update_all_feeds($link, false);
                }
                
@@ -49,7 +51,7 @@
                        pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
                }
 
-               update_all_feeds($link, $fetch);
+       //      update_all_feeds($link, $fetch);
                
                $result = pg_query("SELECT *,
                        (SELECT count(id) FROM ttrss_entries 
 
                print "<p align=\"center\">All feeds: 
                        <a class=\"button\" 
-                               href=\"javascript:updateFeedList(false,true)\">Update</a>";
+                               href=\"javascript:scheduleFeedUpdate()\">Update</a>";
 
                print "&nbsp;<a class=\"button\" 
                                href=\"javascript:catchupAllFeeds()\">Mark as read</a></p>";
index c78a4287d202baebd61251b9e114f8ca88197f3f..125dbad7668b30a6c2d7ddce86240ac643b7266e 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -4,8 +4,10 @@
 */
 
 var xmlhttp = false;
+var xmlhttp_rpc = false;
 
 var total_unread = 0;
+var first_run = true;
 
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
@@ -24,6 +26,8 @@ try {
 
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
+       xmlhttp_rpc = new XMLHttpRequest();
+
 }
 
 function printLockingError() {
@@ -49,7 +53,12 @@ function feedlist_callback() {
                        update_title();
                }
 
-               notify("");
+               if (first_run) {
+                       scheduleFeedUpdate();
+                       first_run = false;
+               } else {
+                       notify("");
+               }
        }
 }
 
@@ -92,12 +101,33 @@ function view_callback() {
        }
 }
 
+function refetch_callback() {
+       if (xmlhttp_rpc.readyState == 4) {
+               // feeds are updated in background
+               updateFeedList(false, false);
+//             notify("All feeds updated");
+       }
+}
+
+function scheduleFeedUpdate() {
+
+       notify("Updating feeds in background...");
+
+       var query_str = "backend.php?op=rpc&subop=forceUpdateAllFeeds";
+
+       if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) {
+               xmlhttp_rpc.open("GET", query_str, true);
+               xmlhttp_rpc.onreadystatechange=refetch_callback;
+               xmlhttp_rpc.send(null);
+       } else {
+               printLockingError();
+       }
+}
 
-function updateFeedList(called_from_timer, fetch) {
+function updateFeedList(silent, fetch) {
        
-       if (called_from_timer != true) {
-               //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
-               notify("Updating feeds...");
+       if (silent != true) {
+               notify("Updating feed list...");
        }
 
        var query_str = "backend.php?op=feeds";