]> git.wh0rd.org - tt-rss.git/blame - js/feedlist.js
fix missing cdmFeedTitle
[tt-rss.git] / js / feedlist.js
CommitLineData
29dfb258 1var _infscroll_disable = 0;
82764a41 2var _infscroll_request_sent = 0;
973fe3c6 3var _search_query = false;
4d5eed55 4var _viewfeed_last = 0;
a95e14fb 5var _viewfeed_timeout = false;
ac541432 6
9922d56b 7var counters_last_request = 0;
91cdbe52 8
ff2c6e6a 9function viewCategory(cat) {
767e2486 10 viewfeed(cat, '', true);
0c3d1219 11 return false;
ff2c6e6a
AD
12}
13
71317973 14function loadMoreHeadlines() {
ac541432 15 try {
d36d86b9
AD
16 console.log("loadMoreHeadlines");
17
71317973
AD
18 var offset = 0;
19
20 var view_mode = document.forms["main_toolbar_form"].view_mode.value;
3d2c9f5a 21 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
71317973 22 var num_all = $$("#headlines-frame > div[id*=RROW]").length;
fe0a51ac 23 var num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat());
71317973
AD
24
25 // TODO implement marked & published
26
27 if (view_mode == "marked") {
28 console.warn("loadMoreHeadlines: marked is not implemented, falling back.");
29 offset = num_all;
30 } else if (view_mode == "published") {
31 console.warn("loadMoreHeadlines: published is not implemented, falling back.");
32 offset = num_all;
33 } else if (view_mode == "unread") {
455e774a 34 offset = unread_in_buffer;
c67cd7ab
AD
35 } else if (_search_query) {
36 offset = num_all;
71317973 37 } else if (view_mode == "adaptive") {
07734eee 38 offset = num_unread > 0 ? unread_in_buffer : num_all;
71317973
AD
39 } else {
40 offset = num_all;
41 }
2a8534a0 42
c67cd7ab
AD
43 console.log("offset: " + offset);
44
28364067 45 viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true);
ac541432
AD
46
47 } catch (e) {
8b365031 48 exception_error("viewNextFeedPage", e);
ac541432
AD
49 }
50}
51
6a2034f9 52
a95e14fb 53function viewfeed(feed, method, is_cat, offset, background, infscroll_req, can_wait) {
7719618b 54 try {
78b2c6ce
AD
55 if (is_cat == undefined)
56 is_cat = false;
57 else
58 is_cat = !!is_cat;
59
f30ef1fa 60 if (method == undefined) method = '';
71317973 61 if (offset == undefined) offset = 0;
37c03d3a 62 if (background == undefined) background = false;
77c3c5f9 63 if (infscroll_req == undefined) infscroll_req = false;
c50e2b30 64
32f0c8b0
AD
65 last_requested_article = 0;
66
2bee32ff 67 if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) {
1e07a58a 68 if (!background && _search_query) _search_query = false;
61834616
AD
69 }
70
37c03d3a 71 if (!background) {
4d5eed55
AD
72 _viewfeed_last = get_timestamp();
73
37c03d3a 74 if (getActiveFeedId() != feed || offset == 0) {
18e1a773 75 setActiveArticleId(0);
37c03d3a
AD
76 _infscroll_disable = 0;
77 }
203de776 78
f30ef1fa 79 if (offset != 0 && !method) {
4d5eed55 80 var timestamp = get_timestamp();
82764a41 81
37c03d3a
AD
82 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
83 //console.log("infscroll request in progress, aborting");
84 return;
85 }
86
87 _infscroll_request_sent = timestamp;
82764a41 88 }
82764a41
AD
89 }
90
fd98576c
AD
91 Form.enable("main_toolbar_form");
92
fd98576c 93 var toolbar_query = Form.serialize("main_toolbar_form");
86b682ce 94
d9e78984 95 var query = "?op=feeds&method=view&feed=" + param_escape(feed) + "&" +
c0c2abba
AD
96 toolbar_query;
97
98 if (method) {
99 query = query + "&m=" + param_escape(method);
100 }
37c03d3a 101
15ae8cd0 102 if (offset > 0) {
48fefe2f
AD
103 if (current_first_id) {
104 query = query + "&fid=" + param_escape(current_first_id);
15ae8cd0 105 }
f5a0fb8b
AD
106 }
107
37c03d3a
AD
108 if (!background) {
109 if (_search_query) {
52d7e7da 110 force_nocache = true;
37c03d3a 111 query = query + "&" + _search_query;
c67cd7ab 112 //_search_query = false;
52d7e7da 113 }
164f4738 114
37c03d3a
AD
115 if (offset != 0) {
116 query = query + "&skip=" + offset;
60d4df4d 117
37c03d3a
AD
118 // to prevent duplicate feed titles when showing grouped vfeeds
119 if (vgroup_last_feed) {
120 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
121 }
c0c2abba
AD
122 } else {
123 if (!method && !is_cat && feed == getActiveFeedId()) {
124 query = query + "&m=ForceUpdate";
125 }
60d4df4d 126 }
37c03d3a
AD
127
128 Form.enable("main_toolbar_form");
129
d5a8e864
AD
130 if (!setFeedExpandoIcon(feed, is_cat,
131 (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif'))
37c03d3a 132 notify_progress("Loading, please wait...", true);
203de776
AD
133 }
134
37c03d3a 135 query += "&cat=" + is_cat;
6b4163cb 136
84c7b824 137 console.log(query);
081e527d 138
a95e14fb
MH
139 if (can_wait && _viewfeed_timeout) {
140 setFeedExpandoIcon(getActiveFeedId(), activeFeedIsCat(), 'images/blank_icon.gif');
141 clearTimeout(_viewfeed_timeout);
142 }
143
ba1c7d7c
AD
144 setActiveFeedId(feed, is_cat);
145
a95e14fb
MH
146 timeout_ms = can_wait ? 250 : 0;
147 _viewfeed_timeout = setTimeout(function() {
148
149 new Ajax.Request("backend.php", {
150 parameters: query,
151 onComplete: function(transport) {
152 setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
153 headlines_callback2(transport, offset, background, infscroll_req);
154 PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]);
155 } });
156 }, timeout_ms); // Wait 250ms
6b4163cb 157
7719618b
AD
158 } catch (e) {
159 exception_error("viewfeed", e);
bd202c3f 160 }
1a66d16e
AD
161}
162
6b4163cb 163function feedlist_init() {
1b0809ae 164 try {
fcf70c51 165 console.log("in feedlist init");
bd202c3f 166
ea18ccea
AD
167 loading_set_progress(50);
168
1b0809ae 169 document.onkeydown = hotkey_handler;
164469f9
AD
170 setTimeout("hotkey_prefix_timeout()", 5*1000);
171
1b04a298
AD
172 if (!getActiveFeedId()) {
173 viewfeed(-3);
174 } else {
175 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
176 }
7086277c 177
a73e6b97 178 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
782ddd70 179
5b55e9e2
AD
180 request_counters(true);
181 timeout();
cd1bb36d 182
1b0809ae 183 } catch (e) {
bbf4d0b2 184 exception_error("feedlist/init", e);
1b0809ae 185 }
3745788e 186}
22e06406 187
997d9d7c 188
5b55e9e2 189function request_counters(force) {
997d9d7c 190 try {
997d9d7c
AD
191 var date = new Date();
192 var timestamp = Math.round(date.getTime() / 1000);
193
5129d29d 194 if (force || timestamp - counters_last_request > 5) {
84c7b824 195 console.log("scheduling request of counters...");
5225d420 196
997d9d7c 197 counters_last_request = timestamp;
5b55e9e2
AD
198
199 var query = "?op=rpc&method=getAllCounters&seq=" + next_seq();
200
0a7b1520 201 if (!force)
5b55e9e2
AD
202 query = query + "&last_article_id=" + getInitParam("last_article_id");
203
204 console.log(query);
205
206 new Ajax.Request("backend.php", {
207 parameters: query,
208 onComplete: function(transport) {
209 try {
210 handle_rpc_json(transport);
211 } catch (e) {
212 exception_error("request_counters", e);
213 }
214 } });
215
997d9d7c 216 } else {
84c7b824 217 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
f55b0b12 218 }
997d9d7c 219
5aaf9b34
AD
220 } catch (e) {
221 exception_error("request_counters", e);
222 }
223}
a4b906ec 224
563b9c78 225function parse_counters(elems, scheduled_call) {
e69fb880 226 try {
e69fb880
AD
227 for (var l = 0; l < elems.length; l++) {
228
e331188f 229 var id = elems[l].id;
e69fb880 230 var kind = elems[l].kind;
e331188f 231 var ctr = parseInt(elems[l].counter);
e69fb880
AD
232 var error = elems[l].error;
233 var has_img = elems[l].has_img;
234 var updated = elems[l].updated;
c594eca0 235 var auxctr = parseInt(elems[l].auxcounter);
563b9c78 236
e69fb880 237 if (id == "global-unread") {
e69fb880
AD
238 global_unread = ctr;
239 updateTitle();
240 continue;
241 }
242
243 if (id == "subscribed-feeds") {
244 feeds_found = ctr;
245 continue;
246 }
13e785e0 247
183ca8b9 248 if (getFeedUnread(id, (kind == "cat")) != ctr ||
0ef32f48 249 (kind == "cat")) {
183ca8b9 250 }
78b2c6ce 251
13e785e0 252 setFeedUnread(id, (kind == "cat"), ctr);
c594eca0 253 setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr);
e69fb880 254
fcf70c51 255 if (kind != "cat") {
700f1426 256 setFeedValue(id, false, 'error', error);
fcf70c51 257 setFeedValue(id, false, 'updated', updated);
2ef5c21f
AD
258
259 if (id > 0) {
260 if (has_img) {
bd202c3f 261 setFeedIcon(id, false,
2ef5c21f
AD
262 getInitParam("icons_url") + "/" + id + ".ico");
263 } else {
264 setFeedIcon(id, false, 'images/blank_icon.gif');
265 }
266 }
e69fb880 267 }
fcf70c51 268 }
bd202c3f 269
e69fb880
AD
270 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
271
e69fb880
AD
272 } catch (e) {
273 exception_error("parse_counters", e);
274 }
275}
276
6e88da82 277function getFeedUnread(feed, is_cat) {
e69fb880 278 try {
e032e2e7
AD
279 var tree = dijit.byId("feedTree");
280
bd202c3f 281 if (tree && tree.model)
e032e2e7
AD
282 return tree.model.getFeedUnread(feed, is_cat);
283
e69fb880 284 } catch (e) {
fcf70c51 285 //
e69fb880 286 }
fcf70c51
AD
287
288 return -1;
e69fb880
AD
289}
290
6c8e8fbd
AD
291function getFeedCategory(feed) {
292 try {
293 var tree = dijit.byId("feedTree");
294
295 if (tree && tree.model)
296 return tree.getFeedCategory(feed);
297
298 } catch (e) {
299 //
300 }
301
302 return false;
303}
304
e69fb880 305function hideOrShowFeeds(hide) {
fcf70c51
AD
306 var tree = dijit.byId("feedTree");
307
05f224a3
AD
308 if (tree)
309 return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
e69fb880
AD
310}
311
bd202c3f 312function getFeedName(feed, is_cat) {
e032e2e7
AD
313 var tree = dijit.byId("feedTree");
314
bd202c3f 315 if (tree && tree.model)
e032e2e7 316 return tree.model.getFeedValue(feed, is_cat, 'name');
fcf70c51 317}
e69fb880 318
bd202c3f 319function getFeedValue(feed, is_cat, key) {
fcf70c51 320 try {
e032e2e7 321 var tree = dijit.byId("feedTree");
fcf70c51 322
bd202c3f 323 if (tree && tree.model)
e032e2e7 324 return tree.model.getFeedValue(feed, is_cat, key);
bd202c3f 325
fcf70c51
AD
326 } catch (e) {
327 //
e69fb880 328 }
fcf70c51 329 return '';
e69fb880
AD
330}
331
13e785e0
AD
332function setFeedUnread(feed, is_cat, unread) {
333 try {
e032e2e7
AD
334 var tree = dijit.byId("feedTree");
335
bd202c3f 336 if (tree && tree.model)
e032e2e7
AD
337 return tree.model.setFeedUnread(feed, is_cat, unread);
338
fcf70c51
AD
339 } catch (e) {
340 exception_error("setFeedUnread", e);
341 }
342}
343
344function setFeedValue(feed, is_cat, key, value) {
345 try {
e032e2e7 346 var tree = dijit.byId("feedTree");
13e785e0 347
bd202c3f 348 if (tree && tree.model)
e032e2e7 349 return tree.model.setFeedValue(feed, is_cat, key, value);
c8a9fe5b 350
13e785e0 351 } catch (e) {
e032e2e7 352 //
fcf70c51
AD
353 }
354}
355
fcf70c51
AD
356function selectFeed(feed, is_cat) {
357 try {
358 var tree = dijit.byId("feedTree");
359
e032e2e7 360 if (tree) return tree.selectFeed(feed, is_cat);
fcf70c51
AD
361
362 } catch (e) {
363 exception_error("selectFeed", e);
13e785e0
AD
364 }
365}
2ef5c21f
AD
366
367function setFeedIcon(feed, is_cat, src) {
368 try {
369 var tree = dijit.byId("feedTree");
370
e032e2e7 371 if (tree) return tree.setFeedIcon(feed, is_cat, src);
2ef5c21f
AD
372
373 } catch (e) {
374 exception_error("setFeedIcon", e);
375 }
376}
9c99281f
AD
377
378function setFeedExpandoIcon(feed, is_cat, src) {
379 try {
380 var tree = dijit.byId("feedTree");
381
e032e2e7 382 if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
9c99281f
AD
383
384 } catch (e) {
385 exception_error("setFeedIcon", e);
386 }
f92d7c2b 387 return false;
9c99281f 388}
37c03d3a
AD
389
390function getNextUnreadFeed(feed, is_cat) {
391 try {
392 var tree = dijit.byId("feedTree");
393 var nuf = tree.model.getNextUnreadFeed(feed, is_cat);
394
395 if (nuf)
396 return tree.model.store.getValue(nuf, 'bare_id');
397
398 } catch (e) {
399 exception_error("getNextUnreadFeed", e);
400 }
401}
402
e3ca32a8
AD
403function catchupCurrentFeed(mode) {
404 catchupFeed(getActiveFeedId(), activeFeedIsCat(), mode);
44245618
AD
405}
406
407function catchupFeedInGroup(id) {
408 try {
409
410 var title = getFeedName(id);
411
412 var str = __("Mark all articles in %s as read?").replace("%s", title);
413
414 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
415 return viewCurrentFeed('MarkAllReadGR:' + id);
416 }
417
418 } catch (e) {
419 exception_error("catchupFeedInGroup", e);
420 }
421}
422
c8b693cf 423function catchupFeed(feed, is_cat, mode) {
e3d2c029 424 try {
184f5195
AD
425 if (is_cat == undefined) is_cat = false;
426
c8b693cf
AD
427 var str = false;
428
429 switch (mode) {
430 case "1day":
431 str = __("Mark all articles in %s older than 1 day as read?");
432 break;
433 case "1week":
434 str = __("Mark all articles in %s older than 1 week as read?");
435 break;
7b32ee7e 436 case "2week":
c8b693cf
AD
437 str = __("Mark all articles in %s older than 2 weeks as read?");
438 break;
439 default:
440 str = __("Mark all articles in %s as read?");
441 }
442
9dd22f1e 443 var fn = getFeedName(feed, is_cat);
a593cb62
AD
444
445 str = str.replace("%s", fn);
446
447 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
448 return;
449 }
e3d2c029 450
f30ef1fa 451 var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" +
c8b693cf 452 feed + "&is_cat=" + is_cat + "&mode=" + mode;
184f5195
AD
453
454 console.log(catchup_query);
e3d2c029
AD
455
456 notify_progress("Loading, please wait...", true);
457
458 new Ajax.Request("backend.php", {
459 parameters: catchup_query,
460 onComplete: function(transport) {
461 handle_rpc_json(transport);
44245618 462
44245618
AD
463 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
464
465 if (show_next_feed) {
466 var nuf = getNextUnreadFeed(feed, is_cat);
467
468 if (nuf) {
c86bf88d 469 viewfeed(nuf, '', is_cat);
44245618 470 }
c8b693cf
AD
471 } else {
472 if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) {
473 viewCurrentFeed();
474 }
44245618
AD
475 }
476
e3d2c029
AD
477 notify("");
478 } });
479
480 } catch (e) {
481 exception_error("catchupFeed", e);
482 }
483}
de44b9a6
AD
484
485function decrementFeedCounter(feed, is_cat) {
486 try {
487 var ctr = getFeedUnread(feed, is_cat);
488
489 if (ctr > 0) {
490 setFeedUnread(feed, is_cat, ctr - 1);
5b55e9e2
AD
491 global_unread = global_unread - 1;
492 updateTitle();
de44b9a6
AD
493
494 if (!is_cat) {
495 var cat = parseInt(getFeedCategory(feed));
496
497 if (!isNaN(cat)) {
498 ctr = getFeedUnread(cat, true);
499
500 if (ctr > 0) {
501 setFeedUnread(cat, true, ctr - 1);
502 }
503 }
504 }
505 }
506
507 } catch (e) {
508 exception_error("decrement_feed_counter", e);
509 }
510}
2196b517
AD
511
512