var query = "?op=feeds&subop=catsort&corder=" +
param_escape(ordered_cats.toString());
- console.log(query);
+ //console.log(query);
new Ajax.Request("backend.php", { parameters: query });
}
try {
loading_set_progress(90);
- console.log("in feedlist init");
+ //console.log("in feedlist init");
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
document.onkeydown = hotkey_handler;
function init_collapsable_feedlist() {
try {
- console.log("init_collapsable_feedlist");
+ //console.log("init_collapsable_feedlist");
var theme = getInitParam("theme");
var options = getInitParam("theme_options");
parameters: query,
onComplete: function(transport) {
try {
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} catch (e) {
exception_error("viewfeed/getcounters", e);
}
var feeds_stored = number_of_feeds;
- console.log("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
+ //console.log("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
if (feeds_stored != feeds_found) {
number_of_feeds = feeds_found;
}
}
-function parse_counters_reply(transport, scheduled_call) {
+/*function parse_counters_reply(transport, scheduled_call) {
if (!transport.responseXML) {
notify_error("Backend did not return valid XML", true);
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
-}
+} */
-function all_counters_callback2(transport) {
+function handle_rpc_reply(transport, scheduled_call) {
try {
- if (offline_mode) return;
+ if (offline_mode) return false;
+
+ if (!transport.responseText && db) {
+ offlineConfirmModeChange();
+ return false;
+ }
+
+ if (transport.responseXML) {
+
+ if (!transport_error_check(transport)) return false;
- parse_counters_reply(transport);
+ var message = transport.responseXML.getElementsByTagName("message")[0];
+
+ if (message) {
+ message = message.firstChild.nodeValue;
+
+ if (message == "UPDATE_COUNTERS") {
+ setInitParam("last_article_id", -1);
+ _force_scheduled_update = true;
+ }
+ }
+
+ var counters = transport.responseXML.getElementsByTagName("counters")[0];
+
+ if (counters)
+ parse_counters(counters, scheduled_call);
+
+ var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
+
+ if (runtime_info)
+ parse_runtime_info(runtime_info);
+
+ if (feedsSortByUnread())
+ resort_feedlist();
+
+ hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
+
+ } else {
+ notify_error("Error communicating with server.");
+ }
} catch (e) {
- exception_error("all_counters_callback2", e, transport);
+ exception_error("handle_rpc_reply", e, transport);
}
+
+ return true;
}
function get_feed_unread(id) {
try {
- console.log("hideOrShowFeeds: " + hide);
+ //console.log("hideOrShowFeeds: " + hide);
if ($("FCATLIST--1")) {
var cat_unread = 0;
if (!node) {
- console.log("hideOrShowFeeds: passed node is null, aborting");
+ console.warn("hideOrShowFeeds: passed node is null, aborting");
return;
}
if (!limit) limit = 3;
- console.log("getRelativePostIds: " + id + " limit=" + limit);
+ //console.log("getRelativePostIds: " + id + " limit=" + limit);
var ids = new Array();
var container = $("headlinesList");
$data['num_feeds'] = (int) $num_feeds;
+ $data['last_article_id'] = getLastArticleId($link);
+
if (ENABLE_UPDATE_DAEMON) {
$data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
}
}
+ function getLastArticleId($link) {
+ $result = db_query($link, "SELECT MAX(ref_id) AS id FROM ttrss_user_entries
+ WHERE owner_uid = " . $_SESSION["uid"]);
+
+ if (db_num_rows($result) == 1) {
+ return db_fetch_result($result, 0, "id");
+ } else {
+ return -1;
+ }
+ }
?>
$result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply><counters><![CDATA[";
- print json_encode(getAllCounters($link));
- print "]]></counters></rpc-reply>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
+ print "</rpc-reply>";
return;
}
$result = db_query($link, "DELETE FROM ttrss_user_entries
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply><counters><![CDATA[";
- print json_encode(getAllCounters($link));
- print "]]></counters></rpc-reply>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
+ print "</rpc-reply>";
return;
}
SET feed_id = orig_feed_id, orig_feed_id = NULL
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply><counters><![CDATA[";
- print json_encode(getAllCounters($link));
- print "]]></counters></rpc-reply>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
+ print "</rpc-reply>";
return;
}
archive_article($link, $id, $_SESSION["uid"]);
}
- print "<rpc-reply><counters><![CDATA[";
- print json_encode(getAllCounters($link));
- print "]]></counters></rpc-reply>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
+ print "</rpc-reply>";
return;
}
print "<rpc-reply>";
- print "<counters><![CDATA[";
- print json_encode(getAllCounters($link));
- print "]]></counters>";
-
if ($note != 'undefined') {
$note_size = strlen($note);
print "<note id=\"$id\" size=\"$note_size\">";
print "</note>";
}
+ print "<message>UPDATE_COUNTERS</message>";
+
print "</rpc-reply>";
return;
update_rss_feed($link, $feed_id);
- print "<rpc-reply>";
- print "<counters><![CDATA[";
- print json_encode(getFeedCounters($link, $feed_id));
- print "]]></counters>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
-
+
return;
}
if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
-
- $global_unread_caller = sprintf("%d", $_REQUEST["uctr"]);
- $global_unread = getGlobalUnread($link);
+
+ $last_article_id = (int) $_REQUEST["last_article_id"];
print "<rpc-reply>";
- if ($global_unread_caller != $global_unread) {
+ if ($last_article_id != getLastArticleId($link)) {
print "<counters><![CDATA[";
$omode = $_REQUEST["omode"];
- print json_encode(getAllCounters($link, $omode));
+
+ if ($omode != "T")
+ print json_encode(getAllCounters($link, $omode));
+ else
+ print json_encode(getGlobalCounters($link));
+
print "]]></counters>";
}
catchupArticlesById($link, $ids, $cmode);
print "<rpc-reply>";
- print "<counters><![CDATA[";
- print json_encode(getAllCounters($link, $_REQUEST['omode']));
- print "]]></counters>";
-
- print_runtime_info($link);
+ print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return;
markArticlesById($link, $ids, $cmode);
print "<rpc-reply>";
- print "<counters><![CDATA[";
- print json_encode(getAllCounters($link, $_REQUEST['omode']));
- print "]]></counters>";
- print_runtime_info($link);
+ print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return;
publishArticlesById($link, $ids, $cmode);
print "<rpc-reply>";
- print "<counters><![CDATA[";
- print json_encode(getAllCounters($link, $_REQUEST['omode']));
- print "]]></counters>";
- print_runtime_info($link);
+ print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return;
print "</info-for-headlines>";
- print "<counters><![CDATA[";
- print json_encode(getAllCounters($link, $_REQUEST['omode']));
- print "]]></counters>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return;
print "</info-for-headlines>";
- print "<counters><![CDATA[";
- print json_encode(getAllCounters($link, $_REQUEST['omode']));
- print "]]></counters>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return;
print "<error><![CDATA[" . $mail->ErrorInfo . "]]></error>";
} else {
save_email_address($link, db_escape_string($destination));
- print "<message>OK</message>";
+ print "<message>UPDATE_COUNTERS</message>";
}
} else {
db_query($link, "DELETE FROM ttrss_access_keys WHERE
owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply><message>OK</message></rpc-reply>";
+ print "<rpc-reply>";
+ print "<message>UPDATE_COUNTERS</message>";
+ print "</rpc-reply>";
return;
}
-
var total_unread = 0;
-var first_run = true;
var display_tags = false;
var global_unread = -1;
-var current_subtitle = "";
-var daemon_enabled = false;
-//var _qfd_deleted_feed = 0;
var firsttime_update = true;
var _active_feed_id = 0;
var _active_feed_is_cat = false;
var number_of_feeds = 0;
-var _hfd_scrolltop = 0;
var hotkey_prefix = false;
var hotkey_prefix_pressed = false;
-var init_params = new Object();
+var init_params = {};
var ver_offset = 0;
var hor_offset = 0;
var feeds_sort_by_unread = false;
var feedlist_sortable_enabled = false;
+var _force_scheduled_update = false;
+var last_scheduled_update = false;
function activeFeedIsCat() {
return _active_feed_is_cat;
closeInfoBox();
}
-function scheduleFeedUpdate() {
-
- window.clearTimeout(counter_timeout_id);
-
- var query_str = "backend.php?op=rpc&subop=getAllCounters";
-
- var omode;
-
- if (firsttime_update && !navigator.userAgent.match("Opera")) {
- firsttime_update = false;
- omode = "T";
- } else {
- if (display_tags) {
- omode = "tl";
- } else {
- omode = "flc";
- }
- }
-
- query_str = query_str + "&omode=" + omode;
- query_str = query_str + "&uctr=" + global_unread;
-
- console.log("[scheduleFeedUpdate] " + query_str);
-
- new Ajax.Request("backend.php", {
- parameters: query_str,
- onComplete: function(transport) {
- parse_counters_reply(transport, true);
- } });
-}
-
function updateFeedList() {
try {
- console.log("updateFeedList");
+ //console.log("updateFeedList");
if (offline_mode) return render_offline_feedlist();
notify_progress("Marking all feeds as read...");
- console.log("catchupAllFeeds Q=" + query_str);
+ //console.log("catchupAllFeeds Q=" + query_str);
new Ajax.Request("backend.php", {
parameters: query_str,
return false; // block unneeded form submits
}
-function viewfeed(feed, subop) {
+/*function viewfeed(feed, subop) {
var f = window.frames["feeds-frame"];
f.viewfeed(feed, subop);
-}
+} */
function timeout() {
if (getInitParam("bw_limit") == "1") return;
- scheduleFeedUpdate(false);
+ try {
+ var date = new Date();
+ var ts = Math.round(date.getTime() / 1000);
+
+ if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
- setTimeout("timeout()", 10*1000);
+ window.clearTimeout(counter_timeout_id);
+
+ var query_str = "?op=rpc&subop=getAllCounters";
+
+ var omode;
+
+ if (firsttime_update && !navigator.userAgent.match("Opera")) {
+ firsttime_update = false;
+ omode = "T";
+ } else {
+ if (display_tags) {
+ omode = "tl";
+ } else {
+ omode = "flc";
+ }
+ }
+
+ query_str = query_str + "&omode=" + omode;
+ 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_reply(transport, true);
+ } });
+
+ last_scheduled_update = ts;
+ }
+
+ } catch (e) {
+ exception_error("timeout", e);
+ }
+
+ setTimeout("timeout()", 3000);
}
function resetSearch() {
viewCurrentFeed(0, "");
}
-// if argument is undefined, current subtitle is not updated
-// use blank string to clear subtitle
-function updateTitle(s) {
+function updateTitle() {
var tmp = "Tiny Tiny RSS";
- if (s != undefined) {
- current_subtitle = s;
- }
-
if (global_unread > 0) {
tmp = tmp + " (" + global_unread + ")";
}
- if (current_subtitle) {
- tmp = tmp + " - " + current_subtitle;
- }
-
if (window.fluid) {
if (global_unread > 0) {
window.fluid.dockBadge = global_unread;
dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by"));
- daemon_enabled = getInitParam("daemon_enabled") == 1;
feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
setTimeout('updateFeedList(false, false)', 50);
return;
}
- if (opid == "qmcUpdateFeeds") {
- scheduleFeedUpdate(true);
- return;
- }
-
if (opid == "qmcCatchupAll") {
catchupAllFeeds();
return;
function parse_runtime_info(elem) {
if (!elem || !elem.firstChild) {
+ console.warn("parse_runtime_info: invalid node passed");
return;
}
var data = JSON.parse(elem.firstChild.nodeValue);
- console.log("parsing runtime info...");
+ //console.log("parsing runtime info...");
for (k in data) {
var v = data[k];
- console.log("RI: " + k + " => " + v);
+ // console.log("RI: " + k + " => " + v);
- if (k == "num_feeds") {
+ if (k == "num_feeds" || k == "last_article_id") {
init_params[k] = v;
}
function collapse_feedlist() {
try {
- console.log("collapse_feedlist");
+ //console.log("collapse_feedlist");
var theme = getInitParam("theme");
if (theme != "" &&
return false;
}
- if (keycode == 82 && shift_key) { // R
+/* if (keycode == 82 && shift_key) { // R
scheduleFeedUpdate(true);
return;
- }
+ } */
if (keycode == 74) { // j
var feed = getActiveFeedId();
return false;
}
- if (keycode == 85 && shift_key) { // U
+/* if (keycode == 85 && shift_key) { // U
scheduleFeedUpdate(true);
return false;
- }
+ } */
if (keycode == 85) { // u
if (getActiveFeedId()) {
try {
console.log("catchup_callback2 " + transport + ", " + callback);
notify("");
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
if (callback) {
setTimeout(callback, 10);
}
function headlines_callback2(transport, feed_cur_page) {
try {
- if (!transport.responseText && db) {
- offlineConfirmModeChange();
- return;
- }
+ if (!handle_rpc_reply(transport)) return;
loading_set_progress(100);
var f = $("headlines-frame");
try {
if (feed_cur_page == 0) {
- console.log("resetting headlines scrollTop");
+ //console.log("resetting headlines scrollTop");
f.scrollTop = 0;
}
} catch (e) { };
if (headlines_info)
headlines_info = JSON.parse(headlines_info.firstChild.nodeValue);
- else
- console.log("didn't find headlines-info object in response");
+ else {
+ console.error("didn't find headlines-info object in response");
+ return;
+ }
var headlines_count = headlines_info.count;
var headlines_unread = headlines_info.unread;
}
} else {
- console.log("headlines_callback: returned no data");
+ console.warn("headlines_callback: returned no data");
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
}
} else {
if (headlines) {
if (headlines_count > 0) {
- console.log("adding some more headlines...");
+ console.warn("adding some more headlines...");
var c = $("headlinesList");
console.log("no new headlines received");
}
} else {
- console.log("headlines_callback: returned no data");
+ console.warn("headlines_callback: returned no data");
notify_error("Error while trying to load more headlines");
}
if (articles) {
for (var i = 0; i < articles.length; i++) {
var a_id = articles[i].getAttribute("id");
- console.log("found id: " + a_id);
+ //console.log("found id: " + a_id);
cache_inject(a_id, articles[i].firstChild.nodeValue);
}
} else {
console.log("no cached articles received");
}
- if (counters) {
- console.log("parsing piggybacked counters: " + counters);
- parse_counters(counters, false);
- } else {
- console.log("counters container not found in reply, requesting...");
- request_counters();
- }
-
+ request_counters();
+
if (runtime_info) {
- console.log("parsing runtime info: " + runtime_info[0]);
parse_runtime_info(runtime_info[0]);
- } else {
- console.log("runtime info container not found in reply");
- }
+ }
} else {
- console.log("headlines_callback: returned no XML object");
+ console.warn("headlines_callback: returned no XML object");
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
}
try {
console.log("article_callback2 " + id);
- if (!transport.responseText && db) {
- offlineConfirmModeChange();
- return;
- }
+ if (!handle_rpc_reply(transport)) return;
if (transport.responseXML) {
active_post_id = id;
- console.log("looking for articles to cache...");
+ //console.log("looking for articles to cache...");
var articles = transport.responseXML.getElementsByTagName("article");
for (var i = 0; i < articles.length; i++) {
var a_id = articles[i].getAttribute("id");
- console.log("found id: " + a_id);
+ //console.log("found id: " + a_id);
if (a_id == active_post_id) {
- console.log("active article, rendering...");
+ //console.log("active article, rendering...");
render_article(articles[i].firstChild.nodeValue);
}
var reply = transport.responseXML.firstChild.firstChild;
} else {
- console.log("article_callback: returned no XML object");
+ console.warn("article_callback: returned no XML object");
//var f = $("content-frame");
//f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
}
setTimeout('updateFeedList(false, false)', 50);
_reload_feedlist_after_view = false;
} else {
- if (transport.responseXML) {
- var counters = transport.responseXML.getElementsByTagName("counters")[0];
-
- if (counters) {
- console.log("parsing piggybacked counters: " + counters);
- parse_counters(counters, false);
- } else {
- console.log("counters container not found in reply, requesting...");
- request_counters();
- }
- }
+ request_counters();
}
notify("");
try {
var elem = effect.effects[0].element;
- console.log("tMark_afh_off : " + elem.id);
+ //console.log("tMark_afh_off : " + elem.id);
if (elem) {
elem.src = elem.src.replace("mark_set", "mark_unset");
try {
var elem = effect.effects[0].element;
- console.log("tPub_afh_off : " + elem.id);
+ //console.log("tPub_afh_off : " + elem.id);
if (elem) {
elem.src = elem.src.replace("pub_set", "pub_unset");
if (!no_effects) update_local_feedlist_counters();
if (!client_only) {
- console.log(query);
+ //console.log(query);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} });
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
var note = transport.responseXML.getElementsByTagName("note")[0];
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} });
}
parameters: query,
onComplete: function(transport) {
show_labels_in_headlines(transport);
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} });
// }
parameters: query,
onComplete: function(transport) {
show_labels_in_headlines(transport);
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} });
// }
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} });
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} });
}
query = "?op=rpc&subop=setArticleTags&" + query;
- console.log(query);
+ //console.log(query);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
try {
- console.log("tags saved...");
+ //console.log("tags saved...");
closeInfoBox();
notify("");
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- all_counters_callback2(transport);
+ handle_rpc_reply(transport);
} });
}
try {
if (!cache_check_param(id, param)) {
- console.log("cache_article: miss: " + id + " [p=" + param + "]");
+ //console.log("cache_article: miss: " + id + " [p=" + param + "]");
var date = new Date();
var ts = Math.round(date.getTime() / 1000);
}
} else {
- console.log("cache_article: hit: " + id + " [p=" + param + "]");
+ //console.log("cache_article: hit: " + id + " [p=" + param + "]");
}
} catch (e) {
exception_error("cache_inject", e);
while (i < article_cache.length) {
if (article_cache[i]["id"] == id) {
- console.log("cache_invalidate: removed id " + id);
+ //console.log("cache_invalidate: removed id " + id);
article_cache.splice(i, 1);
return true;
}
}
}
- console.log("cache_invalidate: id not found: " + id);
+ //console.log("cache_invalidate: id not found: " + id);
return false;
} catch (e) {
exception_error("cache_invalidate", e);
if (preload_id_batch.indexOf(id) == -1)
preload_id_batch.push(id);
- console.log("preload ids batch: " + preload_id_batch.toString());
+ //console.log("preload ids batch: " + preload_id_batch.toString());
window.clearTimeout(preload_timeout_id);
preload_batch_timeout_id = window.setTimeout('preloadBatchedArticles()', 1000);
if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
if (!_infscroll_disable) {
- console.log("more cowbell!");
viewNextFeedPage();
}
}