1
0
mirror of https://tt-rss.org/git/tt-rss.git synced 2024-07-02 12:50:52 +02:00

switch view() to async

This commit is contained in:
Andrew Dolgov 2007-08-24 08:53:35 +01:00
parent 1c9df66e41
commit 71d277deec

View File

@ -196,15 +196,40 @@ function render_article(article) {
} }
} }
function article_callback() { function showArticleInHeadlines(id) {
if (xmlhttp.readyState == 4) {
debug("article_callback");
cleanSelected("headlinesList");
var crow = document.getElementById("RROW-" + id);
var article_is_unread = crow.className.match("Unread");
crow.className = crow.className.replace("Unread", "");
var upd_img_pic = document.getElementById("FUPDPIC-" + id);
if (upd_img_pic) {
upd_img_pic.src = "images/blank_icon.gif";
}
selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
markHeadline(id);
}
function article_callback2(transport, id, feed_id) {
try { try {
if (xmlhttp.responseXML) { debug("article_callback2 " + id);
var reply = xmlhttp.responseXML.firstChild.firstChild;
var articles = xmlhttp.responseXML.getElementsByTagName("article"); if (transport.responseXML) {
active_real_feed_id = feed_id;
active_post_id = id;
showArticleInHeadlines(id);
var reply = transport.responseXML.firstChild.firstChild;
var articles = transport.responseXML.getElementsByTagName("article");
for (var i = 0; i < articles.length; i++) { for (var i = 0; i < articles.length; i++) {
var a_id = articles[i].getAttribute("id"); var a_id = articles[i].getAttribute("id");
@ -224,9 +249,6 @@ function article_callback() {
var f = document.getElementById("content-frame"); var f = document.getElementById("content-frame");
f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>"; f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
} }
} catch (e) {
exception_error("article_callback", e);
}
var date = new Date(); var date = new Date();
last_article_view = date.getTime() / 1000; last_article_view = date.getTime() / 1000;
@ -239,7 +261,7 @@ function article_callback() {
setTimeout('updateFeedList(false, false)', 50); setTimeout('updateFeedList(false, false)', 50);
_reload_feedlist_after_view = false; _reload_feedlist_after_view = false;
} else { } else {
var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; var counters = transport.responseXML.getElementsByTagName("counters")[0];
if (counters) { if (counters) {
debug("parsing piggybacked counters: " + counters); debug("parsing piggybacked counters: " + counters);
@ -250,6 +272,8 @@ function article_callback() {
} }
notify(""); notify("");
} catch (e) {
exception_error("article_callback2", e);
} }
} }
@ -258,8 +282,6 @@ function view(id, feed_id, skip_history) {
try { try {
debug("loading article: " + id + "/" + feed_id); debug("loading article: " + id + "/" + feed_id);
active_real_feed_id = feed_id;
var cached_article = cache_find(id); var cached_article = cache_find(id);
debug("cache check result: " + (cached_article != false)); debug("cache check result: " + (cached_article != false));
@ -273,7 +295,7 @@ function view(id, feed_id, skip_history) {
var date = new Date(); var date = new Date();
if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) { /* if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
debug("<b>xmlhttp seems to be stuck at view, aborting</b>"); debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
xmlhttp.abort(); xmlhttp.abort();
if (is_safari()) { if (is_safari()) {
@ -282,27 +304,7 @@ function view(id, feed_id, skip_history) {
} }
} }
if (xmlhttp_ready(xmlhttp)) { if (xmlhttp_ready(xmlhttp)) { */
active_post_id = id;
cleanSelected("headlinesList");
var crow = document.getElementById("RROW-" + active_post_id);
var article_is_unread = crow.className.match("Unread");
debug("article is unread: " + article_is_unread);
crow.className = crow.className.replace("Unread", "");
var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
if (upd_img_pic) {
upd_img_pic.src = "images/blank_icon.gif";
}
selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
markHeadline(active_post_id);
var neighbor_ids = getRelativePostIds(active_post_id); var neighbor_ids = getRelativePostIds(active_post_id);
@ -332,47 +334,33 @@ function view(id, feed_id, skip_history) {
query = query + "&cids=" + cids_to_request.toString(); query = query + "&cids=" + cids_to_request.toString();
var crow = document.getElementById("RROW-" + id);
var article_is_unread = crow.className.match("Unread");
showArticleInHeadlines(id);
if (!cached_article) { if (!cached_article) {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
debug(query);
xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange=article_callback;
xmlhttp.send(null);
} else if (cached_article && article_is_unread) { } else if (cached_article && article_is_unread) {
query = query + "&mode=prefetch"; query = query + "&mode=prefetch";
debug(query);
xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange=article_callback;
xmlhttp.send(null);
render_article(cached_article); render_article(cached_article);
} else if (cached_article) { } else if (cached_article) {
query = query + "&mode=prefetch_old"; query = query + "&mode=prefetch_old";
debug(query);
xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange=article_callback;
xmlhttp.send(null);
render_article(cached_article); render_article(cached_article);
} }
cache_expire(); cache_expire();
} else { new Ajax.Request(query, {
debug("xmlhttp busy (@view)"); onComplete: function(transport) {
printLockingError(); article_callback2(transport, id, feed_id);
} } });
} catch (e) { } catch (e) {
exception_error("view", e); exception_error("view", e);