From 049a37aa0e7d37cafd979e7d470c7649700b5010 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:05:28 +0300 Subject: WIP reshuffling of JS global context into separate logical objects --- js/feedlist.js | 639 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 366 insertions(+), 273 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index 4d5dbe2ac..b808451b4 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -1,302 +1,430 @@ -let infscroll_in_progress = 0; -let infscroll_disabled = 0; +let counters_last_request = 0; -let _infscroll_timeout = false; -let _search_query = false; -let _viewfeed_wait_timeout = false; +const Counters = { +}; + +const Feeds = { + _active_feed_id: 0, + _active_feed_is_cat: false, + infscroll_in_progress: 0, + infscroll_disabled: 0, + _infscroll_timeout: false, + _search_query: false, + _viewfeed_wait_timeout: false, + _counters_prev: [], + // NOTE: this implementation is incomplete + // for general objects but good enough for counters + // http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html + counterEquals: function(a, b) { + // Create arrays of property names + const aProps = Object.getOwnPropertyNames(a); + const bProps = Object.getOwnPropertyNames(b); + + // If number of properties is different, + // objects are not equivalent + if (aProps.length != bProps.length) { + return false; + } -let counters_last_request = 0; -let _counters_prev = []; + for (let i = 0; i < aProps.length; i++) { + const propName = aProps[i]; -function resetCounterCache() { - _counters_prev = []; -} + // If values of same property are not equal, + // objects are not equivalent + if (a[propName] !== b[propName]) { + return false; + } + } -function loadMoreHeadlines() { - const view_mode = document.forms["main_toolbar_form"].view_mode.value; - const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; - const num_all = $$("#headlines-frame > div[id*=RROW]").length; - const num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat()); - - // TODO implement marked & published - - let offset = num_all; - - switch (view_mode) { - case "marked": - case "published": - console.warn("loadMoreHeadlines: ", view_mode, "not implemented"); - break; - case "unread": - offset = unread_in_buffer; - break; - case "adaptive": - if (!(getActiveFeedId() == -1 && !activeFeedIsCat())) - offset = num_unread > 0 ? unread_in_buffer : num_all; - break; - } + // If we made it this far, objects + // are considered equivalent + return true; + }, + resetCounters: function () { + this._counters_prev = []; + }, + parseCounters: function (elems) { + for (let l = 0; l < elems.length; l++) { + + if (this._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) { + continue; + } - console.log("loadMoreHeadlines, offset=", offset); + const id = elems[l].id; + const kind = elems[l].kind; + const ctr = parseInt(elems[l].counter); + const error = elems[l].error; + const has_img = elems[l].has_img; + const updated = elems[l].updated; + const auxctr = parseInt(elems[l].auxcounter); + + if (id == "global-unread") { + App.global_unread = ctr; + App.updateTitle(); + continue; + } - viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), offset: offset, infscroll_req: true}); -} + if (id == "subscribed-feeds") { + /* feeds_found = ctr; */ + continue; + } -function cleanup_memory(root) { - const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); + /*if (getFeedUnread(id, (kind == "cat")) != ctr || + (kind == "cat")) { + }*/ - dijits.each(function (d) { - dojo.destroy(d.domNode); - }); + setFeedUnread(id, (kind == "cat"), ctr); + setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); - $$("#" + root + " *").each(function (i) { - i.parentNode ? i.parentNode.removeChild(i) : true; - }); -} + if (kind != "cat") { + setFeedValue(id, false, 'error', error); + setFeedValue(id, false, 'updated', updated); -function viewfeed(params) { - const feed = params.feed; - const is_cat = !!params.is_cat || false; - const offset = params.offset || 0; - const viewfeed_debug = params.viewfeed_debug; - const method = params.method; - // 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) { - _search_query = false; - } + if (id > 0) { + if (has_img) { + setFeedIcon(id, false, + getInitParam("icons_url") + "/" + id + ".ico?" + has_img); + } else { + setFeedIcon(id, false, 'images/blank_icon.gif'); + } + } + } + } - if (offset != 0) { - if (infscroll_in_progress) - return; + this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); + this._counters_prev = elems; + }, + viewCurrentFeed: function(method) { + console.log("viewCurrentFeed: " + method); - infscroll_in_progress = 1; + if (this.getActiveFeedId() != undefined) { + this.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), method: method}); + } + return false; // block unneeded form submits + }, + openNextUnreadFeed: function() { + const is_cat = Feeds.activeFeedIsCat(); + const nuf = getNextUnreadFeed(Feeds.getActiveFeedId(), is_cat); + if (nuf) this.viewfeed({feed: nuf, is_cat: is_cat}); + }, + collapseFeedlist: function() { + Element.toggle("feeds-holder"); - window.clearTimeout(_infscroll_timeout); - _infscroll_timeout = window.setTimeout(() => { - console.log('infscroll request timed out, aborting'); - infscroll_in_progress = 0; + const splitter = $("feeds-holder_splitter"); - // call scroll handler to maybe repeat infscroll request - headlinesScrollHandler(); - }, 10 * 1000); - } + Element.visible("feeds-holder") ? splitter.show() : splitter.hide(); - Form.enable("main_toolbar_form"); + dijit.byId("main").resize(); + }, + cancelSearch: function() { + this._search_query = ""; + Feeds.viewCurrentFeed(); + }, + requestCounters: function(force) { + const date = new Date(); + const timestamp = Math.round(date.getTime() / 1000); - let query = Object.assign({op: "feeds", method: "view", feed: feed}, - dojo.formToObject("main_toolbar_form")); + if (force || timestamp - counters_last_request > 5) { + console.log("scheduling request of counters..."); - if (method) query.m = method; + counters_last_request = timestamp; - if (offset > 0) { - if (current_first_id) { - query.fid = current_first_id; - } - } + let query = {op: "rpc", method: "getAllCounters", seq: App.next_seq()}; - if (_search_query) { - query = Object.assign(query, _search_query); - } + if (!force) + query.last_article_id = getInitParam("last_article_id"); - if (offset != 0) { - query.skip = offset; + xhrPost("backend.php", query, (transport) => { + App.handleRpcJson(transport); + }); - // 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"; + } else { + console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); } + }, + reload: function() { + try { + Element.show("feedlistLoading"); - Form.enable("main_toolbar_form"); + this.resetCounters(); - if (!delayed) - if (!setFeedExpandoIcon(feed, is_cat, - (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) - notify_progress("Loading, please wait...", true); + if (dijit.byId("feedTree")) { + dijit.byId("feedTree").destroyRecursive(); + } - query.cat = is_cat; + const store = new dojo.data.ItemFileWriteStore({ + url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2" + }); - setActiveFeedId(feed, is_cat); + const treeModel = new fox.FeedStoreModel({ + store: store, + query: { + "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed" + }, + rootId: "root", + rootLabel: "Feeds", + childrenAttrs: ["items"] + }); - if (viewfeed_debug) { - window.open("backend.php?" + - dojo.objectToQuery( - Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query) - )); - } + const tree = new fox.FeedTree({ + model: treeModel, + onClick: function (item, node) { + const id = String(item.id); + const is_cat = id.match("^CAT:"); + const feed = id.substr(id.indexOf(":") + 1); + Feeds.viewfeed({feed: feed, is_cat: is_cat}); + return false; + }, + openOnClick: false, + showRoot: false, + persist: true, + id: "feedTree", + }, "feedTree"); + + const tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) { + console.log(dijit.getEnclosingWidget(event.target)); + dojo.disconnect(tmph); + }); + + $("feeds-holder").appendChild(tree.domNode); + + const tmph2 = dojo.connect(tree, 'onLoad', function () { + dojo.disconnect(tmph2); + Element.hide("feedlistLoading"); - 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]); + Feeds.init(); + setLoadingProgress(25); } catch (e) { exception_error(e); } }); - }); - }, delayed ? 250 : 0); -} -function feedlist_init() { - console.log("in feedlist init"); + tree.startup(); + } catch (e) { + exception_error(e); + } + }, + init: function() { + console.log("in feedlist init"); - setLoadingProgress(50); + setLoadingProgress(50); - document.onkeydown = hotkey_handler; - setInterval(hotkeyPrefixTimeout, 3*1000); - setInterval(catchupBatchedArticles, 10*1000); + document.onkeydown = App.hotkeyHandler; + setInterval(hotkeyPrefixTimeout, 3 * 1000); + setInterval(catchupBatchedArticles, 10 * 1000); - if (!getActiveFeedId()) { - viewfeed({feed: -3}); - } else { - viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()}); - } + if (!this.getActiveFeedId()) { + this.viewfeed({feed: -3}); + } else { + this.viewfeed({feed: this.getActiveFeedId(), is_cat: this.activeFeedIsCat()}); + } - hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); - - if (getInitParam("is_default_pw")) { - console.warn("user password is at default value"); - - const dialog = new dijit.Dialog({ - title: __("Your password is at default value"), - href: "backend.php?op=dlg&method=defaultpasswordwarning", - id: 'infoBox', - style: "width: 600px", - onCancel: function() { - return true; - }, - onExecute: function() { - return true; - }, - onClose: function() { - return true; - } - }); + this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); + + if (getInitParam("is_default_pw")) { + console.warn("user password is at default value"); + + const dialog = new dijit.Dialog({ + title: __("Your password is at default value"), + href: "backend.php?op=dlg&method=defaultpasswordwarning", + id: 'infoBox', + style: "width: 600px", + onCancel: function () { + return true; + }, + onExecute: function () { + return true; + }, + onClose: function () { + return true; + } + }); - dialog.show(); - } + dialog.show(); + } - // bw_limit disables timeout() so we request initial counters separately - if (getInitParam("bw_limit") == "1") { - request_counters(true); - } else { - setTimeout(timeout, 250); - } -} + // bw_limit disables timeout() so we request initial counters separately + if (getInitParam("bw_limit") == "1") { + this.requestCounters(true); + } else { + setTimeout(() => { + this.requestCounters(true); + + setInterval(() => { + this.requestCounters(); + }, 60 * 1000) + }, 250); + } + }, + activeFeedIsCat: function() { + return !!this._active_feed_is_cat; + }, + getActiveFeedId: function() { + return this._active_feed_id; + }, + setActiveFeedId: function(id, is_cat) { + hash_set('f', id); + hash_set('c', is_cat ? 1 : 0); + + this._active_feed_id = id; + this._active_feed_is_cat = is_cat; + + $("headlines-frame").setAttribute("feed-id", id); + $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0); + + this.selectFeed(id, is_cat); + + PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id); + }, + selectFeed: function(feed, is_cat) { + const tree = dijit.byId("feedTree"); + if (tree) return tree.selectFeed(feed, is_cat); + }, + toggleDispRead: function() { + const hide = !(getInitParam("hide_read_feeds") == "1"); -function request_counters(force) { - const date = new Date(); - const timestamp = Math.round(date.getTime() / 1000); + xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => { + this.hideOrShowFeeds(hide); + setInitParam("hide_read_feeds", hide); + }); + }, + hideOrShowFeeds: function(hide) { + const tree = dijit.byId("feedTree"); - if (force || timestamp - counters_last_request > 5) { - console.log("scheduling request of counters..."); + if (tree) + return tree.hideRead(hide, getInitParam("hide_read_shows_special")); + }, + viewfeed: function(params) { + const feed = params.feed; + const is_cat = !!params.is_cat || false; + const offset = params.offset || 0; + const viewfeed_debug = params.viewfeed_debug; + const method = params.method; + // this is used to quickly switch between feeds, sets active but xhr is on a timeout + const delayed = params.delayed || false; + + if (feed != Feeds.getActiveFeedId() || Feeds.activeFeedIsCat() != is_cat) { + this._search_query = false; + setActiveArticleId(0); + } - counters_last_request = timestamp; + if (offset != 0) { + if (this.infscroll_in_progress) + return; - let query = {op: "rpc", method: "getAllCounters", seq: next_seq()}; + this.infscroll_in_progress = 1; - if (!force) - query.last_article_id = getInitParam("last_article_id"); + window.clearTimeout(this._infscroll_timeout); + this._infscroll_timeout = window.setTimeout(() => { + console.log('infscroll request timed out, aborting'); + this.infscroll_in_progress = 0; - xhrPost("backend.php", query, (transport) => { - handle_rpc_json(transport); - }); + // call scroll handler to maybe repeat infscroll request + Headlines.scrollHandler(); + }, 10 * 1000); + } - } else { - console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); - } -} + Form.enable("main_toolbar_form"); -// NOTE: this implementation is incomplete -// for general objects but good enough for counters -// http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html -function counter_is_equal(a, b) { - // Create arrays of property names - const aProps = Object.getOwnPropertyNames(a); - const bProps = Object.getOwnPropertyNames(b); - - // If number of properties is different, - // objects are not equivalent - if (aProps.length != bProps.length) { - return false; - } + let query = Object.assign({op: "feeds", method: "view", feed: feed}, + dojo.formToObject("main_toolbar_form")); - for (let i = 0; i < aProps.length; i++) { - const propName = aProps[i]; + if (method) query.m = method; - // If values of same property are not equal, - // objects are not equivalent - if (a[propName] !== b[propName]) { - return false; + if (offset > 0) { + if (current_first_id) { + query.fid = current_first_id; + } } - } - - // If we made it this far, objects - // are considered equivalent - return true; -} + if (this._search_query) { + query = Object.assign(query, this._search_query); + } -function parse_counters(elems) { - for (let l = 0; l < elems.length; l++) { + if (offset != 0) { + query.skip = offset; - if (_counters_prev[l] && counter_is_equal(elems[l], _counters_prev[l])) { - continue; + // to prevent duplicate feed titles when showing grouped vfeeds + if (vgroup_last_feed) { + query.vgrlf = vgroup_last_feed; + } + } else if (!is_cat && feed == Feeds.getActiveFeedId() && !params.method) { + query.m = "ForceUpdate"; } - const id = elems[l].id; - const kind = elems[l].kind; - const ctr = parseInt(elems[l].counter); - const error = elems[l].error; - const has_img = elems[l].has_img; - const updated = elems[l].updated; - const auxctr = parseInt(elems[l].auxcounter); - - if (id == "global-unread") { - global_unread = ctr; - updateTitle(); - continue; + 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; + + Feeds.setActiveFeedId(feed, is_cat); + + if (viewfeed_debug) { + window.open("backend.php?" + + dojo.objectToQuery( + Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query) + )); } - if (id == "subscribed-feeds") { - /* feeds_found = ctr; */ - continue; + window.clearTimeout(this._viewfeed_wait_timeout); + this._viewfeed_wait_timeout = window.setTimeout(() => { + catchupBatchedArticles(() => { + xhrPost("backend.php", query, (transport) => { + try { + setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); + Headlines.onLoaded(transport, offset); + PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); + } catch (e) { + exception_error(e); + } + }); + }); + }, delayed ? 250 : 0); + }, + catchupAllFeeds: function() { + const str = __("Mark all articles as read?"); + + if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { + + notify_progress("Marking all feeds as read..."); + + xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => { + this.requestCounters(true); + this.viewCurrentFeed(); + }); + + App.global_unread = 0; + App.updateTitle(); } + }, + decrementFeedCounter: function(feed, is_cat) { + let ctr = getFeedUnread(feed, is_cat); - /*if (getFeedUnread(id, (kind == "cat")) != ctr || - (kind == "cat")) { - }*/ + if (ctr > 0) { + setFeedUnread(feed, is_cat, ctr - 1); + App.global_unread -= 1; + App.updateTitle(); - setFeedUnread(id, (kind == "cat"), ctr); - setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); + if (!is_cat) { + const cat = parseInt(getFeedCategory(feed)); - if (kind != "cat") { - setFeedValue(id, false, 'error', error); - setFeedValue(id, false, 'updated', updated); + if (!isNaN(cat)) { + ctr = getFeedUnread(cat, true); - if (id > 0) { - if (has_img) { - setFeedIcon(id, false, - getInitParam("icons_url") + "/" + id + ".ico?" + has_img); - } else { - setFeedIcon(id, false, 'images/blank_icon.gif'); + if (ctr > 0) { + setFeedUnread(cat, true, ctr - 1); + } } } } } - - hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); - - _counters_prev = elems; -} +}; function getFeedUnread(feed, is_cat) { try { @@ -326,13 +454,6 @@ function getFeedCategory(feed) { return false; } -function hideOrShowFeeds(hide) { - const tree = dijit.byId("feedTree"); - - if (tree) - return tree.hideRead(hide, getInitParam("hide_read_shows_special")); -} - function getFeedName(feed, is_cat) { if (isNaN(feed)) return feed; // it's a tag @@ -375,12 +496,6 @@ function setFeedValue(feed, is_cat, key, value) { } } -function selectFeed(feed, is_cat) { - const tree = dijit.byId("feedTree"); - - if (tree) return tree.selectFeed(feed, is_cat); -} - function setFeedIcon(feed, is_cat, src) { const tree = dijit.byId("feedTree"); @@ -404,7 +519,7 @@ function getNextUnreadFeed(feed, is_cat) { } function catchupCurrentFeed(mode) { - catchupFeed(getActiveFeedId(), activeFeedIsCat(), mode); + catchupFeed(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat(), mode); } function catchupFeedInGroup(id) { @@ -440,13 +555,13 @@ function catchupFeedInGroup(id) { } } - updateFloatingTitle(true); + Headlines.updateFloatingTitle(true); } notify_progress("Loading, please wait...", true); xhrPost("backend.php", { op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => { - handle_rpc_json(transport); + App.handleRpcJson(transport); }); } } @@ -487,7 +602,7 @@ function catchupFeed(feed, is_cat, mode) { notify_progress("Loading, please wait...", true); xhrPost("backend.php", catchup_query, (transport) => { - handle_rpc_json(transport); + App.handleRpcJson(transport); const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; @@ -495,37 +610,15 @@ function catchupFeed(feed, is_cat, mode) { const nuf = getNextUnreadFeed(feed, is_cat); if (nuf) { - viewfeed({feed: nuf, is_cat: is_cat}); + Feeds.viewfeed({feed: nuf, is_cat: is_cat}); } - } else if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { - viewCurrentFeed(); + } else if (feed == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { + Feeds.viewCurrentFeed(); } notify(""); }); } -function decrementFeedCounter(feed, is_cat) { - let ctr = getFeedUnread(feed, is_cat); - - if (ctr > 0) { - setFeedUnread(feed, is_cat, ctr - 1); - global_unread = global_unread - 1; - updateTitle(); - - if (!is_cat) { - const cat = parseInt(getFeedCategory(feed)); - - if (!isNaN(cat)) { - ctr = getFeedUnread(cat, true); - - if (ctr > 0) { - setFeedUnread(cat, true, ctr - 1); - } - } - } - } - -} -- cgit v1.2.3 From d86ddbc635376231ba2e0a70c04f526cb9fedd58 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:21:26 +0300 Subject: further objectification of JS code --- js/feedlist.js | 330 +++++++++++++++++++++++++++------------------------------ 1 file changed, 158 insertions(+), 172 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index b808451b4..c2a0e816d 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -69,23 +69,23 @@ const Feeds = { continue; } - /*if (getFeedUnread(id, (kind == "cat")) != ctr || + /*if (Feeds.getFeedUnread(id, (kind == "cat")) != ctr || (kind == "cat")) { }*/ - setFeedUnread(id, (kind == "cat"), ctr); - setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); + Feeds.setFeedUnread(id, (kind == "cat"), ctr); + Feeds.setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); if (kind != "cat") { - setFeedValue(id, false, 'error', error); - setFeedValue(id, false, 'updated', updated); + Feeds.setFeedValue(id, false, 'error', error); + Feeds.setFeedValue(id, false, 'updated', updated); if (id > 0) { if (has_img) { - setFeedIcon(id, false, + Feeds.setFeedIcon(id, false, getInitParam("icons_url") + "/" + id + ".ico?" + has_img); } else { - setFeedIcon(id, false, 'images/blank_icon.gif'); + Feeds.setFeedIcon(id, false, 'images/blank_icon.gif'); } } } @@ -104,7 +104,7 @@ const Feeds = { }, openNextUnreadFeed: function() { const is_cat = Feeds.activeFeedIsCat(); - const nuf = getNextUnreadFeed(Feeds.getActiveFeedId(), is_cat); + const nuf = Feeds.getNextUnreadFeed(Feeds.getActiveFeedId(), is_cat); if (nuf) this.viewfeed({feed: nuf, is_cat: is_cat}); }, collapseFeedlist: function() { @@ -129,13 +129,13 @@ const Feeds = { counters_last_request = timestamp; - let query = {op: "rpc", method: "getAllCounters", seq: App.next_seq()}; + let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()}; if (!force) query.last_article_id = getInitParam("last_article_id"); xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } else { @@ -357,7 +357,7 @@ const Feeds = { Form.enable("main_toolbar_form"); if (!delayed) - if (!setFeedExpandoIcon(feed, is_cat, + if (!Feeds.setFeedExpandoIcon(feed, is_cat, (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) notify_progress("Loading, please wait...", true); @@ -377,7 +377,7 @@ const Feeds = { catchupBatchedArticles(() => { xhrPost("backend.php", query, (transport) => { try { - setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); + Feeds.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); Headlines.onLoaded(transport, offset); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { @@ -404,221 +404,207 @@ const Feeds = { } }, decrementFeedCounter: function(feed, is_cat) { - let ctr = getFeedUnread(feed, is_cat); + let ctr = Feeds.getFeedUnread(feed, is_cat); if (ctr > 0) { - setFeedUnread(feed, is_cat, ctr - 1); + Feeds.setFeedUnread(feed, is_cat, ctr - 1); App.global_unread -= 1; App.updateTitle(); if (!is_cat) { - const cat = parseInt(getFeedCategory(feed)); + const cat = parseInt(Feeds.getFeedCategory(feed)); if (!isNaN(cat)) { - ctr = getFeedUnread(cat, true); + ctr = Feeds.getFeedUnread(cat, true); if (ctr > 0) { - setFeedUnread(cat, true, ctr - 1); + Feeds.setFeedUnread(cat, true, ctr - 1); } } } } - } -}; - -function getFeedUnread(feed, is_cat) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedUnread(feed, is_cat); - - } catch (e) { - // - } - - return -1; -} - -function getFeedCategory(feed) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.getFeedCategory(feed); - - } catch (e) { - // - } - - return false; -} - -function getFeedName(feed, is_cat) { - - if (isNaN(feed)) return feed; // it's a tag - - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedValue(feed, is_cat, 'name'); -} - -/* function getFeedValue(feed, is_cat, key) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedValue(feed, is_cat, key); + }, + catchupFeed: function(feed, is_cat, mode) { + if (is_cat == undefined) is_cat = false; + + let str = false; + + switch (mode) { + case "1day": + str = __("Mark %w in %s older than 1 day as read?"); + break; + case "1week": + str = __("Mark %w in %s older than 1 week as read?"); + break; + case "2week": + str = __("Mark %w in %s older than 2 weeks as read?"); + break; + default: + str = __("Mark %w in %s as read?"); + } - } catch (e) { - // - } - return ''; -} */ + const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); + const fn = Feeds.getFeedName(feed, is_cat); -function setFeedUnread(feed, is_cat, unread) { - const tree = dijit.byId("feedTree"); + str = str.replace("%s", fn) + .replace("%w", mark_what); - if (tree && tree.model) - return tree.model.setFeedUnread(feed, is_cat, unread); -} + if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + return; + } -function setFeedValue(feed, is_cat, key, value) { - try { - const tree = dijit.byId("feedTree"); + const catchup_query = { + op: 'rpc', method: 'catchupFeed', feed_id: feed, + is_cat: is_cat, mode: mode, search_query: last_search_query[0], + search_lang: last_search_query[1] + }; - if (tree && tree.model) - return tree.model.setFeedValue(feed, is_cat, key, value); + notify_progress("Loading, please wait...", true); - } catch (e) { - // - } -} + xhrPost("backend.php", catchup_query, (transport) => { + Utils.handleRpcJson(transport); -function setFeedIcon(feed, is_cat, src) { - const tree = dijit.byId("feedTree"); + const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; - if (tree) return tree.setFeedIcon(feed, is_cat, src); -} + if (show_next_feed) { + const nuf = Feeds.getNextUnreadFeed(feed, is_cat); -function setFeedExpandoIcon(feed, is_cat, src) { - const tree = dijit.byId("feedTree"); + if (nuf) { + this.viewfeed({feed: nuf, is_cat: is_cat}); + } + } else if (feed == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { + this.viewCurrentFeed(); + } - if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); + notify(""); + }); + }, + catchupCurrentFeed: function(mode) { + Feeds.catchupFeed(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat(), mode); + }, + catchupFeedInGroup: function(id) { + const title = Feeds.getFeedName(id); - return false; -} + const str = __("Mark all articles in %s as read?").replace("%s", title); -function getNextUnreadFeed(feed, is_cat) { - const tree = dijit.byId("feedTree"); - const nuf = tree.model.getNextUnreadFeed(feed, is_cat); + if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - if (nuf) - return tree.model.store.getValue(nuf, 'bare_id'); -} + const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='" + id + "']"); -function catchupCurrentFeed(mode) { - catchupFeed(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat(), mode); -} + if (rows.length > 0) { -function catchupFeedInGroup(id) { - const title = getFeedName(id); + rows.each(function (row) { + row.removeClassName("Unread"); - const str = __("Mark all articles in %s as read?").replace("%s", title); + if (row.getAttribute("data-article-id") != getActiveArticleId()) { + new Effect.Fade(row, {duration: 0.5}); + } - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { + }); - const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='"+id+"']"); + const feedTitles = $$("#headlines-frame > div[class='feed-title']"); - if (rows.length > 0) { + for (let i = 0; i < feedTitles.length; i++) { + if (feedTitles[i].getAttribute("data-feed-id") == id) { - rows.each(function (row) { - row.removeClassName("Unread"); + if (i < feedTitles.length - 1) { + new Effect.Fade(feedTitles[i], {duration: 0.5}); + } - if (row.getAttribute("data-article-id") != getActiveArticleId()) { - new Effect.Fade(row, {duration: 0.5}); + break; + } } - }); - - const feedTitles = $$("#headlines-frame > div[class='feed-title']"); + Headlines.updateFloatingTitle(true); + } - for (let i = 0; i < feedTitles.length; i++) { - if (feedTitles[i].getAttribute("data-feed-id") == id) { + notify_progress("Loading, please wait...", true); - if (i < feedTitles.length - 1) { - new Effect.Fade(feedTitles[i], {duration: 0.5}); - } + xhrPost("backend.php", {op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => { + Utils.handleRpcJson(transport); + }); + } + }, + getFeedUnread: function(feed, is_cat) { + try { + const tree = dijit.byId("feedTree"); - break; - } - } + if (tree && tree.model) + return tree.model.getFeedUnread(feed, is_cat); - Headlines.updateFloatingTitle(true); + } catch (e) { + // } - notify_progress("Loading, please wait...", true); + return -1; + }, + getFeedCategory: function(feed) { + try { + const tree = dijit.byId("feedTree"); - xhrPost("backend.php", { op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => { - App.handleRpcJson(transport); - }); - } -} - -function catchupFeed(feed, is_cat, mode) { - if (is_cat == undefined) is_cat = false; - - let str = false; - - switch (mode) { - case "1day": - str = __("Mark %w in %s older than 1 day as read?"); - break; - case "1week": - str = __("Mark %w in %s older than 1 week as read?"); - break; - case "2week": - str = __("Mark %w in %s older than 2 weeks as read?"); - break; - default: - str = __("Mark %w in %s as read?"); - } + if (tree && tree.model) + return tree.getFeedCategory(feed); - const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); - const fn = getFeedName(feed, is_cat); + } catch (e) { + // + } - str = str.replace("%s", fn) - .replace("%w", mark_what); + return false; + }, + getFeedName: function(feed, is_cat) { + if (isNaN(feed)) return feed; // it's a tag - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { - return; - } + const tree = dijit.byId("feedTree"); - const catchup_query = {op: 'rpc', method: 'catchupFeed', feed_id: feed, - is_cat: is_cat, mode: mode, search_query: last_search_query[0], - search_lang: last_search_query[1]}; + if (tree && tree.model) + return tree.model.getFeedValue(feed, is_cat, 'name'); + }, + setFeedUnread: function(feed, is_cat, unread) { + const tree = dijit.byId("feedTree"); - notify_progress("Loading, please wait...", true); + if (tree && tree.model) + return tree.model.setFeedUnread(feed, is_cat, unread); + }, + setFeedValue: function(feed, is_cat, key, value) { + try { + const tree = dijit.byId("feedTree"); - xhrPost("backend.php", catchup_query, (transport) => { - App.handleRpcJson(transport); + if (tree && tree.model) + return tree.model.setFeedValue(feed, is_cat, key, value); - const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; + } catch (e) { + // + } + }, + getFeedValue: function(feed, is_cat, key) { + try { + const tree = dijit.byId("feedTree"); - if (show_next_feed) { - const nuf = getNextUnreadFeed(feed, is_cat); + if (tree && tree.model) + return tree.model.getFeedValue(feed, is_cat, key); - if (nuf) { - Feeds.viewfeed({feed: nuf, is_cat: is_cat}); - } - } else if (feed == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { - Feeds.viewCurrentFeed(); + } catch (e) { + // } + return ''; + }, + setFeedIcon: function(feed, is_cat, src) { + const tree = dijit.byId("feedTree"); - notify(""); - }); -} + if (tree) return tree.setFeedIcon(feed, is_cat, src); + }, + setFeedExpandoIcon: function(feed, is_cat, src) { + const tree = dijit.byId("feedTree"); + if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); + return false; + }, + getNextUnreadFeed: function(feed, is_cat) { + const tree = dijit.byId("feedTree"); + const nuf = tree.model.getNextUnreadFeed(feed, is_cat); + if (nuf) + return tree.model.store.getValue(nuf, 'bare_id'); + } +}; -- cgit v1.2.3 From 00cd4a48d41ec470e243fe193fd96ae9d0a84902 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:23:44 +0300 Subject: Feeds -> this --- js/feedlist.js | 57 +++++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index c2a0e816d..a95a82672 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -1,8 +1,5 @@ let counters_last_request = 0; -const Counters = { -}; - const Feeds = { _active_feed_id: 0, _active_feed_is_cat: false, @@ -69,23 +66,23 @@ const Feeds = { continue; } - /*if (Feeds.getFeedUnread(id, (kind == "cat")) != ctr || + /*if (this.getFeedUnread(id, (kind == "cat")) != ctr || (kind == "cat")) { }*/ - Feeds.setFeedUnread(id, (kind == "cat"), ctr); - Feeds.setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); + this.setFeedUnread(id, (kind == "cat"), ctr); + this.setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); if (kind != "cat") { - Feeds.setFeedValue(id, false, 'error', error); - Feeds.setFeedValue(id, false, 'updated', updated); + this.setFeedValue(id, false, 'error', error); + this.setFeedValue(id, false, 'updated', updated); if (id > 0) { if (has_img) { - Feeds.setFeedIcon(id, false, + this.setFeedIcon(id, false, getInitParam("icons_url") + "/" + id + ".ico?" + has_img); } else { - Feeds.setFeedIcon(id, false, 'images/blank_icon.gif'); + this.setFeedIcon(id, false, 'images/blank_icon.gif'); } } } @@ -98,13 +95,13 @@ const Feeds = { console.log("viewCurrentFeed: " + method); if (this.getActiveFeedId() != undefined) { - this.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), method: method}); + this.viewfeed({feed: this.getActiveFeedId(), is_cat: this.activeFeedIsCat(), method: method}); } return false; // block unneeded form submits }, openNextUnreadFeed: function() { - const is_cat = Feeds.activeFeedIsCat(); - const nuf = Feeds.getNextUnreadFeed(Feeds.getActiveFeedId(), is_cat); + const is_cat = this.activeFeedIsCat(); + const nuf = this.getNextUnreadFeed(this.getActiveFeedId(), is_cat); if (nuf) this.viewfeed({feed: nuf, is_cat: is_cat}); }, collapseFeedlist: function() { @@ -118,7 +115,7 @@ const Feeds = { }, cancelSearch: function() { this._search_query = ""; - Feeds.viewCurrentFeed(); + this.viewCurrentFeed(); }, requestCounters: function(force) { const date = new Date(); @@ -172,7 +169,7 @@ const Feeds = { const id = String(item.id); const is_cat = id.match("^CAT:"); const feed = id.substr(id.indexOf(":") + 1); - Feeds.viewfeed({feed: feed, is_cat: is_cat}); + this.viewfeed({feed: feed, is_cat: is_cat}); return false; }, openOnClick: false, @@ -305,7 +302,7 @@ const Feeds = { // this is used to quickly switch between feeds, sets active but xhr is on a timeout const delayed = params.delayed || false; - if (feed != Feeds.getActiveFeedId() || Feeds.activeFeedIsCat() != is_cat) { + if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) { this._search_query = false; setActiveArticleId(0); } @@ -350,20 +347,20 @@ const Feeds = { if (vgroup_last_feed) { query.vgrlf = vgroup_last_feed; } - } else if (!is_cat && feed == Feeds.getActiveFeedId() && !params.method) { + } else if (!is_cat && feed == this.getActiveFeedId() && !params.method) { query.m = "ForceUpdate"; } Form.enable("main_toolbar_form"); if (!delayed) - if (!Feeds.setFeedExpandoIcon(feed, is_cat, + if (!this.setFeedExpandoIcon(feed, is_cat, (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) notify_progress("Loading, please wait...", true); query.cat = is_cat; - Feeds.setActiveFeedId(feed, is_cat); + this.setActiveFeedId(feed, is_cat); if (viewfeed_debug) { window.open("backend.php?" + @@ -377,7 +374,7 @@ const Feeds = { catchupBatchedArticles(() => { xhrPost("backend.php", query, (transport) => { try { - Feeds.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); + this.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); Headlines.onLoaded(transport, offset); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { @@ -404,21 +401,21 @@ const Feeds = { } }, decrementFeedCounter: function(feed, is_cat) { - let ctr = Feeds.getFeedUnread(feed, is_cat); + let ctr = this.getFeedUnread(feed, is_cat); if (ctr > 0) { - Feeds.setFeedUnread(feed, is_cat, ctr - 1); + this.setFeedUnread(feed, is_cat, ctr - 1); App.global_unread -= 1; App.updateTitle(); if (!is_cat) { - const cat = parseInt(Feeds.getFeedCategory(feed)); + const cat = parseInt(this.getFeedCategory(feed)); if (!isNaN(cat)) { - ctr = Feeds.getFeedUnread(cat, true); + ctr = this.getFeedUnread(cat, true); if (ctr > 0) { - Feeds.setFeedUnread(cat, true, ctr - 1); + this.setFeedUnread(cat, true, ctr - 1); } } } @@ -444,7 +441,7 @@ const Feeds = { } const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); - const fn = Feeds.getFeedName(feed, is_cat); + const fn = this.getFeedName(feed, is_cat); str = str.replace("%s", fn) .replace("%w", mark_what); @@ -467,12 +464,12 @@ const Feeds = { const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; if (show_next_feed) { - const nuf = Feeds.getNextUnreadFeed(feed, is_cat); + const nuf = this.getNextUnreadFeed(feed, is_cat); if (nuf) { this.viewfeed({feed: nuf, is_cat: is_cat}); } - } else if (feed == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { + } else if (feed == this.getActiveFeedId() && is_cat == this.activeFeedIsCat()) { this.viewCurrentFeed(); } @@ -480,10 +477,10 @@ const Feeds = { }); }, catchupCurrentFeed: function(mode) { - Feeds.catchupFeed(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat(), mode); + this.catchupFeed(this.getActiveFeedId(), this.activeFeedIsCat(), mode); }, catchupFeedInGroup: function(id) { - const title = Feeds.getFeedName(id); + const title = this.getFeedName(id); const str = __("Mark all articles in %s as read?").replace("%s", title); -- cgit v1.2.3 From 97df81d8d9d9ebcbf5a41dd736924d7a61855fbc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:54:16 +0300 Subject: even more objectification of JS --- js/feedlist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index a95a82672..a0b552132 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -43,7 +43,7 @@ const Feeds = { parseCounters: function (elems) { for (let l = 0; l < elems.length; l++) { - if (this._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) { + if (Feeds._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) { continue; } @@ -169,7 +169,7 @@ const Feeds = { const id = String(item.id); const is_cat = id.match("^CAT:"); const feed = id.substr(id.indexOf(":") + 1); - this.viewfeed({feed: feed, is_cat: is_cat}); + Feeds.viewfeed({feed: feed, is_cat: is_cat}); return false; }, openOnClick: false, -- cgit v1.2.3 From 18868fb7ac1006bafa13895360591fdbc3c75736 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 18:03:58 +0300 Subject: remove counters_last_request from globals --- js/feedlist.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index a0b552132..ddef1a586 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -1,6 +1,5 @@ -let counters_last_request = 0; - const Feeds = { + counters_last_request: 0, _active_feed_id: 0, _active_feed_is_cat: false, infscroll_in_progress: 0, @@ -121,10 +120,10 @@ const Feeds = { const date = new Date(); const timestamp = Math.round(date.getTime() / 1000); - if (force || timestamp - counters_last_request > 5) { + if (force || timestamp - this.counters_last_request > 5) { console.log("scheduling request of counters..."); - counters_last_request = timestamp; + this.counters_last_request = timestamp; let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()}; @@ -136,7 +135,7 @@ const Feeds = { }); } else { - console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); + console.log("request_counters: rate limit reached: " + (timestamp - this.counters_last_request)); } }, reload: function() { -- cgit v1.2.3 From 4bed9be57d671324921bfd1d90d25b8cd0af3d4f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 18:25:32 +0300 Subject: js-ification: start on some common dialogs --- js/feedlist.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index ddef1a586..f2f5e60ba 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -190,7 +190,7 @@ const Feeds = { try { Feeds.init(); - setLoadingProgress(25); + Utils.setLoadingProgress(25); } catch (e) { exception_error(e); } @@ -204,7 +204,7 @@ const Feeds = { init: function() { console.log("in feedlist init"); - setLoadingProgress(50); + Utils.setLoadingProgress(50); document.onkeydown = App.hotkeyHandler; setInterval(hotkeyPrefixTimeout, 3 * 1000); @@ -602,5 +602,35 @@ const Feeds = { if (nuf) return tree.model.store.getValue(nuf, 'bare_id'); - } + }, + search: function() { + const query = "backend.php?op=feeds&method=search¶m=" + + param_escape(Feeds.getActiveFeedId() + ":" + Feeds.activeFeedIsCat()); + + if (dijit.byId("searchDlg")) + dijit.byId("searchDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "searchDlg", + title: __("Search"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + Feeds._search_query = this.attr('value'); + this.hide(); + Feeds.viewCurrentFeed(); + } + }, + href: query + }); + + dialog.show(); + }, + updateRandomFeed: function() { + console.log("in update_random_feed"); + + xhrPost("backend.php", {op: "rpc", method: "updateRandomFeed"}, (transport) => { + Utils.handleRpcJson(transport, true); + }); + }, }; -- cgit v1.2.3 From 642c37ea6117954fc19e2a800f2fce4c1304d89d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 21:01:53 +0300 Subject: further effocts to wrap JS stuff into objects --- js/feedlist.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index f2f5e60ba..ad863f94c 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -207,8 +207,8 @@ const Feeds = { Utils.setLoadingProgress(50); document.onkeydown = App.hotkeyHandler; - setInterval(hotkeyPrefixTimeout, 3 * 1000); - setInterval(catchupBatchedArticles, 10 * 1000); + window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000); + window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); if (!this.getActiveFeedId()) { this.viewfeed({feed: -3}); @@ -246,10 +246,7 @@ const Feeds = { } else { setTimeout(() => { this.requestCounters(true); - - setInterval(() => { - this.requestCounters(); - }, 60 * 1000) + setInterval(() => { this.requestCounters(); }, 60 * 1000) }, 250); } }, @@ -271,7 +268,7 @@ const Feeds = { this.selectFeed(id, is_cat); - PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id); + PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, [this._active_feed_id, this._active_feed_is_cat]); }, selectFeed: function(feed, is_cat) { const tree = dijit.byId("feedTree"); @@ -303,7 +300,7 @@ const Feeds = { if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) { this._search_query = false; - setActiveArticleId(0); + Article.setActiveArticleId(0); } if (offset != 0) { @@ -330,8 +327,8 @@ const Feeds = { if (method) query.m = method; if (offset > 0) { - if (current_first_id) { - query.fid = current_first_id; + if (Headlines.current_first_id) { + query.fid = Headlines.current_first_id; } } @@ -343,8 +340,8 @@ const Feeds = { query.skip = offset; // to prevent duplicate feed titles when showing grouped vfeeds - if (vgroup_last_feed) { - query.vgrlf = vgroup_last_feed; + if (Headlines.vgroup_last_feed != undefined) { + query.vgrlf = Headlines.vgroup_last_feed; } } else if (!is_cat && feed == this.getActiveFeedId() && !params.method) { query.m = "ForceUpdate"; @@ -370,7 +367,7 @@ const Feeds = { window.clearTimeout(this._viewfeed_wait_timeout); this._viewfeed_wait_timeout = window.setTimeout(() => { - catchupBatchedArticles(() => { + Headlines.catchupBatchedArticles(() => { xhrPost("backend.php", query, (transport) => { try { this.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); @@ -492,7 +489,7 @@ const Feeds = { rows.each(function (row) { row.removeClassName("Unread"); - if (row.getAttribute("data-article-id") != getActiveArticleId()) { + if (row.getAttribute("data-article-id") != Article.getActiveArticleId()) { new Effect.Fade(row, {duration: 0.5}); } -- cgit v1.2.3 From cc26be0793c6c0e44a540c25f86627342a82714f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 21:51:00 +0300 Subject: migrate tt-rss.js contents to App --- js/feedlist.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index ad863f94c..c295bf22b 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -6,6 +6,7 @@ const Feeds = { infscroll_disabled: 0, _infscroll_timeout: false, _search_query: false, + last_search_query: [], _viewfeed_wait_timeout: false, _counters_prev: [], // NOTE: this implementation is incomplete @@ -206,7 +207,7 @@ const Feeds = { Utils.setLoadingProgress(50); - document.onkeydown = App.hotkeyHandler; + document.onkeydown = () => { App.hotkeyHandler(event) }; window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000); window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); @@ -436,7 +437,7 @@ const Feeds = { str = __("Mark %w in %s as read?"); } - const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); + const mark_what = this.last_search_query && this.last_search_query[0] ? __("search results") : __("all articles"); const fn = this.getFeedName(feed, is_cat); str = str.replace("%s", fn) @@ -448,8 +449,8 @@ const Feeds = { const catchup_query = { op: 'rpc', method: 'catchupFeed', feed_id: feed, - is_cat: is_cat, mode: mode, search_query: last_search_query[0], - search_lang: last_search_query[1] + is_cat: is_cat, mode: mode, search_query: this.last_search_query[0], + search_lang: this.last_search_query[1] }; notify_progress("Loading, please wait...", true); -- cgit v1.2.3 From de9509cd31d63b036f63fc56697e018263e52eda Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:07:00 +0300 Subject: hotkeys: simplify prefix timeout handling --- js/feedlist.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index c295bf22b..bff62043f 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -1,3 +1,5 @@ +/* global notify,__,dijit */ + const Feeds = { counters_last_request: 0, _active_feed_id: 0, @@ -208,7 +210,6 @@ const Feeds = { Utils.setLoadingProgress(50); document.onkeydown = () => { App.hotkeyHandler(event) }; - window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000); window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); if (!this.getActiveFeedId()) { -- cgit v1.2.3 From 4b492cc93ef2a15a4d5dfe51d38164884464d1a9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:24:30 +0300 Subject: clear _infscroll_timeout when headlines are loaded --- js/feedlist.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index bff62043f..33b5806e5 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -372,6 +372,7 @@ const Feeds = { Headlines.catchupBatchedArticles(() => { xhrPost("backend.php", query, (transport) => { try { + window.clearTimeout(this._infscroll_timeout); this.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); Headlines.onLoaded(transport, offset); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); -- cgit v1.2.3 From e5f3b755405ebf191835b449d08a2a8ac7dfebfb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 07:31:10 +0300 Subject: fix some minor linter problems --- js/feedlist.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index 33b5806e5..53274b8ba 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -1,4 +1,4 @@ -/* global notify,__,dijit */ +/* global notify,__,dijit,fox */ const Feeds = { counters_last_request: 0, @@ -155,6 +155,7 @@ const Feeds = { url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2" }); + // noinspection JSUnresolvedFunction const treeModel = new fox.FeedStoreModel({ store: store, query: { @@ -165,9 +166,10 @@ const Feeds = { childrenAttrs: ["items"] }); + // noinspection JSUnresolvedFunction const tree = new fox.FeedTree({ model: treeModel, - onClick: function (item, node) { + onClick: function (item/*, node*/) { const id = String(item.id); const is_cat = id.match("^CAT:"); const feed = id.substr(id.indexOf(":") + 1); -- cgit v1.2.3 From 3678315bead3f7264dc2aa9c7feb6e0a0f20ea63 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 08:32:13 +0300 Subject: Article, Headlines: shorten several method names --- js/feedlist.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index 53274b8ba..400328317 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -212,7 +212,7 @@ const Feeds = { Utils.setLoadingProgress(50); document.onkeydown = () => { App.hotkeyHandler(event) }; - window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); + window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000); if (!this.getActiveFeedId()) { this.viewfeed({feed: -3}); @@ -304,7 +304,7 @@ const Feeds = { if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) { this._search_query = false; - Article.setActiveArticleId(0); + Article.setActive(0); } if (offset != 0) { @@ -371,7 +371,7 @@ const Feeds = { window.clearTimeout(this._viewfeed_wait_timeout); this._viewfeed_wait_timeout = window.setTimeout(() => { - Headlines.catchupBatchedArticles(() => { + Headlines.catchupBatched(() => { xhrPost("backend.php", query, (transport) => { try { window.clearTimeout(this._infscroll_timeout); @@ -494,7 +494,7 @@ const Feeds = { rows.each(function (row) { row.removeClassName("Unread"); - if (row.getAttribute("data-article-id") != Article.getActiveArticleId()) { + if (row.getAttribute("data-article-id") != Article.getActive()) { new Effect.Fade(row, {duration: 0.5}); } -- cgit v1.2.3 From 0a18d0b1edb208e5811c419a1119d131b7041173 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 08:57:22 +0300 Subject: Feeds: shorten some method names finally rename "view as rss" --- js/feedlist.js | 122 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js index 400328317..eca068204 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -68,23 +68,23 @@ const Feeds = { continue; } - /*if (this.getFeedUnread(id, (kind == "cat")) != ctr || + /*if (this.getUnread(id, (kind == "cat")) != ctr || (kind == "cat")) { }*/ - this.setFeedUnread(id, (kind == "cat"), ctr); - this.setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); + this.setUnread(id, (kind == "cat"), ctr); + this.setValue(id, (kind == "cat"), 'auxcounter', auxctr); if (kind != "cat") { - this.setFeedValue(id, false, 'error', error); - this.setFeedValue(id, false, 'updated', updated); + this.setValue(id, false, 'error', error); + this.setValue(id, false, 'updated', updated); if (id > 0) { if (has_img) { - this.setFeedIcon(id, false, + this.setIcon(id, false, getInitParam("icons_url") + "/" + id + ".ico?" + has_img); } else { - this.setFeedIcon(id, false, 'images/blank_icon.gif'); + this.setIcon(id, false, 'images/blank_icon.gif'); } } } @@ -93,20 +93,20 @@ const Feeds = { this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); this._counters_prev = elems; }, - viewCurrentFeed: function(method) { - console.log("viewCurrentFeed: " + method); + reloadCurrent: function(method) { + console.log("reloadCurrent: " + method); - if (this.getActiveFeedId() != undefined) { - this.viewfeed({feed: this.getActiveFeedId(), is_cat: this.activeFeedIsCat(), method: method}); + if (this.getActive() != undefined) { + this.open({feed: this.getActive(), is_cat: this.activeIsCat(), method: method}); } return false; // block unneeded form submits }, - openNextUnreadFeed: function() { - const is_cat = this.activeFeedIsCat(); - const nuf = this.getNextUnreadFeed(this.getActiveFeedId(), is_cat); - if (nuf) this.viewfeed({feed: nuf, is_cat: is_cat}); + openNextUnread: function() { + const is_cat = this.activeIsCat(); + const nuf = this.getNextUnread(this.getActive(), is_cat); + if (nuf) this.open({feed: nuf, is_cat: is_cat}); }, - collapseFeedlist: function() { + toggle: function() { Element.toggle("feeds-holder"); const splitter = $("feeds-holder_splitter"); @@ -117,7 +117,7 @@ const Feeds = { }, cancelSearch: function() { this._search_query = ""; - this.viewCurrentFeed(); + this.reloadCurrent(); }, requestCounters: function(force) { const date = new Date(); @@ -173,7 +173,7 @@ const Feeds = { const id = String(item.id); const is_cat = id.match("^CAT:"); const feed = id.substr(id.indexOf(":") + 1); - Feeds.viewfeed({feed: feed, is_cat: is_cat}); + Feeds.open({feed: feed, is_cat: is_cat}); return false; }, openOnClick: false, @@ -214,10 +214,10 @@ const Feeds = { document.onkeydown = () => { App.hotkeyHandler(event) }; window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000); - if (!this.getActiveFeedId()) { - this.viewfeed({feed: -3}); + if (!this.getActive()) { + this.open({feed: -3}); } else { - this.viewfeed({feed: this.getActiveFeedId(), is_cat: this.activeFeedIsCat()}); + this.open({feed: this.getActive(), is_cat: this.activeIsCat()}); } this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); @@ -254,13 +254,13 @@ const Feeds = { }, 250); } }, - activeFeedIsCat: function() { + activeIsCat: function() { return !!this._active_feed_is_cat; }, - getActiveFeedId: function() { + getActive: function() { return this._active_feed_id; }, - setActiveFeedId: function(id, is_cat) { + setActive: function(id, is_cat) { hash_set('f', id); hash_set('c', is_cat ? 1 : 0); @@ -270,16 +270,16 @@ const Feeds = { $("headlines-frame").setAttribute("feed-id", id); $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0); - this.selectFeed(id, is_cat); + this.select(id, is_cat); PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, [this._active_feed_id, this._active_feed_is_cat]); }, - selectFeed: function(feed, is_cat) { + select: function(feed, is_cat) { const tree = dijit.byId("feedTree"); if (tree) return tree.selectFeed(feed, is_cat); }, - toggleDispRead: function() { + toggleUnread: function() { const hide = !(getInitParam("hide_read_feeds") == "1"); xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => { @@ -293,7 +293,7 @@ const Feeds = { if (tree) return tree.hideRead(hide, getInitParam("hide_read_shows_special")); }, - viewfeed: function(params) { + open: function(params) { const feed = params.feed; const is_cat = !!params.is_cat || false; const offset = params.offset || 0; @@ -302,7 +302,7 @@ const Feeds = { // this is used to quickly switch between feeds, sets active but xhr is on a timeout const delayed = params.delayed || false; - if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) { + if (feed != this.getActive() || this.activeIsCat() != is_cat) { this._search_query = false; Article.setActive(0); } @@ -347,20 +347,20 @@ const Feeds = { if (Headlines.vgroup_last_feed != undefined) { query.vgrlf = Headlines.vgroup_last_feed; } - } else if (!is_cat && feed == this.getActiveFeedId() && !params.method) { + } else if (!is_cat && feed == this.getActive() && !params.method) { query.m = "ForceUpdate"; } Form.enable("main_toolbar_form"); if (!delayed) - if (!this.setFeedExpandoIcon(feed, is_cat, + if (!this.setExpando(feed, is_cat, (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) notify_progress("Loading, please wait...", true); query.cat = is_cat; - this.setActiveFeedId(feed, is_cat); + this.setActive(feed, is_cat); if (viewfeed_debug) { window.open("backend.php?" + @@ -375,7 +375,7 @@ const Feeds = { xhrPost("backend.php", query, (transport) => { try { window.clearTimeout(this._infscroll_timeout); - this.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); + this.setExpando(feed, is_cat, 'images/blank_icon.gif'); Headlines.onLoaded(transport, offset); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { @@ -385,7 +385,7 @@ const Feeds = { }); }, delayed ? 250 : 0); }, - catchupAllFeeds: function() { + catchupAll: function() { const str = __("Mark all articles as read?"); if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { @@ -394,7 +394,7 @@ const Feeds = { xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => { this.requestCounters(true); - this.viewCurrentFeed(); + this.reloadCurrent(); }); App.global_unread = 0; @@ -402,21 +402,21 @@ const Feeds = { } }, decrementFeedCounter: function(feed, is_cat) { - let ctr = this.getFeedUnread(feed, is_cat); + let ctr = this.getUnread(feed, is_cat); if (ctr > 0) { - this.setFeedUnread(feed, is_cat, ctr - 1); + this.setUnread(feed, is_cat, ctr - 1); App.global_unread -= 1; App.updateTitle(); if (!is_cat) { - const cat = parseInt(this.getFeedCategory(feed)); + const cat = parseInt(this.getCategory(feed)); if (!isNaN(cat)) { - ctr = this.getFeedUnread(cat, true); + ctr = this.getUnread(cat, true); if (ctr > 0) { - this.setFeedUnread(cat, true, ctr - 1); + this.setUnread(cat, true, ctr - 1); } } } @@ -442,7 +442,7 @@ const Feeds = { } const mark_what = this.last_search_query && this.last_search_query[0] ? __("search results") : __("all articles"); - const fn = this.getFeedName(feed, is_cat); + const fn = this.getName(feed, is_cat); str = str.replace("%s", fn) .replace("%w", mark_what); @@ -465,23 +465,23 @@ const Feeds = { const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; if (show_next_feed) { - const nuf = this.getNextUnreadFeed(feed, is_cat); + const nuf = this.getNextUnread(feed, is_cat); if (nuf) { - this.viewfeed({feed: nuf, is_cat: is_cat}); + this.open({feed: nuf, is_cat: is_cat}); } - } else if (feed == this.getActiveFeedId() && is_cat == this.activeFeedIsCat()) { - this.viewCurrentFeed(); + } else if (feed == this.getActive() && is_cat == this.activeIsCat()) { + this.reloadCurrent(); } notify(""); }); }, - catchupCurrentFeed: function(mode) { - this.catchupFeed(this.getActiveFeedId(), this.activeFeedIsCat(), mode); + catchupCurrent: function(mode) { + this.catchupFeed(this.getActive(), this.activeIsCat(), mode); }, catchupFeedInGroup: function(id) { - const title = this.getFeedName(id); + const title = this.getName(id); const str = __("Mark all articles in %s as read?").replace("%s", title); @@ -523,7 +523,7 @@ const Feeds = { }); } }, - getFeedUnread: function(feed, is_cat) { + getUnread: function(feed, is_cat) { try { const tree = dijit.byId("feedTree"); @@ -536,7 +536,7 @@ const Feeds = { return -1; }, - getFeedCategory: function(feed) { + getCategory: function(feed) { try { const tree = dijit.byId("feedTree"); @@ -549,7 +549,7 @@ const Feeds = { return false; }, - getFeedName: function(feed, is_cat) { + getName: function(feed, is_cat) { if (isNaN(feed)) return feed; // it's a tag const tree = dijit.byId("feedTree"); @@ -557,13 +557,13 @@ const Feeds = { if (tree && tree.model) return tree.model.getFeedValue(feed, is_cat, 'name'); }, - setFeedUnread: function(feed, is_cat, unread) { + setUnread: function(feed, is_cat, unread) { const tree = dijit.byId("feedTree"); if (tree && tree.model) return tree.model.setFeedUnread(feed, is_cat, unread); }, - setFeedValue: function(feed, is_cat, key, value) { + setValue: function(feed, is_cat, key, value) { try { const tree = dijit.byId("feedTree"); @@ -574,7 +574,7 @@ const Feeds = { // } }, - getFeedValue: function(feed, is_cat, key) { + getValue: function(feed, is_cat, key) { try { const tree = dijit.byId("feedTree"); @@ -586,19 +586,19 @@ const Feeds = { } return ''; }, - setFeedIcon: function(feed, is_cat, src) { + setIcon: function(feed, is_cat, src) { const tree = dijit.byId("feedTree"); if (tree) return tree.setFeedIcon(feed, is_cat, src); }, - setFeedExpandoIcon: function(feed, is_cat, src) { + setExpando: function(feed, is_cat, src) { const tree = dijit.byId("feedTree"); if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); return false; }, - getNextUnreadFeed: function(feed, is_cat) { + getNextUnread: function(feed, is_cat) { const tree = dijit.byId("feedTree"); const nuf = tree.model.getNextUnreadFeed(feed, is_cat); @@ -607,7 +607,7 @@ const Feeds = { }, search: function() { const query = "backend.php?op=feeds&method=search¶m=" + - param_escape(Feeds.getActiveFeedId() + ":" + Feeds.activeFeedIsCat()); + param_escape(Feeds.getActive() + ":" + Feeds.activeIsCat()); if (dijit.byId("searchDlg")) dijit.byId("searchDlg").destroyRecursive(); @@ -620,7 +620,7 @@ const Feeds = { if (this.validate()) { Feeds._search_query = this.attr('value'); this.hide(); - Feeds.viewCurrentFeed(); + Feeds.reloadCurrent(); } }, href: query @@ -628,10 +628,10 @@ const Feeds = { dialog.show(); }, - updateRandomFeed: function() { + updateRandom: function() { console.log("in update_random_feed"); - xhrPost("backend.php", {op: "rpc", method: "updateRandomFeed"}, (transport) => { + xhrPost("backend.php", {op: "rpc", method: "updateRandom"}, (transport) => { Utils.handleRpcJson(transport, true); }); }, -- cgit v1.2.3 From 807ff074540575e6ef8f99ad32b098a816091171 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 17:18:59 +0300 Subject: split main objects to dojo modules --- js/feedlist.js | 638 --------------------------------------------------------- 1 file changed, 638 deletions(-) delete mode 100644 js/feedlist.js (limited to 'js/feedlist.js') diff --git a/js/feedlist.js b/js/feedlist.js deleted file mode 100644 index eca068204..000000000 --- a/js/feedlist.js +++ /dev/null @@ -1,638 +0,0 @@ -/* global notify,__,dijit,fox */ - -const Feeds = { - counters_last_request: 0, - _active_feed_id: 0, - _active_feed_is_cat: false, - infscroll_in_progress: 0, - infscroll_disabled: 0, - _infscroll_timeout: false, - _search_query: false, - last_search_query: [], - _viewfeed_wait_timeout: false, - _counters_prev: [], - // NOTE: this implementation is incomplete - // for general objects but good enough for counters - // http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html - counterEquals: function(a, b) { - // Create arrays of property names - const aProps = Object.getOwnPropertyNames(a); - const bProps = Object.getOwnPropertyNames(b); - - // If number of properties is different, - // objects are not equivalent - if (aProps.length != bProps.length) { - return false; - } - - for (let i = 0; i < aProps.length; i++) { - const propName = aProps[i]; - - // If values of same property are not equal, - // objects are not equivalent - if (a[propName] !== b[propName]) { - return false; - } - } - - // If we made it this far, objects - // are considered equivalent - return true; - }, - resetCounters: function () { - this._counters_prev = []; - }, - parseCounters: function (elems) { - for (let l = 0; l < elems.length; l++) { - - if (Feeds._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) { - continue; - } - - const id = elems[l].id; - const kind = elems[l].kind; - const ctr = parseInt(elems[l].counter); - const error = elems[l].error; - const has_img = elems[l].has_img; - const updated = elems[l].updated; - const auxctr = parseInt(elems[l].auxcounter); - - if (id == "global-unread") { - App.global_unread = ctr; - App.updateTitle(); - continue; - } - - if (id == "subscribed-feeds") { - /* feeds_found = ctr; */ - continue; - } - - /*if (this.getUnread(id, (kind == "cat")) != ctr || - (kind == "cat")) { - }*/ - - this.setUnread(id, (kind == "cat"), ctr); - this.setValue(id, (kind == "cat"), 'auxcounter', auxctr); - - if (kind != "cat") { - this.setValue(id, false, 'error', error); - this.setValue(id, false, 'updated', updated); - - if (id > 0) { - if (has_img) { - this.setIcon(id, false, - getInitParam("icons_url") + "/" + id + ".ico?" + has_img); - } else { - this.setIcon(id, false, 'images/blank_icon.gif'); - } - } - } - } - - this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); - this._counters_prev = elems; - }, - reloadCurrent: function(method) { - console.log("reloadCurrent: " + method); - - if (this.getActive() != undefined) { - this.open({feed: this.getActive(), is_cat: this.activeIsCat(), method: method}); - } - return false; // block unneeded form submits - }, - openNextUnread: function() { - const is_cat = this.activeIsCat(); - const nuf = this.getNextUnread(this.getActive(), is_cat); - if (nuf) this.open({feed: nuf, is_cat: is_cat}); - }, - toggle: function() { - Element.toggle("feeds-holder"); - - const splitter = $("feeds-holder_splitter"); - - Element.visible("feeds-holder") ? splitter.show() : splitter.hide(); - - dijit.byId("main").resize(); - }, - cancelSearch: function() { - this._search_query = ""; - this.reloadCurrent(); - }, - requestCounters: function(force) { - const date = new Date(); - const timestamp = Math.round(date.getTime() / 1000); - - if (force || timestamp - this.counters_last_request > 5) { - console.log("scheduling request of counters..."); - - this.counters_last_request = timestamp; - - let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()}; - - if (!force) - query.last_article_id = getInitParam("last_article_id"); - - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); - }); - - } else { - console.log("request_counters: rate limit reached: " + (timestamp - this.counters_last_request)); - } - }, - reload: function() { - try { - Element.show("feedlistLoading"); - - this.resetCounters(); - - if (dijit.byId("feedTree")) { - dijit.byId("feedTree").destroyRecursive(); - } - - const store = new dojo.data.ItemFileWriteStore({ - url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2" - }); - - // noinspection JSUnresolvedFunction - const treeModel = new fox.FeedStoreModel({ - store: store, - query: { - "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed" - }, - rootId: "root", - rootLabel: "Feeds", - childrenAttrs: ["items"] - }); - - // noinspection JSUnresolvedFunction - const tree = new fox.FeedTree({ - model: treeModel, - onClick: function (item/*, node*/) { - const id = String(item.id); - const is_cat = id.match("^CAT:"); - const feed = id.substr(id.indexOf(":") + 1); - Feeds.open({feed: feed, is_cat: is_cat}); - return false; - }, - openOnClick: false, - showRoot: false, - persist: true, - id: "feedTree", - }, "feedTree"); - - const tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) { - console.log(dijit.getEnclosingWidget(event.target)); - dojo.disconnect(tmph); - }); - - $("feeds-holder").appendChild(tree.domNode); - - const tmph2 = dojo.connect(tree, 'onLoad', function () { - dojo.disconnect(tmph2); - Element.hide("feedlistLoading"); - - try { - Feeds.init(); - Utils.setLoadingProgress(25); - } catch (e) { - exception_error(e); - } - }); - - tree.startup(); - } catch (e) { - exception_error(e); - } - }, - init: function() { - console.log("in feedlist init"); - - Utils.setLoadingProgress(50); - - document.onkeydown = () => { App.hotkeyHandler(event) }; - window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000); - - if (!this.getActive()) { - this.open({feed: -3}); - } else { - this.open({feed: this.getActive(), is_cat: this.activeIsCat()}); - } - - this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); - - if (getInitParam("is_default_pw")) { - console.warn("user password is at default value"); - - const dialog = new dijit.Dialog({ - title: __("Your password is at default value"), - href: "backend.php?op=dlg&method=defaultpasswordwarning", - id: 'infoBox', - style: "width: 600px", - onCancel: function () { - return true; - }, - onExecute: function () { - return true; - }, - onClose: function () { - return true; - } - }); - - dialog.show(); - } - - // bw_limit disables timeout() so we request initial counters separately - if (getInitParam("bw_limit") == "1") { - this.requestCounters(true); - } else { - setTimeout(() => { - this.requestCounters(true); - setInterval(() => { this.requestCounters(); }, 60 * 1000) - }, 250); - } - }, - activeIsCat: function() { - return !!this._active_feed_is_cat; - }, - getActive: function() { - return this._active_feed_id; - }, - setActive: function(id, is_cat) { - hash_set('f', id); - hash_set('c', is_cat ? 1 : 0); - - this._active_feed_id = id; - this._active_feed_is_cat = is_cat; - - $("headlines-frame").setAttribute("feed-id", id); - $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0); - - this.select(id, is_cat); - - PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, [this._active_feed_id, this._active_feed_is_cat]); - }, - select: function(feed, is_cat) { - const tree = dijit.byId("feedTree"); - - if (tree) return tree.selectFeed(feed, is_cat); - }, - toggleUnread: function() { - const hide = !(getInitParam("hide_read_feeds") == "1"); - - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => { - this.hideOrShowFeeds(hide); - setInitParam("hide_read_feeds", hide); - }); - }, - hideOrShowFeeds: function(hide) { - const tree = dijit.byId("feedTree"); - - if (tree) - return tree.hideRead(hide, getInitParam("hide_read_shows_special")); - }, - open: function(params) { - const feed = params.feed; - const is_cat = !!params.is_cat || false; - const offset = params.offset || 0; - const viewfeed_debug = params.viewfeed_debug; - const method = params.method; - // this is used to quickly switch between feeds, sets active but xhr is on a timeout - const delayed = params.delayed || false; - - if (feed != this.getActive() || this.activeIsCat() != is_cat) { - this._search_query = false; - Article.setActive(0); - } - - if (offset != 0) { - if (this.infscroll_in_progress) - return; - - this.infscroll_in_progress = 1; - - window.clearTimeout(this._infscroll_timeout); - this._infscroll_timeout = window.setTimeout(() => { - console.log('infscroll request timed out, aborting'); - this.infscroll_in_progress = 0; - - // call scroll handler to maybe repeat infscroll request - Headlines.scrollHandler(); - }, 10 * 1000); - } - - Form.enable("main_toolbar_form"); - - let query = Object.assign({op: "feeds", method: "view", feed: feed}, - dojo.formToObject("main_toolbar_form")); - - if (method) query.m = method; - - if (offset > 0) { - if (Headlines.current_first_id) { - query.fid = Headlines.current_first_id; - } - } - - if (this._search_query) { - query = Object.assign(query, this._search_query); - } - - if (offset != 0) { - query.skip = offset; - - // to prevent duplicate feed titles when showing grouped vfeeds - if (Headlines.vgroup_last_feed != undefined) { - query.vgrlf = Headlines.vgroup_last_feed; - } - } else if (!is_cat && feed == this.getActive() && !params.method) { - query.m = "ForceUpdate"; - } - - Form.enable("main_toolbar_form"); - - if (!delayed) - if (!this.setExpando(feed, is_cat, - (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) - notify_progress("Loading, please wait...", true); - - query.cat = is_cat; - - this.setActive(feed, is_cat); - - if (viewfeed_debug) { - window.open("backend.php?" + - dojo.objectToQuery( - Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query) - )); - } - - window.clearTimeout(this._viewfeed_wait_timeout); - this._viewfeed_wait_timeout = window.setTimeout(() => { - Headlines.catchupBatched(() => { - xhrPost("backend.php", query, (transport) => { - try { - window.clearTimeout(this._infscroll_timeout); - this.setExpando(feed, is_cat, 'images/blank_icon.gif'); - Headlines.onLoaded(transport, offset); - PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); - } catch (e) { - exception_error(e); - } - }); - }); - }, delayed ? 250 : 0); - }, - catchupAll: function() { - const str = __("Mark all articles as read?"); - - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - - notify_progress("Marking all feeds as read..."); - - xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => { - this.requestCounters(true); - this.reloadCurrent(); - }); - - App.global_unread = 0; - App.updateTitle(); - } - }, - decrementFeedCounter: function(feed, is_cat) { - let ctr = this.getUnread(feed, is_cat); - - if (ctr > 0) { - this.setUnread(feed, is_cat, ctr - 1); - App.global_unread -= 1; - App.updateTitle(); - - if (!is_cat) { - const cat = parseInt(this.getCategory(feed)); - - if (!isNaN(cat)) { - ctr = this.getUnread(cat, true); - - if (ctr > 0) { - this.setUnread(cat, true, ctr - 1); - } - } - } - } - }, - catchupFeed: function(feed, is_cat, mode) { - if (is_cat == undefined) is_cat = false; - - let str = false; - - switch (mode) { - case "1day": - str = __("Mark %w in %s older than 1 day as read?"); - break; - case "1week": - str = __("Mark %w in %s older than 1 week as read?"); - break; - case "2week": - str = __("Mark %w in %s older than 2 weeks as read?"); - break; - default: - str = __("Mark %w in %s as read?"); - } - - const mark_what = this.last_search_query && this.last_search_query[0] ? __("search results") : __("all articles"); - const fn = this.getName(feed, is_cat); - - str = str.replace("%s", fn) - .replace("%w", mark_what); - - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { - return; - } - - const catchup_query = { - op: 'rpc', method: 'catchupFeed', feed_id: feed, - is_cat: is_cat, mode: mode, search_query: this.last_search_query[0], - search_lang: this.last_search_query[1] - }; - - notify_progress("Loading, please wait...", true); - - xhrPost("backend.php", catchup_query, (transport) => { - Utils.handleRpcJson(transport); - - const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; - - if (show_next_feed) { - const nuf = this.getNextUnread(feed, is_cat); - - if (nuf) { - this.open({feed: nuf, is_cat: is_cat}); - } - } else if (feed == this.getActive() && is_cat == this.activeIsCat()) { - this.reloadCurrent(); - } - - notify(""); - }); - }, - catchupCurrent: function(mode) { - this.catchupFeed(this.getActive(), this.activeIsCat(), mode); - }, - catchupFeedInGroup: function(id) { - const title = this.getName(id); - - const str = __("Mark all articles in %s as read?").replace("%s", title); - - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - - const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='" + id + "']"); - - if (rows.length > 0) { - - rows.each(function (row) { - row.removeClassName("Unread"); - - if (row.getAttribute("data-article-id") != Article.getActive()) { - new Effect.Fade(row, {duration: 0.5}); - } - - }); - - const feedTitles = $$("#headlines-frame > div[class='feed-title']"); - - for (let i = 0; i < feedTitles.length; i++) { - if (feedTitles[i].getAttribute("data-feed-id") == id) { - - if (i < feedTitles.length - 1) { - new Effect.Fade(feedTitles[i], {duration: 0.5}); - } - - break; - } - } - - Headlines.updateFloatingTitle(true); - } - - notify_progress("Loading, please wait...", true); - - xhrPost("backend.php", {op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => { - Utils.handleRpcJson(transport); - }); - } - }, - getUnread: function(feed, is_cat) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedUnread(feed, is_cat); - - } catch (e) { - // - } - - return -1; - }, - getCategory: function(feed) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.getFeedCategory(feed); - - } catch (e) { - // - } - - return false; - }, - getName: function(feed, is_cat) { - if (isNaN(feed)) return feed; // it's a tag - - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedValue(feed, is_cat, 'name'); - }, - setUnread: function(feed, is_cat, unread) { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.setFeedUnread(feed, is_cat, unread); - }, - setValue: function(feed, is_cat, key, value) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.setFeedValue(feed, is_cat, key, value); - - } catch (e) { - // - } - }, - getValue: function(feed, is_cat, key) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedValue(feed, is_cat, key); - - } catch (e) { - // - } - return ''; - }, - setIcon: function(feed, is_cat, src) { - const tree = dijit.byId("feedTree"); - - if (tree) return tree.setFeedIcon(feed, is_cat, src); - }, - setExpando: function(feed, is_cat, src) { - const tree = dijit.byId("feedTree"); - - if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); - - return false; - }, - getNextUnread: function(feed, is_cat) { - const tree = dijit.byId("feedTree"); - const nuf = tree.model.getNextUnreadFeed(feed, is_cat); - - if (nuf) - return tree.model.store.getValue(nuf, 'bare_id'); - }, - search: function() { - const query = "backend.php?op=feeds&method=search¶m=" + - param_escape(Feeds.getActive() + ":" + Feeds.activeIsCat()); - - if (dijit.byId("searchDlg")) - dijit.byId("searchDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "searchDlg", - title: __("Search"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - Feeds._search_query = this.attr('value'); - this.hide(); - Feeds.reloadCurrent(); - } - }, - href: query - }); - - dialog.show(); - }, - updateRandom: function() { - console.log("in update_random_feed"); - - xhrPost("backend.php", {op: "rpc", method: "updateRandom"}, (transport) => { - Utils.handleRpcJson(transport, true); - }); - }, -}; -- cgit v1.2.3