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