2018-12-01 14:05:28 +00:00
|
|
|
const Feeds = {
|
2018-12-01 15:03:58 +00:00
|
|
|
counters_last_request: 0,
|
2018-12-01 14:05:28 +00:00
|
|
|
_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;
|
|
|
|
}
|
2007-08-09 07:36:04 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
for (let i = 0; i < aProps.length; i++) {
|
|
|
|
const propName = aProps[i];
|
2008-05-19 16:55:57 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
// If values of same property are not equal,
|
|
|
|
// objects are not equivalent
|
|
|
|
if (a[propName] !== b[propName]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-02-04 08:57:31 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
// 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++) {
|
|
|
|
|
2018-12-01 14:54:16 +00:00
|
|
|
if (Feeds._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) {
|
2018-12-01 14:05:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-05-17 05:21:57 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-10-10 12:30:26 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (id == "subscribed-feeds") {
|
|
|
|
/* feeds_found = ctr; */
|
|
|
|
continue;
|
|
|
|
}
|
2007-08-09 07:36:04 +00:00
|
|
|
|
2018-12-01 14:23:44 +00:00
|
|
|
/*if (this.getFeedUnread(id, (kind == "cat")) != ctr ||
|
2018-12-01 14:05:28 +00:00
|
|
|
(kind == "cat")) {
|
|
|
|
}*/
|
2016-01-10 22:11:26 +00:00
|
|
|
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setFeedUnread(id, (kind == "cat"), ctr);
|
|
|
|
this.setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr);
|
2016-01-10 22:11:26 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (kind != "cat") {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setFeedValue(id, false, 'error', error);
|
|
|
|
this.setFeedValue(id, false, 'updated', updated);
|
2016-01-10 22:11:26 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (id > 0) {
|
|
|
|
if (has_img) {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setFeedIcon(id, false,
|
2018-12-01 14:05:28 +00:00
|
|
|
getInitParam("icons_url") + "/" + id + ".ico?" + has_img);
|
|
|
|
} else {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setFeedIcon(id, false, 'images/blank_icon.gif');
|
2018-12-01 14:05:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-14 15:30:49 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
|
|
|
this._counters_prev = elems;
|
|
|
|
},
|
|
|
|
viewCurrentFeed: function(method) {
|
|
|
|
console.log("viewCurrentFeed: " + method);
|
2007-01-19 09:38:16 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (this.getActiveFeedId() != undefined) {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.viewfeed({feed: this.getActiveFeedId(), is_cat: this.activeFeedIsCat(), method: method});
|
2018-12-01 14:05:28 +00:00
|
|
|
}
|
|
|
|
return false; // block unneeded form submits
|
|
|
|
},
|
|
|
|
openNextUnreadFeed: function() {
|
2018-12-01 14:23:44 +00:00
|
|
|
const is_cat = this.activeFeedIsCat();
|
|
|
|
const nuf = this.getNextUnreadFeed(this.getActiveFeedId(), is_cat);
|
2018-12-01 14:05:28 +00:00
|
|
|
if (nuf) this.viewfeed({feed: nuf, is_cat: is_cat});
|
|
|
|
},
|
|
|
|
collapseFeedlist: function() {
|
|
|
|
Element.toggle("feeds-holder");
|
2011-08-31 11:25:42 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
const splitter = $("feeds-holder_splitter");
|
2017-03-04 11:34:44 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
Element.visible("feeds-holder") ? splitter.show() : splitter.hide();
|
2007-08-28 05:05:45 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
dijit.byId("main").resize();
|
|
|
|
},
|
|
|
|
cancelSearch: function() {
|
|
|
|
this._search_query = "";
|
2018-12-01 14:23:44 +00:00
|
|
|
this.viewCurrentFeed();
|
2018-12-01 14:05:28 +00:00
|
|
|
},
|
|
|
|
requestCounters: function(force) {
|
|
|
|
const date = new Date();
|
|
|
|
const timestamp = Math.round(date.getTime() / 1000);
|
2007-06-19 13:03:47 +00:00
|
|
|
|
2018-12-01 15:03:58 +00:00
|
|
|
if (force || timestamp - this.counters_last_request > 5) {
|
2018-12-01 14:05:28 +00:00
|
|
|
console.log("scheduling request of counters...");
|
2006-05-21 04:28:51 +00:00
|
|
|
|
2018-12-01 15:03:58 +00:00
|
|
|
this.counters_last_request = timestamp;
|
2015-09-03 13:41:04 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()};
|
2015-07-11 22:29:36 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (!force)
|
|
|
|
query.last_article_id = getInitParam("last_article_id");
|
2006-05-21 12:09:55 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
xhrPost("backend.php", query, (transport) => {
|
2018-12-01 14:21:26 +00:00
|
|
|
Utils.handleRpcJson(transport);
|
2018-12-01 14:05:28 +00:00
|
|
|
});
|
2008-05-17 09:23:04 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
} else {
|
2018-12-01 15:03:58 +00:00
|
|
|
console.log("request_counters: rate limit reached: " + (timestamp - this.counters_last_request));
|
2018-12-01 09:36:28 +00:00
|
|
|
}
|
2018-12-01 14:05:28 +00:00
|
|
|
},
|
|
|
|
reload: function() {
|
|
|
|
try {
|
|
|
|
Element.show("feedlistLoading");
|
2011-08-31 11:25:42 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
this.resetCounters();
|
2011-08-31 11:25:42 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (dijit.byId("feedTree")) {
|
|
|
|
dijit.byId("feedTree").destroyRecursive();
|
|
|
|
}
|
2007-01-19 09:38:16 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
const store = new dojo.data.ItemFileWriteStore({
|
|
|
|
url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"
|
|
|
|
});
|
2006-09-28 12:00:03 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
const treeModel = new fox.FeedStoreModel({
|
|
|
|
store: store,
|
|
|
|
query: {
|
|
|
|
"type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
|
|
|
|
},
|
|
|
|
rootId: "root",
|
|
|
|
rootLabel: "Feeds",
|
|
|
|
childrenAttrs: ["items"]
|
|
|
|
});
|
2013-04-04 16:14:39 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
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);
|
2018-12-01 14:54:16 +00:00
|
|
|
Feeds.viewfeed({feed: feed, is_cat: is_cat});
|
2018-12-01 14:05:28 +00:00
|
|
|
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");
|
2015-08-12 11:09:46 +00:00
|
|
|
|
2018-12-01 09:36:28 +00:00
|
|
|
try {
|
2018-12-01 14:05:28 +00:00
|
|
|
Feeds.init();
|
2018-12-01 15:25:32 +00:00
|
|
|
Utils.setLoadingProgress(25);
|
2018-12-01 09:36:28 +00:00
|
|
|
} catch (e) {
|
|
|
|
exception_error(e);
|
|
|
|
}
|
|
|
|
});
|
2005-09-07 03:53:29 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
tree.startup();
|
|
|
|
} catch (e) {
|
|
|
|
exception_error(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
init: function() {
|
|
|
|
console.log("in feedlist init");
|
2011-03-18 09:55:45 +00:00
|
|
|
|
2018-12-01 15:25:32 +00:00
|
|
|
Utils.setLoadingProgress(50);
|
2013-05-02 05:48:38 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
document.onkeydown = App.hotkeyHandler;
|
2018-12-01 18:01:53 +00:00
|
|
|
window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000);
|
|
|
|
window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000);
|
2009-10-06 11:04:46 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (!this.getActiveFeedId()) {
|
|
|
|
this.viewfeed({feed: -3});
|
|
|
|
} else {
|
|
|
|
this.viewfeed({feed: this.getActiveFeedId(), is_cat: this.activeFeedIsCat()});
|
|
|
|
}
|
2006-11-22 10:11:41 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2017-12-03 17:46:27 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
dialog.show();
|
|
|
|
}
|
2017-12-03 17:46:27 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
// bw_limit disables timeout() so we request initial counters separately
|
|
|
|
if (getInitParam("bw_limit") == "1") {
|
|
|
|
this.requestCounters(true);
|
|
|
|
} else {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.requestCounters(true);
|
2018-12-01 18:01:53 +00:00
|
|
|
setInterval(() => { this.requestCounters(); }, 60 * 1000)
|
2018-12-01 14:05:28 +00:00
|
|
|
}, 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);
|
|
|
|
|
2018-12-01 18:01:53 +00:00
|
|
|
PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, [this._active_feed_id, this._active_feed_is_cat]);
|
2018-12-01 14:05:28 +00:00
|
|
|
},
|
|
|
|
selectFeed: function(feed, is_cat) {
|
|
|
|
const tree = dijit.byId("feedTree");
|
2007-11-21 07:08:25 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (tree) return tree.selectFeed(feed, is_cat);
|
|
|
|
},
|
|
|
|
toggleDispRead: function() {
|
|
|
|
const hide = !(getInitParam("hide_read_feeds") == "1");
|
2008-05-20 15:59:42 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
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");
|
2010-11-10 11:48:35 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
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;
|
|
|
|
|
2018-12-01 14:23:44 +00:00
|
|
|
if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) {
|
2018-12-01 14:05:28 +00:00
|
|
|
this._search_query = false;
|
2018-12-01 18:01:53 +00:00
|
|
|
Article.setActiveArticleId(0);
|
2018-12-01 14:05:28 +00:00
|
|
|
}
|
2013-02-01 09:09:43 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (offset != 0) {
|
|
|
|
if (this.infscroll_in_progress)
|
|
|
|
return;
|
2013-02-01 09:09:43 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
this.infscroll_in_progress = 1;
|
2013-02-01 09:09:43 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
window.clearTimeout(this._infscroll_timeout);
|
|
|
|
this._infscroll_timeout = window.setTimeout(() => {
|
|
|
|
console.log('infscroll request timed out, aborting');
|
|
|
|
this.infscroll_in_progress = 0;
|
2013-02-01 09:09:43 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
// call scroll handler to maybe repeat infscroll request
|
|
|
|
Headlines.scrollHandler();
|
|
|
|
}, 10 * 1000);
|
|
|
|
}
|
2008-05-20 15:59:42 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
Form.enable("main_toolbar_form");
|
2009-02-03 19:33:52 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
let query = Object.assign({op: "feeds", method: "view", feed: feed},
|
|
|
|
dojo.formToObject("main_toolbar_form"));
|
2017-01-22 16:38:07 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (method) query.m = method;
|
2017-01-22 16:38:07 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (offset > 0) {
|
2018-12-01 18:01:53 +00:00
|
|
|
if (Headlines.current_first_id) {
|
|
|
|
query.fid = Headlines.current_first_id;
|
2018-12-01 14:05:28 +00:00
|
|
|
}
|
2017-01-22 16:38:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (this._search_query) {
|
|
|
|
query = Object.assign(query, this._search_query);
|
|
|
|
}
|
2017-01-22 16:38:07 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (offset != 0) {
|
|
|
|
query.skip = offset;
|
2010-11-12 10:52:53 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
// to prevent duplicate feed titles when showing grouped vfeeds
|
2018-12-01 18:01:53 +00:00
|
|
|
if (Headlines.vgroup_last_feed != undefined) {
|
|
|
|
query.vgrlf = Headlines.vgroup_last_feed;
|
2018-12-01 14:05:28 +00:00
|
|
|
}
|
2018-12-01 14:23:44 +00:00
|
|
|
} else if (!is_cat && feed == this.getActiveFeedId() && !params.method) {
|
2018-12-01 14:05:28 +00:00
|
|
|
query.m = "ForceUpdate";
|
2017-03-04 11:34:44 +00:00
|
|
|
}
|
2017-01-22 16:29:14 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
Form.enable("main_toolbar_form");
|
|
|
|
|
|
|
|
if (!delayed)
|
2018-12-01 14:23:44 +00:00
|
|
|
if (!this.setFeedExpandoIcon(feed, is_cat,
|
2018-12-01 14:05:28 +00:00
|
|
|
(is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif'))
|
|
|
|
notify_progress("Loading, please wait...", true);
|
|
|
|
|
|
|
|
query.cat = is_cat;
|
|
|
|
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setActiveFeedId(feed, is_cat);
|
2018-12-01 14:05:28 +00:00
|
|
|
|
|
|
|
if (viewfeed_debug) {
|
|
|
|
window.open("backend.php?" +
|
|
|
|
dojo.objectToQuery(
|
|
|
|
Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query)
|
|
|
|
));
|
2017-03-04 11:34:44 +00:00
|
|
|
}
|
2010-11-15 13:23:42 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
window.clearTimeout(this._viewfeed_wait_timeout);
|
|
|
|
this._viewfeed_wait_timeout = window.setTimeout(() => {
|
2018-12-01 18:01:53 +00:00
|
|
|
Headlines.catchupBatchedArticles(() => {
|
2018-12-01 14:05:28 +00:00
|
|
|
xhrPost("backend.php", query, (transport) => {
|
|
|
|
try {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
|
2018-12-01 14:05:28 +00:00
|
|
|
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();
|
2017-03-04 11:34:44 +00:00
|
|
|
}
|
2018-12-01 14:05:28 +00:00
|
|
|
},
|
|
|
|
decrementFeedCounter: function(feed, is_cat) {
|
2018-12-01 14:23:44 +00:00
|
|
|
let ctr = this.getFeedUnread(feed, is_cat);
|
2011-08-31 10:03:52 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (ctr > 0) {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setFeedUnread(feed, is_cat, ctr - 1);
|
2018-12-01 14:05:28 +00:00
|
|
|
App.global_unread -= 1;
|
|
|
|
App.updateTitle();
|
2010-11-12 10:52:53 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (!is_cat) {
|
2018-12-01 14:23:44 +00:00
|
|
|
const cat = parseInt(this.getFeedCategory(feed));
|
2010-11-16 06:49:00 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (!isNaN(cat)) {
|
2018-12-01 14:23:44 +00:00
|
|
|
ctr = this.getFeedUnread(cat, true);
|
2017-03-04 11:34:44 +00:00
|
|
|
|
2018-12-01 14:05:28 +00:00
|
|
|
if (ctr > 0) {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.setFeedUnread(cat, true, ctr - 1);
|
2018-12-01 14:05:28 +00:00
|
|
|
}
|
2010-11-16 06:49:00 +00:00
|
|
|
}
|
2010-11-12 10:52:53 +00:00
|
|
|
}
|
2010-11-15 18:49:00 +00:00
|
|
|
}
|
2018-12-01 14:21:26 +00:00
|
|
|
},
|
|
|
|
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?");
|
|
|
|
}
|
2011-03-18 09:55:45 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles");
|
2018-12-01 14:23:44 +00:00
|
|
|
const fn = this.getFeedName(feed, is_cat);
|
2010-11-12 10:52:53 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
str = str.replace("%s", fn)
|
|
|
|
.replace("%w", mark_what);
|
2010-11-18 13:00:00 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-15 18:49:00 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
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]
|
|
|
|
};
|
2010-11-15 13:23:42 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
notify_progress("Loading, please wait...", true);
|
2009-02-04 06:51:31 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
xhrPost("backend.php", catchup_query, (transport) => {
|
|
|
|
Utils.handleRpcJson(transport);
|
2010-11-15 18:49:00 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
|
2010-11-16 06:49:00 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (show_next_feed) {
|
2018-12-01 14:23:44 +00:00
|
|
|
const nuf = this.getNextUnreadFeed(feed, is_cat);
|
2010-11-16 09:23:06 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (nuf) {
|
|
|
|
this.viewfeed({feed: nuf, is_cat: is_cat});
|
|
|
|
}
|
2018-12-01 14:23:44 +00:00
|
|
|
} else if (feed == this.getActiveFeedId() && is_cat == this.activeFeedIsCat()) {
|
2018-12-01 14:21:26 +00:00
|
|
|
this.viewCurrentFeed();
|
|
|
|
}
|
2010-11-16 09:23:06 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
notify("");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
catchupCurrentFeed: function(mode) {
|
2018-12-01 14:23:44 +00:00
|
|
|
this.catchupFeed(this.getActiveFeedId(), this.activeFeedIsCat(), mode);
|
2018-12-01 14:21:26 +00:00
|
|
|
},
|
|
|
|
catchupFeedInGroup: function(id) {
|
2018-12-01 14:23:44 +00:00
|
|
|
const title = this.getFeedName(id);
|
2010-11-16 09:23:06 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
const str = __("Mark all articles in %s as read?").replace("%s", title);
|
2011-08-31 11:25:42 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
|
2011-08-31 11:25:42 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='" + id + "']");
|
2011-08-31 11:25:42 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (rows.length > 0) {
|
2012-03-29 11:03:48 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
rows.each(function (row) {
|
|
|
|
row.removeClassName("Unread");
|
2012-03-29 11:03:48 +00:00
|
|
|
|
2018-12-01 18:01:53 +00:00
|
|
|
if (row.getAttribute("data-article-id") != Article.getActiveArticleId()) {
|
2018-12-01 14:21:26 +00:00
|
|
|
new Effect.Fade(row, {duration: 0.5});
|
|
|
|
}
|
2012-03-29 11:03:48 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
});
|
2016-03-21 18:40:40 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
const feedTitles = $$("#headlines-frame > div[class='feed-title']");
|
2016-03-21 18:40:40 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
for (let i = 0; i < feedTitles.length; i++) {
|
|
|
|
if (feedTitles[i].getAttribute("data-feed-id") == id) {
|
2016-03-21 18:40:40 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (i < feedTitles.length - 1) {
|
|
|
|
new Effect.Fade(feedTitles[i], {duration: 0.5});
|
|
|
|
}
|
2016-03-22 20:22:28 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-04 11:34:44 +00:00
|
|
|
}
|
2016-03-21 18:40:40 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
Headlines.updateFloatingTitle(true);
|
|
|
|
}
|
2016-03-22 20:22:28 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
notify_progress("Loading, please wait...", true);
|
2016-03-22 20:22:28 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
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");
|
2016-03-22 20:22:28 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (tree && tree.model)
|
|
|
|
return tree.model.getFeedUnread(feed, is_cat);
|
2016-03-21 18:40:40 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
//
|
2017-03-04 11:34:44 +00:00
|
|
|
}
|
2016-03-21 18:40:40 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
getFeedCategory: function(feed) {
|
|
|
|
try {
|
|
|
|
const tree = dijit.byId("feedTree");
|
2016-03-21 18:40:40 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (tree && tree.model)
|
|
|
|
return tree.getFeedCategory(feed);
|
2013-03-31 08:37:42 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
//
|
|
|
|
}
|
2011-11-11 11:35:29 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
getFeedName: function(feed, is_cat) {
|
|
|
|
if (isNaN(feed)) return feed; // it's a tag
|
2011-11-11 11:35:29 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
const tree = dijit.byId("feedTree");
|
2011-11-11 11:28:11 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (tree && tree.model)
|
|
|
|
return tree.model.getFeedValue(feed, is_cat, 'name');
|
|
|
|
},
|
|
|
|
setFeedUnread: function(feed, is_cat, unread) {
|
|
|
|
const tree = dijit.byId("feedTree");
|
2012-06-03 16:02:51 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
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");
|
2011-11-11 11:28:11 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (tree && tree.model)
|
|
|
|
return tree.model.setFeedValue(feed, is_cat, key, value);
|
2012-03-29 11:03:48 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getFeedValue: function(feed, is_cat, key) {
|
|
|
|
try {
|
|
|
|
const tree = dijit.byId("feedTree");
|
2012-03-29 11:03:48 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (tree && tree.model)
|
|
|
|
return tree.model.getFeedValue(feed, is_cat, key);
|
2012-03-29 11:03:48 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
//
|
2018-11-30 12:07:44 +00:00
|
|
|
}
|
2018-12-01 14:21:26 +00:00
|
|
|
return '';
|
|
|
|
},
|
|
|
|
setFeedIcon: function(feed, is_cat, src) {
|
|
|
|
const tree = dijit.byId("feedTree");
|
2011-11-11 11:28:11 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (tree) return tree.setFeedIcon(feed, is_cat, src);
|
|
|
|
},
|
|
|
|
setFeedExpandoIcon: function(feed, is_cat, src) {
|
|
|
|
const tree = dijit.byId("feedTree");
|
2012-04-05 07:58:50 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
|
2013-03-26 12:31:36 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
getNextUnreadFeed: function(feed, is_cat) {
|
|
|
|
const tree = dijit.byId("feedTree");
|
|
|
|
const nuf = tree.model.getNextUnreadFeed(feed, is_cat);
|
2013-03-26 12:31:36 +00:00
|
|
|
|
2018-12-01 14:21:26 +00:00
|
|
|
if (nuf)
|
|
|
|
return tree.model.store.getValue(nuf, 'bare_id');
|
2018-12-01 15:25:32 +00:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
},
|
2018-12-01 14:21:26 +00:00
|
|
|
};
|