]> git.wh0rd.org Git - tt-rss.git/commitdiff
js: simplify counter updating, remove some unused stuff
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 1 Feb 2013 09:09:43 +0000 (13:09 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 1 Feb 2013 09:09:43 +0000 (13:09 +0400)
classes/api.php
classes/rpc.php
include/functions.php
js/feedlist.js
js/tt-rss.js
js/viewfeed.js

index 9b9a5bbe500b02e26366411b1c8d946e19d4b909..a4294e026dad09e10277a7e3d609555382f917d1 100644 (file)
@@ -104,11 +104,7 @@ class API extends Handler {
 
        /* Method added for ttrss-reader for Android */
        function getCounters() {
-
-               /* flct (flc is the default) FIXME: document */
-               $output_mode = db_escape_string($_REQUEST["output_mode"]);
-
-               print $this->wrap(self::STATUS_OK, getAllCounters($this->link, $output_mode));
+               print $this->wrap(self::STATUS_OK, getAllCounters($this->link));
        }
 
        function getFeeds() {
index d529e496c99bf8b04cdc798f722dc5b7e8e8ff93..5cc2235e8188eedefb448a285aaf2a116aaee46a 100644 (file)
@@ -243,20 +243,15 @@ class RPC extends Handler_Protected {
 
                $reply = array();
 
-                if ($seq) $reply['seq'] = $seq;
+               if ($seq) $reply['seq'] = $seq;
 
-                if ($last_article_id != getLastArticleId($this->link)) {
-                               $omode = $_REQUEST["omode"];
-
-                       if ($omode != "T")
-                               $reply['counters'] = getAllCounters($this->link, $omode);
-                       else
-                               $reply['counters'] = getGlobalCounters($this->link);
-                }
+               if ($last_article_id != getLastArticleId($this->link)) {
+                       $reply['counters'] = getAllCounters($this->link);
+               }
 
-                $reply['runtime-info'] = make_runtime_info($this->link);
+               $reply['runtime-info'] = make_runtime_info($this->link);
 
-                print json_encode($reply);
+               print json_encode($reply);
        }
 
        /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
index 060a8a3aaf1148c456a8a441430b1daf30850c50..c32d31f6d84367b4c1dc587a711fd2c30a77b574 100644 (file)
                        }
        }
 
-       function getAllCounters($link, $omode = "flc", $active_feed = false) {
-
-               if (!$omode) $omode = "flc";
-
+       function getAllCounters($link) {
                $data = getGlobalCounters($link);
 
                $data = array_merge($data, getVirtCounters($link));
-
-               if (strchr($omode, "l")) $data = array_merge($data, getLabelCounters($link));
-               if (strchr($omode, "f")) $data = array_merge($data, getFeedCounters($link, $active_feed));
-               if (strchr($omode, "t")) $data = array_merge($data, getTagCounters($link));
-               if (strchr($omode, "c")) $data = array_merge($data, getCategoryCounters($link));
+               $data = array_merge($data, getLabelCounters($link));
+               $data = array_merge($data, getFeedCounters($link, $active_feed));
+               $data = array_merge($data, getCategoryCounters($link));
 
                return $data;
        }
                return $ret_arr;
        }
 
-       function getTagCounters($link) {
-
-               $ret_arr = array();
-
-               $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
-                       FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
-                               AND ref_id = id AND unread = true)) AS count FROM ttrss_tags
-                               WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
-                               ORDER BY count DESC LIMIT 55");
-
-               $tags = array();
-
-               while ($line = db_fetch_assoc($result)) {
-                       $tags[$line["tag_name"]] += $line["count"];
-               }
-
-               foreach (array_keys($tags) as $tag) {
-                       $unread = $tags[$tag];
-                       $tag = htmlspecialchars($tag);
-
-                       $cv = array("id" => $tag,
-                               "kind" => "tag",
-                               "counter" => $unread);
-
-                       array_push($ret_arr, $cv);
-               }
-
-               return $ret_arr;
-       }
-
        function getVirtCounters($link) {
 
                $ret_arr = array();
index e66fcb45dd14177b36f322cdf74ab08d31b251c4..f4196a7265780ab2519e0b97d546fc58bd018632 100644 (file)
@@ -3,8 +3,6 @@ var _infscroll_request_sent = 0;
 var _search_query = false;
 var _viewfeed_last = 0;
 
-var counter_timeout_id = false;
-
 var counters_last_request = 0;
 
 function viewCategory(cat) {
@@ -218,7 +216,8 @@ function feedlist_init() {
 
                hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
 
-               setTimeout("timeout()", 5000);
+               request_counters(true);
+               timeout();
                setTimeout("precache_headlines_idle()", 15000);
 
        } catch (e) {
@@ -226,46 +225,34 @@ function feedlist_init() {
        }
 }
 
-function request_counters_real() {
-       try {
-               console.log("requesting counters...");
-
-               var query = "?op=rpc&method=getAllCounters&seq=" + next_seq();
-
-               query = query + "&omode=flc";
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               try {
-                                       handle_rpc_json(transport);
-                               } catch (e) {
-                                       exception_error("viewfeed/getcounters", e);
-                               }
-                       } });
-
-       } catch (e) {
-               exception_error("request_counters_real", e);
-       }
-}
-
-
-function request_counters() {
 
+function request_counters(force) {
        try {
-
-               //if (getInitParam("bw_limit") == "1") return;
-
                var date = new Date();
                var timestamp = Math.round(date.getTime() / 1000);
 
-               if (timestamp - counters_last_request > 5) {
+               if (force || timestamp - counters_last_request > 15) {
                        console.log("scheduling request of counters...");
 
-                       window.clearTimeout(counter_timeout_id);
-                       counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
-
                        counters_last_request = timestamp;
+
+                       var query = "?op=rpc&method=getAllCounters&seq=" + next_seq();
+
+                       if (!force)
+                               query = query + "&last_article_id=" + getInitParam("last_article_id");
+
+                       console.log(query);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       try {
+                                               handle_rpc_json(transport);
+                                       } catch (e) {
+                                               exception_error("request_counters", e);
+                                       }
+                               } });
+
                } else {
                        console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
                }
@@ -567,6 +554,8 @@ function decrementFeedCounter(feed, is_cat) {
 
                if (ctr > 0) {
                        setFeedUnread(feed, is_cat, ctr - 1);
+                       global_unread = global_unread - 1;
+                       updateTitle();
 
                        if (!is_cat) {
                                var cat = parseInt(getFeedCategory(feed));
index bfbb40684ba6d66e5e93d66ba636c992a8729ad2..7cbe3cfc56e1037d9d5089858dbbf4fc7e0a8edf 100644 (file)
@@ -1,14 +1,9 @@
-var total_unread = 0;
 var global_unread = -1;
-var firsttime_update = true;
 var _active_feed_id = undefined;
 var _active_feed_is_cat = false;
 var hotkey_prefix = false;
 var hotkey_prefix_pressed = false;
-var _force_scheduled_update = false;
-var last_scheduled_update = false;
 var _widescreen_mode = false;
-
 var _rpc_seq = 0;
 
 function next_seq() {
@@ -105,8 +100,6 @@ function updateFeedList() {
                id: "feedTree",
                }, "feedTree");
 
-               _force_scheduled_update = true;
-
 /*             var menu = new dijit.Menu({id: 'feedMenu'});
 
                menu.addChild(new dijit.MenuItem({
@@ -176,51 +169,10 @@ function viewCurrentFeed(method) {
 }
 
 function timeout() {
-       if (getInitParam("bw_limit") == "1") return;
-
-       try {
-          var date = new Date();
-      var ts = Math.round(date.getTime() / 1000);
-
-               if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
-
-                       //console.log("timeout()");
-
-                       window.clearTimeout(counter_timeout_id);
-
-                       var query_str = "?op=rpc&method=getAllCounters&seq=" + next_seq();
-
-                       var omode;
-
-                       if (firsttime_update && !navigator.userAgent.match("Opera")) {
-                               firsttime_update = false;
-                               omode = "T";
-                       } else {
-                               omode = "flc";
-                       }
-
-                       query_str = query_str + "&omode=" + omode;
-
-                       if (!_force_scheduled_update)
-                               query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
-
-                       //console.log("[timeout]" + query_str);
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query_str,
-                               onComplete: function(transport) {
-                                               handle_rpc_json(transport, !_force_scheduled_update);
-                                               _force_scheduled_update = false;
-                                       } });
-
-                       last_scheduled_update = ts;
-               }
-
-       } catch (e) {
-               exception_error("timeout", e);
+       if (getInitParam("bw_limit") != "1") {
+               request_counters();
+               setTimeout("timeout()", 60*1000);
        }
-
-       setTimeout("timeout()", 3000);
 }
 
 function search() {
@@ -960,7 +912,7 @@ function handle_rpc_json(transport, scheduled_call) {
                                if (message == "UPDATE_COUNTERS") {
                                        console.log("need to refresh counters...");
                                        setInitParam("last_article_id", -1);
-                                       _force_scheduled_update = true;
+                                       request_counters(true);
                                }
                        }
 
index d6801a186a1e8a201e63a91397d26d9a785b7311..a59e28a5f6fc8db0eb5c12841b98ba616c330e1f 100644 (file)
@@ -1650,6 +1650,8 @@ function cdmClicked(event, id) {
                        zoomToArticle(event, id);
                }
 
+               request_counters();
+
        } catch (e) {
                exception_error("cdmClicked");
        }
@@ -2058,7 +2060,7 @@ function render_local_headlines(feed, is_cat, obj) {
 
 function precache_headlines_idle() {
        try {
-               if (!feed_precache_timeout_id) {
+               if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
                        if (get_timestamp() - _viewfeed_last > 120) {
 
                                var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
@@ -2084,8 +2086,8 @@ function precache_headlines_idle() {
 
 function precache_headlines() {
        try {
+               if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
 
-               if (!feed_precache_timeout_id) {
                        feed_precache_timeout_id = window.setTimeout(function() {
                                var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
                                var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());