/* 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() {
$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 */
}
}
- 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();
var _search_query = false;
var _viewfeed_last = 0;
-var counter_timeout_id = false;
-
var counters_last_request = 0;
function viewCategory(cat) {
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
- setTimeout("timeout()", 5000);
+ request_counters(true);
+ timeout();
setTimeout("precache_headlines_idle()", 15000);
} catch (e) {
}
}
-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));
}
if (ctr > 0) {
setFeedUnread(feed, is_cat, ctr - 1);
+ global_unread = global_unread - 1;
+ updateTitle();
if (!is_cat) {
var cat = parseInt(getFeedCategory(feed));
-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() {
id: "feedTree",
}, "feedTree");
- _force_scheduled_update = true;
-
/* var menu = new dijit.Menu({id: 'feedMenu'});
menu.addChild(new dijit.MenuItem({
}
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() {
if (message == "UPDATE_COUNTERS") {
console.log("need to refresh counters...");
setInitParam("last_article_id", -1);
- _force_scheduled_update = true;
+ request_counters(true);
}
}
zoomToArticle(event, id);
}
+ request_counters();
+
} catch (e) {
exception_error("cdmClicked");
}
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();
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());