]>
Commit | Line | Data |
---|---|---|
1 | var _infscroll_disable = 0; | |
2 | var _infscroll_request_sent = 0; | |
3 | var _search_query = false; | |
4 | ||
5 | var counter_timeout_id = false; | |
6 | ||
7 | var counters_last_request = 0; | |
8 | ||
9 | function viewCategory(cat) { | |
10 | viewfeed(cat, '', true); | |
11 | return false; | |
12 | } | |
13 | ||
14 | function loadMoreHeadlines() { | |
15 | try { | |
16 | console.log("loadMoreHeadlines"); | |
17 | ||
18 | var offset = 0; | |
19 | ||
20 | var view_mode = document.forms["main_toolbar_form"].view_mode.value; | |
21 | var num_unread = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; | |
22 | var num_all = $$("#headlines-frame > div[id*=RROW]").length; | |
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") { | |
33 | offset = num_unread; | |
34 | } else if (view_mode == "adaptive") { | |
35 | if (num_unread > 0) | |
36 | offset = num_unread; | |
37 | else | |
38 | offset = num_all; | |
39 | } else { | |
40 | offset = num_all; | |
41 | } | |
42 | ||
43 | viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true); | |
44 | ||
45 | } catch (e) { | |
46 | exception_error("viewNextFeedPage", e); | |
47 | } | |
48 | } | |
49 | ||
50 | ||
51 | function viewfeed(feed, method, is_cat, offset, background, infscroll_req) { | |
52 | try { | |
53 | if (is_cat == undefined) | |
54 | is_cat = false; | |
55 | else | |
56 | is_cat = !!is_cat; | |
57 | ||
58 | if (method == undefined) method = ''; | |
59 | if (offset == undefined) offset = 0; | |
60 | if (background == undefined) background = false; | |
61 | if (infscroll_req == undefined) infscroll_req = false; | |
62 | ||
63 | last_requested_article = 0; | |
64 | ||
65 | var cached_headlines = false; | |
66 | ||
67 | if (feed == getActiveFeedId()) { | |
68 | cache_delete("feed:" + feed + ":" + is_cat); | |
69 | } else { | |
70 | cached_headlines = cache_get("feed:" + feed + ":" + is_cat); | |
71 | ||
72 | // switching to a different feed, we might as well catchup stuff visible | |
73 | // in headlines buffer (if any) | |
74 | if (!background && isCdmMode() && getInitParam("cdm_auto_catchup") == 1 && parseInt(getActiveFeedId()) > 0) { | |
75 | ||
76 | $$("#headlines-frame > div[id*=RROW][class*=Unread]").each( | |
77 | function(child) { | |
78 | var hf = $("headlines-frame"); | |
79 | ||
80 | if (hf.scrollTop + hf.offsetHeight >= | |
81 | child.offsetTop + child.offsetHeight) { | |
82 | ||
83 | var id = child.id.replace("RROW-", ""); | |
84 | ||
85 | if (catchup_id_batch.indexOf(id) == -1) | |
86 | catchup_id_batch.push(id); | |
87 | ||
88 | } | |
89 | ||
90 | if (catchup_id_batch.length > 0) { | |
91 | window.clearTimeout(catchup_timeout_id); | |
92 | ||
93 | if (!_infscroll_request_sent) { | |
94 | catchup_timeout_id = window.setTimeout('catchupBatchedArticles()', | |
95 | 2000); | |
96 | } | |
97 | } | |
98 | ||
99 | }); | |
100 | } | |
101 | } | |
102 | ||
103 | if (offset == 0 && !background) | |
104 | dijit.byId("content-tabs").selectChild( | |
105 | dijit.byId("content-tabs").getChildren()[0]); | |
106 | ||
107 | if (!background) { | |
108 | if (getActiveFeedId() != feed || offset == 0) { | |
109 | active_post_id = 0; | |
110 | _infscroll_disable = 0; | |
111 | } | |
112 | ||
113 | if (!offset && !method && cached_headlines && !background) { | |
114 | try { | |
115 | render_local_headlines(feed, is_cat, JSON.parse(cached_headlines)); | |
116 | return; | |
117 | } catch (e) { | |
118 | console.warn("render_local_headlines failed: " + e); | |
119 | } | |
120 | } | |
121 | ||
122 | if (offset != 0 && !method) { | |
123 | var date = new Date(); | |
124 | var timestamp = Math.round(date.getTime() / 1000); | |
125 | ||
126 | if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) { | |
127 | //console.log("infscroll request in progress, aborting"); | |
128 | return; | |
129 | } | |
130 | ||
131 | _infscroll_request_sent = timestamp; | |
132 | } | |
133 | ||
134 | hideAuxDlg(); | |
135 | } | |
136 | ||
137 | Form.enable("main_toolbar_form"); | |
138 | ||
139 | var toolbar_query = Form.serialize("main_toolbar_form"); | |
140 | ||
141 | var query = "?op=feeds&method=view&feed=" + feed + "&" + | |
142 | toolbar_query + "&m=" + param_escape(method); | |
143 | ||
144 | if (!background) { | |
145 | if (_search_query) { | |
146 | force_nocache = true; | |
147 | query = query + "&" + _search_query; | |
148 | _search_query = false; | |
149 | } | |
150 | ||
151 | if (offset != 0) { | |
152 | query = query + "&skip=" + offset; | |
153 | ||
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 | } | |
158 | } | |
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 | } | |
169 | } | |
170 | ||
171 | query += "&cat=" + is_cat; | |
172 | ||
173 | console.log(query); | |
174 | ||
175 | new Ajax.Request("backend.php", { | |
176 | parameters: query, | |
177 | onComplete: function(transport) { | |
178 | setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); | |
179 | headlines_callback2(transport, offset, background, infscroll_req); | |
180 | } }); | |
181 | ||
182 | } catch (e) { | |
183 | exception_error("viewfeed", e); | |
184 | } | |
185 | } | |
186 | ||
187 | function feedlist_init() { | |
188 | try { | |
189 | console.log("in feedlist init"); | |
190 | ||
191 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
192 | document.onkeydown = hotkey_handler; | |
193 | setTimeout("hotkey_prefix_timeout()", 5*1000); | |
194 | ||
195 | if (!getActiveFeedId()) { | |
196 | setTimeout("viewfeed(-3)", 100); | |
197 | } | |
198 | ||
199 | console.log("T:" + | |
200 | getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3)); | |
201 | ||
202 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
203 | ||
204 | setTimeout("timeout()", 5000); | |
205 | setTimeout("precache_headlines_idle()", 3000); | |
206 | ||
207 | } catch (e) { | |
208 | exception_error("feedlist/init", e); | |
209 | } | |
210 | } | |
211 | ||
212 | function request_counters_real() { | |
213 | try { | |
214 | console.log("requesting counters..."); | |
215 | ||
216 | var query = "?op=rpc&method=getAllCounters&seq=" + next_seq(); | |
217 | ||
218 | query = query + "&omode=flc"; | |
219 | ||
220 | new Ajax.Request("backend.php", { | |
221 | parameters: query, | |
222 | onComplete: function(transport) { | |
223 | try { | |
224 | handle_rpc_json(transport); | |
225 | } catch (e) { | |
226 | exception_error("viewfeed/getcounters", e); | |
227 | } | |
228 | } }); | |
229 | ||
230 | } catch (e) { | |
231 | exception_error("request_counters_real", e); | |
232 | } | |
233 | } | |
234 | ||
235 | ||
236 | function request_counters() { | |
237 | ||
238 | try { | |
239 | ||
240 | if (getInitParam("bw_limit") == "1") return; | |
241 | ||
242 | var date = new Date(); | |
243 | var timestamp = Math.round(date.getTime() / 1000); | |
244 | ||
245 | if (timestamp - counters_last_request > 5) { | |
246 | console.log("scheduling request of counters..."); | |
247 | ||
248 | window.clearTimeout(counter_timeout_id); | |
249 | counter_timeout_id = window.setTimeout("request_counters_real()", 1000); | |
250 | ||
251 | counters_last_request = timestamp; | |
252 | } else { | |
253 | console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); | |
254 | } | |
255 | ||
256 | } catch (e) { | |
257 | exception_error("request_counters", e); | |
258 | } | |
259 | } | |
260 | ||
261 | function displayNewContentPrompt(id) { | |
262 | try { | |
263 | ||
264 | var msg = "<a href='#' onclick='viewCurrentFeed()'>" + | |
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 | ||
278 | function parse_counters(elems, scheduled_call) { | |
279 | try { | |
280 | for (var l = 0; l < elems.length; l++) { | |
281 | ||
282 | var id = elems[l].id; | |
283 | var kind = elems[l].kind; | |
284 | var ctr = parseInt(elems[l].counter); | |
285 | var error = elems[l].error; | |
286 | var has_img = elems[l].has_img; | |
287 | var updated = elems[l].updated; | |
288 | ||
289 | if (id == "global-unread") { | |
290 | global_unread = ctr; | |
291 | updateTitle(); | |
292 | continue; | |
293 | } | |
294 | ||
295 | if (id == "subscribed-feeds") { | |
296 | feeds_found = ctr; | |
297 | continue; | |
298 | } | |
299 | ||
300 | // TODO: enable new content notification for categories | |
301 | ||
302 | if (!activeFeedIsCat() && id == getActiveFeedId() | |
303 | && ctr > getFeedUnread(id) && scheduled_call) { | |
304 | displayNewContentPrompt(id); | |
305 | } | |
306 | ||
307 | if (getFeedUnread(id, (kind == "cat")) != ctr) | |
308 | cache_delete("feed:" + id + ":" + (kind == "cat")); | |
309 | ||
310 | setFeedUnread(id, (kind == "cat"), ctr); | |
311 | ||
312 | if (kind != "cat") { | |
313 | setFeedValue(id, false, 'error', error); | |
314 | setFeedValue(id, false, 'updated', updated); | |
315 | ||
316 | if (id > 0) { | |
317 | if (has_img) { | |
318 | setFeedIcon(id, false, | |
319 | getInitParam("icons_url") + "/" + id + ".ico"); | |
320 | } else { | |
321 | setFeedIcon(id, false, 'images/blank_icon.gif'); | |
322 | } | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
327 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
328 | ||
329 | } catch (e) { | |
330 | exception_error("parse_counters", e); | |
331 | } | |
332 | } | |
333 | ||
334 | function getFeedUnread(feed, is_cat) { | |
335 | try { | |
336 | var tree = dijit.byId("feedTree"); | |
337 | ||
338 | if (tree && tree.model) | |
339 | return tree.model.getFeedUnread(feed, is_cat); | |
340 | ||
341 | } catch (e) { | |
342 | // | |
343 | } | |
344 | ||
345 | return -1; | |
346 | } | |
347 | ||
348 | function hideOrShowFeeds(hide) { | |
349 | var tree = dijit.byId("feedTree"); | |
350 | ||
351 | if (tree) | |
352 | return tree.hideRead(hide, getInitParam("hide_read_shows_special")); | |
353 | } | |
354 | ||
355 | function getFeedName(feed, is_cat) { | |
356 | var tree = dijit.byId("feedTree"); | |
357 | ||
358 | if (tree && tree.model) | |
359 | return tree.model.getFeedValue(feed, is_cat, 'name'); | |
360 | } | |
361 | ||
362 | function getFeedValue(feed, is_cat, key) { | |
363 | try { | |
364 | var tree = dijit.byId("feedTree"); | |
365 | ||
366 | if (tree && tree.model) | |
367 | return tree.model.getFeedValue(feed, is_cat, key); | |
368 | ||
369 | } catch (e) { | |
370 | // | |
371 | } | |
372 | return ''; | |
373 | } | |
374 | ||
375 | function setFeedUnread(feed, is_cat, unread) { | |
376 | try { | |
377 | var tree = dijit.byId("feedTree"); | |
378 | ||
379 | if (tree && tree.model) | |
380 | return tree.model.setFeedUnread(feed, is_cat, unread); | |
381 | ||
382 | } catch (e) { | |
383 | exception_error("setFeedUnread", e); | |
384 | } | |
385 | } | |
386 | ||
387 | function setFeedValue(feed, is_cat, key, value) { | |
388 | try { | |
389 | var tree = dijit.byId("feedTree"); | |
390 | ||
391 | if (tree && tree.model) | |
392 | return tree.model.setFeedValue(feed, is_cat, key, value); | |
393 | ||
394 | } catch (e) { | |
395 | // | |
396 | } | |
397 | } | |
398 | ||
399 | function selectFeed(feed, is_cat) { | |
400 | try { | |
401 | var tree = dijit.byId("feedTree"); | |
402 | ||
403 | if (tree) return tree.selectFeed(feed, is_cat); | |
404 | ||
405 | } catch (e) { | |
406 | exception_error("selectFeed", e); | |
407 | } | |
408 | } | |
409 | ||
410 | function setFeedIcon(feed, is_cat, src) { | |
411 | try { | |
412 | var tree = dijit.byId("feedTree"); | |
413 | ||
414 | if (tree) return tree.setFeedIcon(feed, is_cat, src); | |
415 | ||
416 | } catch (e) { | |
417 | exception_error("setFeedIcon", e); | |
418 | } | |
419 | } | |
420 | ||
421 | function setFeedExpandoIcon(feed, is_cat, src) { | |
422 | try { | |
423 | var tree = dijit.byId("feedTree"); | |
424 | ||
425 | if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); | |
426 | ||
427 | } catch (e) { | |
428 | exception_error("setFeedIcon", e); | |
429 | } | |
430 | return false; | |
431 | } | |
432 | ||
433 | function getNextUnreadFeed(feed, is_cat) { | |
434 | try { | |
435 | var tree = dijit.byId("feedTree"); | |
436 | var nuf = tree.model.getNextUnreadFeed(feed, is_cat); | |
437 | ||
438 | if (nuf) | |
439 | return tree.model.store.getValue(nuf, 'bare_id'); | |
440 | ||
441 | } catch (e) { | |
442 | exception_error("getNextUnreadFeed", e); | |
443 | } | |
444 | } | |
445 | ||
446 | function catchupCurrentFeed() { | |
447 | return catchupFeed(getActiveFeedId(), activeFeedIsCat()); | |
448 | } | |
449 | ||
450 | function catchupFeedInGroup(id) { | |
451 | try { | |
452 | ||
453 | var title = getFeedName(id); | |
454 | ||
455 | var str = __("Mark all articles in %s as read?").replace("%s", title); | |
456 | ||
457 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
458 | return viewCurrentFeed('MarkAllReadGR:' + id); | |
459 | } | |
460 | ||
461 | } catch (e) { | |
462 | exception_error("catchupFeedInGroup", e); | |
463 | } | |
464 | } | |
465 | ||
466 | function catchupFeed(feed, is_cat) { | |
467 | try { | |
468 | var str = __("Mark all articles in %s as read?"); | |
469 | var fn = getFeedName(feed, is_cat); | |
470 | ||
471 | str = str.replace("%s", fn); | |
472 | ||
473 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
474 | return; | |
475 | } | |
476 | ||
477 | var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + | |
478 | feed + "&is_cat=" + is_cat; | |
479 | ||
480 | notify_progress("Loading, please wait...", true); | |
481 | ||
482 | new Ajax.Request("backend.php", { | |
483 | parameters: catchup_query, | |
484 | onComplete: function(transport) { | |
485 | handle_rpc_json(transport); | |
486 | ||
487 | if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { | |
488 | ||
489 | $$("#headlines-frame > div[id*=RROW][class*=Unread]").each( | |
490 | function(child) { | |
491 | child.removeClassName("Unread"); | |
492 | } | |
493 | ); | |
494 | } | |
495 | ||
496 | var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; | |
497 | ||
498 | if (show_next_feed) { | |
499 | var nuf = getNextUnreadFeed(feed, is_cat); | |
500 | ||
501 | if (nuf) { | |
502 | viewfeed(nuf); | |
503 | } | |
504 | } | |
505 | ||
506 | notify(""); | |
507 | } }); | |
508 | ||
509 | } catch (e) { | |
510 | exception_error("catchupFeed", e); | |
511 | } | |
512 | } |