]> git.wh0rd.org - tt-rss.git/blame - feedlist.js
trigger loadMoreHeadlines in view() when rendering local article only
[tt-rss.git] / feedlist.js
CommitLineData
29dfb258 1var _infscroll_disable = 0;
82764a41 2var _infscroll_request_sent = 0;
973fe3c6 3var _search_query = false;
ac541432 4
5225d420
AD
5var counter_timeout_id = false;
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 {
71317973
AD
16 var offset = 0;
17
18 var view_mode = document.forms["main_toolbar_form"].view_mode.value;
19 var num_unread = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
20 var num_all = $$("#headlines-frame > div[id*=RROW]").length;
21
22 // TODO implement marked & published
23
24 if (view_mode == "marked") {
25 console.warn("loadMoreHeadlines: marked is not implemented, falling back.");
26 offset = num_all;
27 } else if (view_mode == "published") {
28 console.warn("loadMoreHeadlines: published is not implemented, falling back.");
29 offset = num_all;
30 } else if (view_mode == "unread") {
31 offset = num_unread;
32 } else if (view_mode == "adaptive") {
33 if (num_unread > 0)
34 offset = num_unread;
35 else
36 offset = num_all;
37 } else {
38 offset = num_all;
39 }
2a8534a0 40
71317973 41 viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset);
ac541432
AD
42
43 } catch (e) {
8b365031 44 exception_error("viewNextFeedPage", e);
ac541432
AD
45 }
46}
47
6a2034f9 48
37c03d3a 49function viewfeed(feed, subop, is_cat, offset, background) {
7719618b 50 try {
78b2c6ce
AD
51 if (is_cat == undefined)
52 is_cat = false;
53 else
54 is_cat = !!is_cat;
55
cd1bb36d 56 if (subop == undefined) subop = '';
71317973 57 if (offset == undefined) offset = 0;
37c03d3a 58 if (background == undefined) background = false;
c50e2b30 59
32f0c8b0
AD
60 last_requested_article = 0;
61
78b2c6ce
AD
62 var cached_headlines = false;
63
64 if (feed == getActiveFeedId())
65 cache_delete("feed:" + feed + ":" + is_cat);
66 else
67 cached_headlines = cache_get("feed:" + feed + ":" + is_cat);
b8e6acea 68
f92d7c2b
AD
69 dijit.byId("content-tabs").selectChild(
70 dijit.byId("content-tabs").getChildren()[0]);
71
52d7e7da
AD
72 var force_nocache = false;
73
37c03d3a
AD
74 if (!background) {
75 if (getActiveFeedId() != feed || offset == 0) {
76 active_post_id = 0;
77 _infscroll_disable = 0;
78 }
203de776 79
37c03d3a
AD
80 if (!offset && !subop && cached_headlines && !background) {
81 try {
82 render_local_headlines(feed, is_cat, JSON.parse(cached_headlines));
83 return;
84 } catch (e) {
85 console.warn("render_local_headlines failed: " + e);
86 }
78b2c6ce 87 }
78b2c6ce 88
37c03d3a
AD
89 if (offset != 0 && !subop) {
90 var date = new Date();
91 var timestamp = Math.round(date.getTime() / 1000);
82764a41 92
37c03d3a
AD
93 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
94 //console.log("infscroll request in progress, aborting");
95 return;
96 }
97
98 _infscroll_request_sent = timestamp;
82764a41
AD
99 }
100
37c03d3a 101 hideAuxDlg();
82764a41
AD
102 }
103
fd98576c
AD
104 Form.enable("main_toolbar_form");
105
fd98576c 106 var toolbar_query = Form.serialize("main_toolbar_form");
86b682ce 107
37c03d3a
AD
108 var query = "?op=viewfeed&feed=" + feed + "&" +
109 toolbar_query + "&subop=" + param_escape(subop);
110
111 if (!background) {
112 if (_search_query) {
52d7e7da 113 force_nocache = true;
37c03d3a
AD
114 query = query + "&" + _search_query;
115 _search_query = false;
52d7e7da 116 }
164f4738 117
37c03d3a 118 if (subop == "MarkAllRead") {
86b682ce 119
37c03d3a 120 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
86b682ce 121
37c03d3a
AD
122 if (show_next_feed) {
123 var nuf = getNextUnreadFeed(feed, is_cat);
e0998414 124
37c03d3a
AD
125 if (nuf) {
126 var cached_nuf = cache_get("feed:" + nuf + ":false");
3ac2b520 127
37c03d3a 128 if (cached_nuf) {
692de159 129
37c03d3a 130 render_local_headlines(nuf, false, JSON.parse(cached_nuf));
692de159 131
37c03d3a
AD
132 var catchup_query = "?op=rpc&subop=catchupFeed&feed_id=" +
133 feed + "&is_cat=" + is_cat;
134
135 console.log(catchup_query);
136
137 new Ajax.Request("backend.php", {
138 parameters: catchup_query,
139 onComplete: function(transport) {
140 handle_rpc_json(transport);
141 } });
142
143 return;
144 } else {
145 query += "&nuf=" + param_escape(nuf);
146 }
147 }
692de159 148 }
e0998414 149 }
ff2c6e6a 150
37c03d3a
AD
151 if (offset != 0) {
152 query = query + "&skip=" + offset;
60d4df4d 153
37c03d3a
AD
154 // to prevent duplicate feed titles when showing grouped vfeeds
155 if (vgroup_last_feed) {
156 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
157 }
60d4df4d 158 }
37c03d3a
AD
159
160 Form.enable("main_toolbar_form");
161
162 if (!offset)
163 if (!is_cat) {
164 if (!setFeedExpandoIcon(feed, is_cat, 'images/indicator_white.gif'))
165 notify_progress("Loading, please wait...", true);
166 } else {
167 notify_progress("Loading, please wait...", true);
168 }
203de776
AD
169 }
170
37c03d3a 171 query += "&cat=" + is_cat;
6b4163cb 172
84c7b824 173 console.log(query);
081e527d 174
71317973
AD
175 new Ajax.Request("backend.php", {
176 parameters: query,
177 onComplete: function(transport) {
178 setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
37c03d3a 179 headlines_callback2(transport, offset, background);
71317973 180 } });
6b4163cb 181
7719618b
AD
182 } catch (e) {
183 exception_error("viewfeed", e);
bd202c3f 184 }
1a66d16e
AD
185}
186
6b4163cb 187function feedlist_init() {
1b0809ae 188 try {
fcf70c51 189 console.log("in feedlist init");
bd202c3f 190
60ea2377 191 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1b0809ae 192 document.onkeydown = hotkey_handler;
164469f9
AD
193 setTimeout("hotkey_prefix_timeout()", 5*1000);
194
6e88da82 195 if (!getActiveFeedId()) {
bd202c3f
AD
196 setTimeout("viewfeed(-3)", 100);
197 }
fcf70c51 198
bd202c3f 199 console.log("T:" +
6e88da82 200 getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3));
7086277c 201
a73e6b97 202 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
782ddd70 203
cd1bb36d 204 setTimeout("timeout()", 5000);
452e75cc 205 setTimeout("precache_headlines_idle()", 3000);
cd1bb36d 206
1b0809ae 207 } catch (e) {
bbf4d0b2 208 exception_error("feedlist/init", e);
1b0809ae 209 }
3745788e 210}
22e06406 211
997d9d7c 212function request_counters_real() {
5aaf9b34 213 try {
84c7b824 214 console.log("requesting counters...");
06c88b8d 215
6237ea05 216 var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
5aaf9b34 217
9c99281f 218 query = query + "&omode=flc";
5aaf9b34 219
b4e75b2a
AD
220 new Ajax.Request("backend.php", {
221 parameters: query,
bd202c3f 222 onComplete: function(transport) {
5aaf9b34 223 try {
563b9c78 224 handle_rpc_json(transport);
5aaf9b34
AD
225 } catch (e) {
226 exception_error("viewfeed/getcounters", e);
227 }
228 } });
229
997d9d7c
AD
230 } catch (e) {
231 exception_error("request_counters_real", e);
232 }
233}
234
997d9d7c
AD
235
236function request_counters() {
237
238 try {
239
a598370d
AD
240 if (getInitParam("bw_limit") == "1") return;
241
997d9d7c
AD
242 var date = new Date();
243 var timestamp = Math.round(date.getTime() / 1000);
244
b39b57ac 245 if (timestamp - counters_last_request > 5) {
84c7b824 246 console.log("scheduling request of counters...");
5225d420
AD
247
248 window.clearTimeout(counter_timeout_id);
249 counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
250
997d9d7c
AD
251 counters_last_request = timestamp;
252 } else {
84c7b824 253 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
f55b0b12 254 }
997d9d7c 255
5aaf9b34
AD
256 } catch (e) {
257 exception_error("request_counters", e);
258 }
259}
a4b906ec 260
e69fb880
AD
261function displayNewContentPrompt(id) {
262 try {
263
a8328019 264 var msg = "<a href='#' onclick='viewCurrentFeed()'>" +
e69fb880
AD
265 __("New articles available in this feed (click to show)") + "</a>";
266
267 msg = msg.replace("%s", getFeedName(id));
268
269 $('auxDlg').innerHTML = msg;
270
271 new Effect.Appear('auxDlg', {duration : 0.5});
272
273 } catch (e) {
274 exception_error("displayNewContentPrompt", e);
275 }
276}
277
563b9c78 278function parse_counters(elems, scheduled_call) {
e69fb880
AD
279 try {
280
281 var feeds_found = 0;
282
e69fb880
AD
283 for (var l = 0; l < elems.length; l++) {
284
285 var id = elems[l].id
286 var kind = elems[l].kind;
287 var ctr = parseInt(elems[l].counter)
288 var error = elems[l].error;
289 var has_img = elems[l].has_img;
290 var updated = elems[l].updated;
291 var title = elems[l].title;
563b9c78 292
e69fb880 293 if (id == "global-unread") {
e69fb880
AD
294 global_unread = ctr;
295 updateTitle();
296 continue;
297 }
298
299 if (id == "subscribed-feeds") {
300 feeds_found = ctr;
301 continue;
302 }
13e785e0
AD
303
304 var treeItem;
305
179db4a0
AD
306 // TODO: enable new content notification for categories
307
bd202c3f 308 if (!activeFeedIsCat() && id == getActiveFeedId()
179db4a0 309 && ctr > getFeedUnread(id) && scheduled_call) {
6e88da82
AD
310 displayNewContentPrompt(id);
311 }
312
78b2c6ce
AD
313 if (getFeedUnread(id, (kind == "cat")) != ctr)
314 cache_delete("feed:" + id + ":" + (kind == "cat"));
315
13e785e0 316 setFeedUnread(id, (kind == "cat"), ctr);
e69fb880 317
fcf70c51 318 if (kind != "cat") {
700f1426 319 setFeedValue(id, false, 'error', error);
fcf70c51 320 setFeedValue(id, false, 'updated', updated);
2ef5c21f
AD
321
322 if (id > 0) {
323 if (has_img) {
bd202c3f 324 setFeedIcon(id, false,
2ef5c21f
AD
325 getInitParam("icons_url") + "/" + id + ".ico");
326 } else {
327 setFeedIcon(id, false, 'images/blank_icon.gif');
328 }
329 }
e69fb880 330 }
fcf70c51 331 }
bd202c3f 332
e69fb880
AD
333 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
334
e69fb880
AD
335 } catch (e) {
336 exception_error("parse_counters", e);
337 }
338}
339
6e88da82 340function getFeedUnread(feed, is_cat) {
e69fb880 341 try {
e032e2e7
AD
342 var tree = dijit.byId("feedTree");
343
bd202c3f 344 if (tree && tree.model)
e032e2e7
AD
345 return tree.model.getFeedUnread(feed, is_cat);
346
e69fb880 347 } catch (e) {
fcf70c51 348 //
e69fb880 349 }
fcf70c51
AD
350
351 return -1;
e69fb880
AD
352}
353
e69fb880 354function resort_feedlist() {
6e88da82 355 console.warn("resort_feedlist: function not implemented");
e69fb880
AD
356}
357
358function hideOrShowFeeds(hide) {
fcf70c51
AD
359 var tree = dijit.byId("feedTree");
360
05f224a3
AD
361 if (tree)
362 return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
e69fb880
AD
363}
364
bd202c3f 365function getFeedName(feed, is_cat) {
e032e2e7
AD
366 var tree = dijit.byId("feedTree");
367
bd202c3f 368 if (tree && tree.model)
e032e2e7 369 return tree.model.getFeedValue(feed, is_cat, 'name');
fcf70c51 370}
e69fb880 371
bd202c3f 372function getFeedValue(feed, is_cat, key) {
fcf70c51 373 try {
e032e2e7 374 var tree = dijit.byId("feedTree");
fcf70c51 375
bd202c3f 376 if (tree && tree.model)
e032e2e7 377 return tree.model.getFeedValue(feed, is_cat, key);
bd202c3f 378
fcf70c51
AD
379 } catch (e) {
380 //
e69fb880 381 }
fcf70c51 382 return '';
e69fb880
AD
383}
384
13e785e0
AD
385function setFeedUnread(feed, is_cat, unread) {
386 try {
e032e2e7
AD
387 var tree = dijit.byId("feedTree");
388
bd202c3f 389 if (tree && tree.model)
e032e2e7
AD
390 return tree.model.setFeedUnread(feed, is_cat, unread);
391
fcf70c51
AD
392 } catch (e) {
393 exception_error("setFeedUnread", e);
394 }
395}
396
397function setFeedValue(feed, is_cat, key, value) {
398 try {
e032e2e7 399 var tree = dijit.byId("feedTree");
13e785e0 400
bd202c3f 401 if (tree && tree.model)
e032e2e7 402 return tree.model.setFeedValue(feed, is_cat, key, value);
c8a9fe5b 403
13e785e0 404 } catch (e) {
e032e2e7 405 //
fcf70c51
AD
406 }
407}
408
fcf70c51
AD
409function selectFeed(feed, is_cat) {
410 try {
411 var tree = dijit.byId("feedTree");
412
e032e2e7 413 if (tree) return tree.selectFeed(feed, is_cat);
fcf70c51
AD
414
415 } catch (e) {
416 exception_error("selectFeed", e);
13e785e0
AD
417 }
418}
2ef5c21f
AD
419
420function setFeedIcon(feed, is_cat, src) {
421 try {
422 var tree = dijit.byId("feedTree");
423
e032e2e7 424 if (tree) return tree.setFeedIcon(feed, is_cat, src);
2ef5c21f
AD
425
426 } catch (e) {
427 exception_error("setFeedIcon", e);
428 }
429}
9c99281f
AD
430
431function setFeedExpandoIcon(feed, is_cat, src) {
432 try {
433 var tree = dijit.byId("feedTree");
434
e032e2e7 435 if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
9c99281f
AD
436
437 } catch (e) {
438 exception_error("setFeedIcon", e);
439 }
f92d7c2b 440 return false;
9c99281f 441}
37c03d3a
AD
442
443function getNextUnreadFeed(feed, is_cat) {
444 try {
445 var tree = dijit.byId("feedTree");
446 var nuf = tree.model.getNextUnreadFeed(feed, is_cat);
447
448 if (nuf)
449 return tree.model.store.getValue(nuf, 'bare_id');
450
451 } catch (e) {
452 exception_error("getNextUnreadFeed", e);
453 }
454}
455