mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-20 21:41:28 +00:00
remove xml from getAllCounters rpc call, use pure JSON
This commit is contained in:
@@ -232,7 +232,7 @@ function request_counters_real() {
|
|||||||
parameters: query,
|
parameters: query,
|
||||||
onComplete: function(transport) {
|
onComplete: function(transport) {
|
||||||
try {
|
try {
|
||||||
handle_rpc_reply(transport);
|
handle_rpc_json(transport);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exception_error("viewfeed/getcounters", e);
|
exception_error("viewfeed/getcounters", e);
|
||||||
}
|
}
|
||||||
@@ -286,13 +286,11 @@ function displayNewContentPrompt(id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_counters(reply, scheduled_call) {
|
function parse_counters(elems, scheduled_call) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var feeds_found = 0;
|
var feeds_found = 0;
|
||||||
|
|
||||||
var elems = JSON.parse(reply.firstChild.nodeValue);
|
|
||||||
|
|
||||||
for (var l = 0; l < elems.length; l++) {
|
for (var l = 0; l < elems.length; l++) {
|
||||||
|
|
||||||
var id = elems[l].id
|
var id = elems[l].id
|
||||||
|
|||||||
@@ -282,29 +282,27 @@
|
|||||||
|
|
||||||
if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
|
if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
|
||||||
|
|
||||||
|
header("Content-Type: text/plain");
|
||||||
|
|
||||||
$last_article_id = (int) $_REQUEST["last_article_id"];
|
$last_article_id = (int) $_REQUEST["last_article_id"];
|
||||||
|
|
||||||
print "<rpc-reply>";
|
$reply = array();
|
||||||
|
|
||||||
if ($seq)
|
if ($seq) $reply['seq'] = $seq;
|
||||||
print "<seq>$seq</seq>";
|
|
||||||
|
|
||||||
if ($last_article_id != getLastArticleId($link)) {
|
if ($last_article_id != getLastArticleId($link)) {
|
||||||
print "<counters><![CDATA[";
|
|
||||||
$omode = $_REQUEST["omode"];
|
$omode = $_REQUEST["omode"];
|
||||||
|
|
||||||
if ($omode != "T")
|
if ($omode != "T")
|
||||||
print json_encode(getAllCounters($link, $omode));
|
$reply['counters'] = getAllCounters($link, $omode);
|
||||||
else
|
else
|
||||||
print json_encode(getGlobalCounters($link));
|
$reply['counters'] = getGlobalCounters($link);
|
||||||
|
|
||||||
print "]]></counters>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_runtime_info($link);
|
$reply['runtime-info'] = make_runtime_info($link);
|
||||||
|
|
||||||
print "</rpc-reply>";
|
|
||||||
|
|
||||||
|
print json_encode($reply);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -983,7 +981,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($subop == "getTweetInfo") {
|
if ($subop == "getTweetInfo") {
|
||||||
header("Content-Type: text/html");
|
header("Content-Type: text/plain");
|
||||||
$id = db_escape_string($_REQUEST['id']);
|
$id = db_escape_string($_REQUEST['id']);
|
||||||
|
|
||||||
$result = db_query($link, "SELECT title, link
|
$result = db_query($link, "SELECT title, link
|
||||||
|
|||||||
76
tt-rss.js
76
tt-rss.js
@@ -207,7 +207,7 @@ function timeout() {
|
|||||||
new Ajax.Request("backend.php", {
|
new Ajax.Request("backend.php", {
|
||||||
parameters: query_str,
|
parameters: query_str,
|
||||||
onComplete: function(transport) {
|
onComplete: function(transport) {
|
||||||
handle_rpc_reply(transport, !_force_scheduled_update);
|
handle_rpc_json(transport, !_force_scheduled_update);
|
||||||
_force_scheduled_update = false;
|
_force_scheduled_update = false;
|
||||||
} });
|
} });
|
||||||
|
|
||||||
@@ -472,14 +472,7 @@ function toggleDispRead() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_runtime_info(elem) {
|
function parse_runtime_info(data) {
|
||||||
|
|
||||||
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...");
|
||||||
|
|
||||||
@@ -1044,12 +1037,12 @@ function handle_rpc_reply(transport, scheduled_call) {
|
|||||||
var counters = transport.responseXML.getElementsByTagName("counters")[0];
|
var counters = transport.responseXML.getElementsByTagName("counters")[0];
|
||||||
|
|
||||||
if (counters)
|
if (counters)
|
||||||
parse_counters(counters, scheduled_call);
|
parse_counters(JSON.parse(counters.firstChild.nodeValue), scheduled_call);
|
||||||
|
|
||||||
var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
|
var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
|
||||||
|
|
||||||
if (runtime_info)
|
if (runtime_info)
|
||||||
parse_runtime_info(runtime_info);
|
parse_runtime_info(JSON.parse(runtime_info.firstChild.nodeValue));
|
||||||
|
|
||||||
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
||||||
|
|
||||||
@@ -1125,3 +1118,64 @@ function newVersionDlg() {
|
|||||||
exception_error("newVersionDlg", e);
|
exception_error("newVersionDlg", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handle_rpc_json(transport, scheduled_call) {
|
||||||
|
try {
|
||||||
|
var reply = JSON.parse(transport.responseText);
|
||||||
|
|
||||||
|
if (reply) {
|
||||||
|
|
||||||
|
var error = reply['error'];
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
var code = error['code'];
|
||||||
|
var msg = error['msg'];
|
||||||
|
if (code != 0) {
|
||||||
|
fatalError(code, msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var seq = reply['seq'];
|
||||||
|
|
||||||
|
if (seq) {
|
||||||
|
if (get_seq() != seq) {
|
||||||
|
console.log("[handle_rpc_json] sequence mismatch: " + seq +
|
||||||
|
" (want: " + get_seq() + ")");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = reply['message'];
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
if (message == "UPDATE_COUNTERS") {
|
||||||
|
console.log("need to refresh counters...");
|
||||||
|
setInitParam("last_article_id", -1);
|
||||||
|
_force_scheduled_update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var counters = reply['counters'];
|
||||||
|
|
||||||
|
if (counters)
|
||||||
|
parse_counters(counters, scheduled_call);
|
||||||
|
|
||||||
|
var runtime_info = reply['runtime-info'];;
|
||||||
|
|
||||||
|
if (runtime_info)
|
||||||
|
parse_runtime_info(runtime_info);
|
||||||
|
|
||||||
|
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
notify_error("Error communicating with server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
exception_error("handle_rpc_json", e, transport);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,10 +172,6 @@ function headlines_callback2(transport, feed_cur_page) {
|
|||||||
else
|
else
|
||||||
request_counters();
|
request_counters();
|
||||||
|
|
||||||
if (runtime_info) {
|
|
||||||
parse_runtime_info(runtime_info[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.warn("headlines_callback: returned no XML object");
|
console.warn("headlines_callback: returned no XML object");
|
||||||
dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
|
dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
|
||||||
|
|||||||
Reference in New Issue
Block a user