From 468faee6351fa186c41775bb3d2f1675a3b3ba7c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 12:36:28 +0300 Subject: viewfeed: remove (tons of) obsolete code --- js/feedlist.js | 116 +++++++++++++++++++++++++-------------------------------- js/tt-rss.js | 4 +- js/viewfeed.js | 54 +++++++++------------------ 3 files changed, 70 insertions(+), 104 deletions(-) diff --git a/js/feedlist.js b/js/feedlist.js index 2d4e9f9b1..4d5dbe2ac 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -1,9 +1,9 @@ -let _infscroll_disable = 0; -let _infscroll_request_sent = 0; +let infscroll_in_progress = 0; +let infscroll_disabled = 0; +let _infscroll_timeout = false; let _search_query = false; -let _viewfeed_last = 0; -let _viewfeed_timeout = false; +let _viewfeed_wait_timeout = false; let counters_last_request = 0; let _counters_prev = []; @@ -55,42 +55,31 @@ function cleanup_memory(root) { function viewfeed(params) { const feed = params.feed; - let is_cat = !!params.is_cat || false; - let offset = params.offset || 0; - let background = params.background || false; - let infscroll_req = params.infscroll_req || false; - const can_wait = params.can_wait; + const is_cat = !!params.is_cat || false; + const offset = params.offset || 0; const viewfeed_debug = params.viewfeed_debug; const method = params.method; - - if (infscroll_req == undefined) infscroll_req = false; - - last_requested_article = 0; + // this is used to quickly switch between feeds, sets active but xhr is on a timeout + const delayed = params.delayed || false; if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) { - if (!background && _search_query) _search_query = false; + _search_query = false; } - if (!background) { - _viewfeed_last = get_timestamp(); - - if (getActiveFeedId() != feed || !infscroll_req) { - setActiveArticleId(0); - _infscroll_disable = 0; + if (offset != 0) { + if (infscroll_in_progress) + return; - cleanup_memory("headlines-frame"); - } - - if (infscroll_req) { - const timestamp = get_timestamp(); + infscroll_in_progress = 1; - if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) { - //console.log("infscroll request in progress, aborting"); - return; - } + window.clearTimeout(_infscroll_timeout); + _infscroll_timeout = window.setTimeout(() => { + console.log('infscroll request timed out, aborting'); + infscroll_in_progress = 0; - _infscroll_request_sent = timestamp; - } + // call scroll handler to maybe repeat infscroll request + headlinesScrollHandler(); + }, 10 * 1000); } Form.enable("main_toolbar_form"); @@ -106,36 +95,30 @@ function viewfeed(params) { } } - if (!background) { - if (_search_query) { - query = Object.assign(query, _search_query); - } + if (_search_query) { + query = Object.assign(query, _search_query); + } - if (offset != 0) { - query.skip = offset; + if (offset != 0) { + query.skip = offset; - // to prevent duplicate feed titles when showing grouped vfeeds - if (vgroup_last_feed) { - query.vgrlf = vgroup_last_feed; - } - } else if (!is_cat && feed == getActiveFeedId() && !params.method) { - query.m = "ForceUpdate"; - } + // to prevent duplicate feed titles when showing grouped vfeeds + if (vgroup_last_feed) { + query.vgrlf = vgroup_last_feed; + } + } else if (!is_cat && feed == getActiveFeedId() && !params.method) { + query.m = "ForceUpdate"; + } - Form.enable("main_toolbar_form"); + Form.enable("main_toolbar_form"); + if (!delayed) if (!setFeedExpandoIcon(feed, is_cat, (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) notify_progress("Loading, please wait...", true); - } query.cat = is_cat; - if (can_wait && _viewfeed_timeout) { - setFeedExpandoIcon(getActiveFeedId(), activeFeedIsCat(), 'images/blank_icon.gif'); - clearTimeout(_viewfeed_timeout); - } - setActiveFeedId(feed, is_cat); if (viewfeed_debug) { @@ -145,17 +128,20 @@ function viewfeed(params) { )); } - catchupBatchedArticles(() => { - xhrPost("backend.php", query, (transport) => { - try { - setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); - headlines_callback2(transport, offset, background, infscroll_req); - PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); - } catch (e) { - exception_error(e); - } + window.clearTimeout(_viewfeed_wait_timeout); + _viewfeed_wait_timeout = window.setTimeout(() => { + catchupBatchedArticles(() => { + xhrPost("backend.php", query, (transport) => { + try { + setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); + headlines_callback2(transport, offset); + PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); + } catch (e) { + exception_error(e); + } + }); }); - }); + }, delayed ? 250 : 0); } function feedlist_init() { @@ -164,8 +150,8 @@ function feedlist_init() { setLoadingProgress(50); document.onkeydown = hotkey_handler; - setInterval(hotkeyPrefixTimeout, 5*1000); - setInterval(catchupBatchedArticles, 3*1000); + setInterval(hotkeyPrefixTimeout, 3*1000); + setInterval(catchupBatchedArticles, 10*1000); if (!getActiveFeedId()) { viewfeed({feed: -3}); @@ -357,7 +343,7 @@ function getFeedName(feed, is_cat) { return tree.model.getFeedValue(feed, is_cat, 'name'); } -function getFeedValue(feed, is_cat, key) { +/* function getFeedValue(feed, is_cat, key) { try { const tree = dijit.byId("feedTree"); @@ -368,7 +354,7 @@ function getFeedValue(feed, is_cat, key) { // } return ''; -} +} */ function setFeedUnread(feed, is_cat, unread) { const tree = dijit.byId("feedTree"); diff --git a/js/tt-rss.js b/js/tt-rss.js index 432fa13f1..99a484e9a 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -274,13 +274,13 @@ function init_hotkey_actions() { const rv = dijit.byId("feedTree").getNextFeed( 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() { const rv = dijit.byId("feedTree").getPreviousFeed( 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() { moveToPost('next'); diff --git a/js/viewfeed.js b/js/viewfeed.js index f40caca50..bc6ed32da 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -5,28 +5,20 @@ let _active_article_id = 0; let vgroup_last_feed = false; let post_under_pointer = false; -let last_requested_article = 0; - let catchup_id_batch = []; //let catchup_timeout_id = false; //let cids_requested = []; let loaded_article_ids = []; -let _last_headlines_update = 0; let current_first_id = 0; let last_search_query; -let _catchup_request_sent = false; - 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); - console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req); - - if (background) - return; + console.log("headlines_callback2, offset=", offset); let is_cat = false; let feed_id = false; @@ -41,7 +33,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { return; try { - if (infscroll_req == false) { + if (offset == 0) { $("headlines-frame").scrollTop = 0; Element.hide("floatingTitle"); @@ -56,18 +48,14 @@ function headlines_callback2(transport, offset, background, infscroll_req) { $("headlines-frame").addClassName(isCombinedMode() ? "cdm" : "normal"); const headlines_count = reply['headlines-info']['count']; + infscroll_disabled = parseInt(headlines_count) != 30; - vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; - - if (parseInt(headlines_count) < 30) { - _infscroll_disable = 1; - } else { - _infscroll_disable = 0; - } + console.log('received', headlines_count, 'headlines, infscroll disabled=', infscroll_disabled); + vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; current_first_id = reply['headlines']['first_id']; - if (infscroll_req == false) { + if (offset == 0) { loaded_article_ids = []; dojo.html.set($("headlines-toolbar"), @@ -96,7 +84,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { initHeadlinesMenu(); - if (_infscroll_disable) + if (infscroll_disabled) hsp.innerHTML = "" + __("Click to open next unread feed.") + ""; @@ -107,8 +95,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) { } } 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 ids = getSelectedArticleIds2(); @@ -134,7 +120,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); c.domNode.appendChild(hsp); - if (headlines_count < 30) _infscroll_disable = true; + if (headlines_count < 30) infscroll_disabled = true; /* console.log("restore selected ids: " + ids); @@ -144,7 +130,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { initHeadlinesMenu(); - if (_infscroll_disable) { + if (infscroll_disabled) { hsp.innerHTML = "" + __("Click to open next unread feed.") + ""; } @@ -175,20 +161,19 @@ function headlines_callback2(transport, offset, background, infscroll_req) { ""); } - _infscroll_request_sent = 0; - _last_headlines_update = new Date().getTime(); + infscroll_in_progress = 0; // this is used to auto-catchup articles if needed after infscroll request has finished, // unpack visible articles, etc headlinesScrollHandler(); // 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) { window.setTimeout(function() { loadMoreHeadlines(); - }, 250); + }, 500); } notify(""); @@ -933,7 +918,7 @@ function headlinesScrollHandler(/* event */) { } } - if (!_infscroll_disable) { + if (!infscroll_disabled) { const hsp = $("headlines-spacer"); const container = $("headlines-frame"); @@ -944,11 +929,10 @@ function headlinesScrollHandler(/* event */) { loadMoreHeadlines(); 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]"); @@ -966,7 +950,7 @@ function headlinesScrollHandler(/* event */) { } } - if (_infscroll_disable) { + if (infscroll_disabled) { const row = $$("#headlines-frame div[id*=RROW]").last(); if (row && $("headlines-frame").scrollTop > @@ -994,20 +978,16 @@ function openNextUnreadFeed() { function catchupBatchedArticles(callback) { 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 const batch = catchup_id_batch.slice(); const query = { op: "rpc", method: "catchupSelected", cmode: 0, ids: batch.toString() }; - _catchup_request_sent = true; - xhrPost("backend.php", query, (transport) => { const reply = handle_rpc_json(transport); - _catchup_request_sent = false; - if (reply) { const batch = reply.ids; -- cgit v1.2.3