viewfeed: remove (tons of) obsolete code

master
Andrew Dolgov 6 years ago
parent 069ecb6c2e
commit 468faee635

@ -1,9 +1,9 @@
let _infscroll_disable = 0; let infscroll_in_progress = 0;
let _infscroll_request_sent = 0; let infscroll_disabled = 0;
let _infscroll_timeout = false;
let _search_query = false; let _search_query = false;
let _viewfeed_last = 0; let _viewfeed_wait_timeout = false;
let _viewfeed_timeout = false;
let counters_last_request = 0; let counters_last_request = 0;
let _counters_prev = []; let _counters_prev = [];
@ -55,42 +55,31 @@ function cleanup_memory(root) {
function viewfeed(params) { function viewfeed(params) {
const feed = params.feed; const feed = params.feed;
let is_cat = !!params.is_cat || false; const is_cat = !!params.is_cat || false;
let offset = params.offset || 0; const offset = params.offset || 0;
let background = params.background || false;
let infscroll_req = params.infscroll_req || false;
const can_wait = params.can_wait;
const viewfeed_debug = params.viewfeed_debug; const viewfeed_debug = params.viewfeed_debug;
const method = params.method; const method = params.method;
// this is used to quickly switch between feeds, sets active but xhr is on a timeout
if (infscroll_req == undefined) infscroll_req = false; const delayed = params.delayed || false;
last_requested_article = 0;
if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) { if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) {
if (!background && _search_query) _search_query = false; _search_query = false;
} }
if (!background) { if (offset != 0) {
_viewfeed_last = get_timestamp(); if (infscroll_in_progress)
return;
if (getActiveFeedId() != feed || !infscroll_req) {
setActiveArticleId(0);
_infscroll_disable = 0;
cleanup_memory("headlines-frame"); infscroll_in_progress = 1;
}
if (infscroll_req) { window.clearTimeout(_infscroll_timeout);
const timestamp = get_timestamp(); _infscroll_timeout = window.setTimeout(() => {
console.log('infscroll request timed out, aborting');
infscroll_in_progress = 0;
if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) { // call scroll handler to maybe repeat infscroll request
//console.log("infscroll request in progress, aborting"); headlinesScrollHandler();
return; }, 10 * 1000);
}
_infscroll_request_sent = timestamp;
}
} }
Form.enable("main_toolbar_form"); Form.enable("main_toolbar_form");
@ -106,7 +95,6 @@ function viewfeed(params) {
} }
} }
if (!background) {
if (_search_query) { if (_search_query) {
query = Object.assign(query, _search_query); query = Object.assign(query, _search_query);
} }
@ -124,18 +112,13 @@ function viewfeed(params) {
Form.enable("main_toolbar_form"); Form.enable("main_toolbar_form");
if (!delayed)
if (!setFeedExpandoIcon(feed, is_cat, if (!setFeedExpandoIcon(feed, is_cat,
(is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif'))
notify_progress("Loading, please wait...", true); notify_progress("Loading, please wait...", true);
}
query.cat = is_cat; query.cat = is_cat;
if (can_wait && _viewfeed_timeout) {
setFeedExpandoIcon(getActiveFeedId(), activeFeedIsCat(), 'images/blank_icon.gif');
clearTimeout(_viewfeed_timeout);
}
setActiveFeedId(feed, is_cat); setActiveFeedId(feed, is_cat);
if (viewfeed_debug) { if (viewfeed_debug) {
@ -145,17 +128,20 @@ function viewfeed(params) {
)); ));
} }
window.clearTimeout(_viewfeed_wait_timeout);
_viewfeed_wait_timeout = window.setTimeout(() => {
catchupBatchedArticles(() => { catchupBatchedArticles(() => {
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
try { try {
setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
headlines_callback2(transport, offset, background, infscroll_req); headlines_callback2(transport, offset);
PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
} catch (e) { } catch (e) {
exception_error(e); exception_error(e);
} }
}); });
}); });
}, delayed ? 250 : 0);
} }
function feedlist_init() { function feedlist_init() {
@ -164,8 +150,8 @@ function feedlist_init() {
setLoadingProgress(50); setLoadingProgress(50);
document.onkeydown = hotkey_handler; document.onkeydown = hotkey_handler;
setInterval(hotkeyPrefixTimeout, 5*1000); setInterval(hotkeyPrefixTimeout, 3*1000);
setInterval(catchupBatchedArticles, 3*1000); setInterval(catchupBatchedArticles, 10*1000);
if (!getActiveFeedId()) { if (!getActiveFeedId()) {
viewfeed({feed: -3}); viewfeed({feed: -3});
@ -357,7 +343,7 @@ function getFeedName(feed, is_cat) {
return tree.model.getFeedValue(feed, is_cat, 'name'); return tree.model.getFeedValue(feed, is_cat, 'name');
} }
function getFeedValue(feed, is_cat, key) { /* function getFeedValue(feed, is_cat, key) {
try { try {
const tree = dijit.byId("feedTree"); const tree = dijit.byId("feedTree");
@ -368,7 +354,7 @@ function getFeedValue(feed, is_cat, key) {
// //
} }
return ''; return '';
} } */
function setFeedUnread(feed, is_cat, unread) { function setFeedUnread(feed, is_cat, unread) {
const tree = dijit.byId("feedTree"); const tree = dijit.byId("feedTree");

@ -274,13 +274,13 @@ function init_hotkey_actions() {
const rv = dijit.byId("feedTree").getNextFeed( const rv = dijit.byId("feedTree").getNextFeed(
getActiveFeedId(), activeFeedIsCat()); getActiveFeedId(), activeFeedIsCat());
if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) if (rv) viewfeed({feed: rv[0], is_cat: rv[1], delayed: true})
}; };
hotkey_actions["prev_feed"] = function() { hotkey_actions["prev_feed"] = function() {
const rv = dijit.byId("feedTree").getPreviousFeed( const rv = dijit.byId("feedTree").getPreviousFeed(
getActiveFeedId(), activeFeedIsCat()); getActiveFeedId(), activeFeedIsCat());
if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) if (rv) viewfeed({feed: rv[0], is_cat: rv[1], delayed: true})
}; };
hotkey_actions["next_article"] = function() { hotkey_actions["next_article"] = function() {
moveToPost('next'); moveToPost('next');

@ -5,28 +5,20 @@ let _active_article_id = 0;
let vgroup_last_feed = false; let vgroup_last_feed = false;
let post_under_pointer = false; let post_under_pointer = false;
let last_requested_article = 0;
let catchup_id_batch = []; let catchup_id_batch = [];
//let catchup_timeout_id = false; //let catchup_timeout_id = false;
//let cids_requested = []; //let cids_requested = [];
let loaded_article_ids = []; let loaded_article_ids = [];
let _last_headlines_update = 0;
let current_first_id = 0; let current_first_id = 0;
let last_search_query; let last_search_query;
let _catchup_request_sent = false;
let has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null; let has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
function headlines_callback2(transport, offset, background, infscroll_req) { function headlines_callback2(transport, offset) {
const reply = handle_rpc_json(transport); const reply = handle_rpc_json(transport);
console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req); console.log("headlines_callback2, offset=", offset);
if (background)
return;
let is_cat = false; let is_cat = false;
let feed_id = false; let feed_id = false;
@ -41,7 +33,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
return; return;
try { try {
if (infscroll_req == false) { if (offset == 0) {
$("headlines-frame").scrollTop = 0; $("headlines-frame").scrollTop = 0;
Element.hide("floatingTitle"); Element.hide("floatingTitle");
@ -56,18 +48,14 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
$("headlines-frame").addClassName(isCombinedMode() ? "cdm" : "normal"); $("headlines-frame").addClassName(isCombinedMode() ? "cdm" : "normal");
const headlines_count = reply['headlines-info']['count']; const headlines_count = reply['headlines-info']['count'];
infscroll_disabled = parseInt(headlines_count) != 30;
vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; console.log('received', headlines_count, 'headlines, infscroll disabled=', infscroll_disabled);
if (parseInt(headlines_count) < 30) {
_infscroll_disable = 1;
} else {
_infscroll_disable = 0;
}
vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
current_first_id = reply['headlines']['first_id']; current_first_id = reply['headlines']['first_id'];
if (infscroll_req == false) { if (offset == 0) {
loaded_article_ids = []; loaded_article_ids = [];
dojo.html.set($("headlines-toolbar"), dojo.html.set($("headlines-toolbar"),
@ -96,7 +84,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
initHeadlinesMenu(); initHeadlinesMenu();
if (_infscroll_disable) if (infscroll_disabled)
hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" + hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
__("Click to open next unread feed.") + "</a>"; __("Click to open next unread feed.") + "</a>";
@ -107,8 +95,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
} }
} else if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) { } else if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
console.log("adding some more headlines: " + headlines_count);
const c = dijit.byId("headlines-frame"); const c = dijit.byId("headlines-frame");
//const ids = getSelectedArticleIds2(); //const ids = getSelectedArticleIds2();
@ -134,7 +120,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
c.domNode.appendChild(hsp); c.domNode.appendChild(hsp);
if (headlines_count < 30) _infscroll_disable = true; if (headlines_count < 30) infscroll_disabled = true;
/* console.log("restore selected ids: " + ids); /* console.log("restore selected ids: " + ids);
@ -144,7 +130,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
initHeadlinesMenu(); initHeadlinesMenu();
if (_infscroll_disable) { if (infscroll_disabled) {
hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" + hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
__("Click to open next unread feed.") + "</a>"; __("Click to open next unread feed.") + "</a>";
} }
@ -175,20 +161,19 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
"</div>"); "</div>");
} }
_infscroll_request_sent = 0; infscroll_in_progress = 0;
_last_headlines_update = new Date().getTime();
// this is used to auto-catchup articles if needed after infscroll request has finished, // this is used to auto-catchup articles if needed after infscroll request has finished,
// unpack visible articles, etc // unpack visible articles, etc
headlinesScrollHandler(); headlinesScrollHandler();
// if we have some more space in the buffer, why not try to fill it // if we have some more space in the buffer, why not try to fill it
if (!_infscroll_disable && $("headlines-spacer") && if (!infscroll_disabled && $("headlines-spacer") &&
$("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) { $("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) {
window.setTimeout(function() { window.setTimeout(function() {
loadMoreHeadlines(); loadMoreHeadlines();
}, 250); }, 500);
} }
notify(""); notify("");
@ -933,7 +918,7 @@ function headlinesScrollHandler(/* event */) {
} }
} }
if (!_infscroll_disable) { if (!infscroll_disabled) {
const hsp = $("headlines-spacer"); const hsp = $("headlines-spacer");
const container = $("headlines-frame"); const container = $("headlines-frame");
@ -944,11 +929,10 @@ function headlinesScrollHandler(/* event */) {
loadMoreHeadlines(); loadMoreHeadlines();
return; return;
} }
} }
if (getInitParam("cdm_auto_catchup") == 1 && !_infscroll_request_sent) { if (getInitParam("cdm_auto_catchup") == 1) {
let rows = $$("#headlines-frame > div[id*=RROW][class*=Unread]"); let rows = $$("#headlines-frame > div[id*=RROW][class*=Unread]");
@ -966,7 +950,7 @@ function headlinesScrollHandler(/* event */) {
} }
} }
if (_infscroll_disable) { if (infscroll_disabled) {
const row = $$("#headlines-frame div[id*=RROW]").last(); const row = $$("#headlines-frame div[id*=RROW]").last();
if (row && $("headlines-frame").scrollTop > if (row && $("headlines-frame").scrollTop >
@ -994,20 +978,16 @@ function openNextUnreadFeed() {
function catchupBatchedArticles(callback) { function catchupBatchedArticles(callback) {
console.log("catchupBatchedArticles, size=", catchup_id_batch.length); console.log("catchupBatchedArticles, size=", catchup_id_batch.length);
if (catchup_id_batch.length > 0 /* && !_infscroll_request_sent */ && !_catchup_request_sent) { if (catchup_id_batch.length > 0) {
// make a copy of the array // make a copy of the array
const batch = catchup_id_batch.slice(); const batch = catchup_id_batch.slice();
const query = { op: "rpc", method: "catchupSelected", const query = { op: "rpc", method: "catchupSelected",
cmode: 0, ids: batch.toString() }; cmode: 0, ids: batch.toString() };
_catchup_request_sent = true;
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
const reply = handle_rpc_json(transport); const reply = handle_rpc_json(transport);
_catchup_request_sent = false;
if (reply) { if (reply) {
const batch = reply.ids; const batch = reply.ids;

Loading…
Cancel
Save