]>
Commit | Line | Data |
---|---|---|
1 | var _infscroll_disable = 0; | |
2 | var _infscroll_request_sent = 0; | |
3 | var _search_query = false; | |
4 | var _viewfeed_last = 0; | |
5 | var _viewfeed_timeout = 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 unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; | |
22 | var num_all = $$("#headlines-frame > div[id*=RROW]").length; | |
23 | var num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat()); | |
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") { | |
34 | offset = unread_in_buffer; | |
35 | } else if (_search_query) { | |
36 | offset = num_all; | |
37 | } else if (view_mode == "adaptive") { | |
38 | offset = num_unread > 0 ? unread_in_buffer : num_all; | |
39 | } else { | |
40 | offset = num_all; | |
41 | } | |
42 | ||
43 | console.log("offset: " + offset); | |
44 | ||
45 | viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true); | |
46 | ||
47 | } catch (e) { | |
48 | exception_error("viewNextFeedPage", e); | |
49 | } | |
50 | } | |
51 | ||
52 | ||
53 | function viewfeed(feed, method, is_cat, offset, background, infscroll_req, can_wait) { | |
54 | try { | |
55 | if (is_cat == undefined) | |
56 | is_cat = false; | |
57 | else | |
58 | is_cat = !!is_cat; | |
59 | ||
60 | if (method == undefined) method = ''; | |
61 | if (offset == undefined) offset = 0; | |
62 | if (background == undefined) background = false; | |
63 | if (infscroll_req == undefined) infscroll_req = false; | |
64 | ||
65 | last_requested_article = 0; | |
66 | ||
67 | if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) { | |
68 | if (!background && _search_query) _search_query = false; | |
69 | } | |
70 | ||
71 | if (!background) { | |
72 | _viewfeed_last = get_timestamp(); | |
73 | ||
74 | if (getActiveFeedId() != feed || offset == 0) { | |
75 | setActiveArticleId(0); | |
76 | _infscroll_disable = 0; | |
77 | } | |
78 | ||
79 | if (offset != 0 && !method) { | |
80 | var timestamp = get_timestamp(); | |
81 | ||
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; | |
88 | } | |
89 | } | |
90 | ||
91 | Form.enable("main_toolbar_form"); | |
92 | ||
93 | var toolbar_query = Form.serialize("main_toolbar_form"); | |
94 | ||
95 | var query = "?op=feeds&method=view&feed=" + param_escape(feed) + "&" + | |
96 | toolbar_query; | |
97 | ||
98 | if (method) { | |
99 | query = query + "&m=" + param_escape(method); | |
100 | } | |
101 | ||
102 | if (offset > 0) { | |
103 | var firstRow = $$('div[id*="RROW-"]').first(); | |
104 | ||
105 | if (firstRow) { | |
106 | query = query + "&topid=" + param_escape(parseInt(firstRow.id.replace("RROW-", ""))); | |
107 | } | |
108 | } | |
109 | ||
110 | if (!background) { | |
111 | if (_search_query) { | |
112 | force_nocache = true; | |
113 | query = query + "&" + _search_query; | |
114 | //_search_query = false; | |
115 | } | |
116 | ||
117 | if (offset != 0) { | |
118 | query = query + "&skip=" + offset; | |
119 | ||
120 | // to prevent duplicate feed titles when showing grouped vfeeds | |
121 | if (vgroup_last_feed) { | |
122 | query = query + "&vgrlf=" + param_escape(vgroup_last_feed); | |
123 | } | |
124 | } else { | |
125 | if (!method && !is_cat && feed == getActiveFeedId()) { | |
126 | query = query + "&m=ForceUpdate"; | |
127 | } | |
128 | } | |
129 | ||
130 | Form.enable("main_toolbar_form"); | |
131 | ||
132 | if (!setFeedExpandoIcon(feed, is_cat, | |
133 | (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) | |
134 | notify_progress("Loading, please wait...", true); | |
135 | } | |
136 | ||
137 | query += "&cat=" + is_cat; | |
138 | ||
139 | console.log(query); | |
140 | ||
141 | if (can_wait && _viewfeed_timeout) { | |
142 | setFeedExpandoIcon(getActiveFeedId(), activeFeedIsCat(), 'images/blank_icon.gif'); | |
143 | clearTimeout(_viewfeed_timeout); | |
144 | } | |
145 | ||
146 | setActiveFeedId(feed, is_cat); | |
147 | ||
148 | timeout_ms = can_wait ? 250 : 0; | |
149 | _viewfeed_timeout = setTimeout(function() { | |
150 | ||
151 | new Ajax.Request("backend.php", { | |
152 | parameters: query, | |
153 | onComplete: function(transport) { | |
154 | setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); | |
155 | headlines_callback2(transport, offset, background, infscroll_req); | |
156 | PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); | |
157 | } }); | |
158 | }, timeout_ms); // Wait 250ms | |
159 | ||
160 | } catch (e) { | |
161 | exception_error("viewfeed", e); | |
162 | } | |
163 | } | |
164 | ||
165 | function feedlist_init() { | |
166 | try { | |
167 | console.log("in feedlist init"); | |
168 | ||
169 | loading_set_progress(50); | |
170 | ||
171 | document.onkeydown = hotkey_handler; | |
172 | setTimeout("hotkey_prefix_timeout()", 5*1000); | |
173 | ||
174 | if (!getActiveFeedId()) { | |
175 | viewfeed(-3); | |
176 | } else { | |
177 | viewfeed(getActiveFeedId(), '', activeFeedIsCat()); | |
178 | } | |
179 | ||
180 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
181 | ||
182 | request_counters(true); | |
183 | timeout(); | |
184 | ||
185 | } catch (e) { | |
186 | exception_error("feedlist/init", e); | |
187 | } | |
188 | } | |
189 | ||
190 | ||
191 | function request_counters(force) { | |
192 | try { | |
193 | var date = new Date(); | |
194 | var timestamp = Math.round(date.getTime() / 1000); | |
195 | ||
196 | if (force || timestamp - counters_last_request > 5) { | |
197 | console.log("scheduling request of counters..."); | |
198 | ||
199 | counters_last_request = timestamp; | |
200 | ||
201 | var query = "?op=rpc&method=getAllCounters&seq=" + next_seq(); | |
202 | ||
203 | if (!force) | |
204 | query = query + "&last_article_id=" + getInitParam("last_article_id"); | |
205 | ||
206 | console.log(query); | |
207 | ||
208 | new Ajax.Request("backend.php", { | |
209 | parameters: query, | |
210 | onComplete: function(transport) { | |
211 | try { | |
212 | handle_rpc_json(transport); | |
213 | } catch (e) { | |
214 | exception_error("request_counters", e); | |
215 | } | |
216 | } }); | |
217 | ||
218 | } else { | |
219 | console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); | |
220 | } | |
221 | ||
222 | } catch (e) { | |
223 | exception_error("request_counters", e); | |
224 | } | |
225 | } | |
226 | ||
227 | function parse_counters(elems, scheduled_call) { | |
228 | try { | |
229 | for (var l = 0; l < elems.length; l++) { | |
230 | ||
231 | var id = elems[l].id; | |
232 | var kind = elems[l].kind; | |
233 | var ctr = parseInt(elems[l].counter); | |
234 | var error = elems[l].error; | |
235 | var has_img = elems[l].has_img; | |
236 | var updated = elems[l].updated; | |
237 | var auxctr = parseInt(elems[l].auxcounter); | |
238 | ||
239 | if (id == "global-unread") { | |
240 | global_unread = ctr; | |
241 | updateTitle(); | |
242 | continue; | |
243 | } | |
244 | ||
245 | if (id == "subscribed-feeds") { | |
246 | feeds_found = ctr; | |
247 | continue; | |
248 | } | |
249 | ||
250 | if (getFeedUnread(id, (kind == "cat")) != ctr || | |
251 | (kind == "cat")) { | |
252 | } | |
253 | ||
254 | setFeedUnread(id, (kind == "cat"), ctr); | |
255 | setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); | |
256 | ||
257 | if (kind != "cat") { | |
258 | setFeedValue(id, false, 'error', error); | |
259 | setFeedValue(id, false, 'updated', updated); | |
260 | ||
261 | if (id > 0) { | |
262 | if (has_img) { | |
263 | setFeedIcon(id, false, | |
264 | getInitParam("icons_url") + "/" + id + ".ico"); | |
265 | } else { | |
266 | setFeedIcon(id, false, 'images/blank_icon.gif'); | |
267 | } | |
268 | } | |
269 | } | |
270 | } | |
271 | ||
272 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
273 | ||
274 | } catch (e) { | |
275 | exception_error("parse_counters", e); | |
276 | } | |
277 | } | |
278 | ||
279 | function getFeedUnread(feed, is_cat) { | |
280 | try { | |
281 | var tree = dijit.byId("feedTree"); | |
282 | ||
283 | if (tree && tree.model) | |
284 | return tree.model.getFeedUnread(feed, is_cat); | |
285 | ||
286 | } catch (e) { | |
287 | // | |
288 | } | |
289 | ||
290 | return -1; | |
291 | } | |
292 | ||
293 | function getFeedCategory(feed) { | |
294 | try { | |
295 | var tree = dijit.byId("feedTree"); | |
296 | ||
297 | if (tree && tree.model) | |
298 | return tree.getFeedCategory(feed); | |
299 | ||
300 | } catch (e) { | |
301 | // | |
302 | } | |
303 | ||
304 | return false; | |
305 | } | |
306 | ||
307 | function hideOrShowFeeds(hide) { | |
308 | var tree = dijit.byId("feedTree"); | |
309 | ||
310 | if (tree) | |
311 | return tree.hideRead(hide, getInitParam("hide_read_shows_special")); | |
312 | } | |
313 | ||
314 | function getFeedName(feed, is_cat) { | |
315 | var tree = dijit.byId("feedTree"); | |
316 | ||
317 | if (tree && tree.model) | |
318 | return tree.model.getFeedValue(feed, is_cat, 'name'); | |
319 | } | |
320 | ||
321 | function getFeedValue(feed, is_cat, key) { | |
322 | try { | |
323 | var tree = dijit.byId("feedTree"); | |
324 | ||
325 | if (tree && tree.model) | |
326 | return tree.model.getFeedValue(feed, is_cat, key); | |
327 | ||
328 | } catch (e) { | |
329 | // | |
330 | } | |
331 | return ''; | |
332 | } | |
333 | ||
334 | function setFeedUnread(feed, is_cat, unread) { | |
335 | try { | |
336 | var tree = dijit.byId("feedTree"); | |
337 | ||
338 | if (tree && tree.model) | |
339 | return tree.model.setFeedUnread(feed, is_cat, unread); | |
340 | ||
341 | } catch (e) { | |
342 | exception_error("setFeedUnread", e); | |
343 | } | |
344 | } | |
345 | ||
346 | function setFeedValue(feed, is_cat, key, value) { | |
347 | try { | |
348 | var tree = dijit.byId("feedTree"); | |
349 | ||
350 | if (tree && tree.model) | |
351 | return tree.model.setFeedValue(feed, is_cat, key, value); | |
352 | ||
353 | } catch (e) { | |
354 | // | |
355 | } | |
356 | } | |
357 | ||
358 | function selectFeed(feed, is_cat) { | |
359 | try { | |
360 | var tree = dijit.byId("feedTree"); | |
361 | ||
362 | if (tree) return tree.selectFeed(feed, is_cat); | |
363 | ||
364 | } catch (e) { | |
365 | exception_error("selectFeed", e); | |
366 | } | |
367 | } | |
368 | ||
369 | function setFeedIcon(feed, is_cat, src) { | |
370 | try { | |
371 | var tree = dijit.byId("feedTree"); | |
372 | ||
373 | if (tree) return tree.setFeedIcon(feed, is_cat, src); | |
374 | ||
375 | } catch (e) { | |
376 | exception_error("setFeedIcon", e); | |
377 | } | |
378 | } | |
379 | ||
380 | function setFeedExpandoIcon(feed, is_cat, src) { | |
381 | try { | |
382 | var tree = dijit.byId("feedTree"); | |
383 | ||
384 | if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); | |
385 | ||
386 | } catch (e) { | |
387 | exception_error("setFeedIcon", e); | |
388 | } | |
389 | return false; | |
390 | } | |
391 | ||
392 | function getNextUnreadFeed(feed, is_cat) { | |
393 | try { | |
394 | var tree = dijit.byId("feedTree"); | |
395 | var nuf = tree.model.getNextUnreadFeed(feed, is_cat); | |
396 | ||
397 | if (nuf) | |
398 | return tree.model.store.getValue(nuf, 'bare_id'); | |
399 | ||
400 | } catch (e) { | |
401 | exception_error("getNextUnreadFeed", e); | |
402 | } | |
403 | } | |
404 | ||
405 | function catchupCurrentFeed(mode) { | |
406 | catchupFeed(getActiveFeedId(), activeFeedIsCat(), mode); | |
407 | } | |
408 | ||
409 | function catchupFeedInGroup(id) { | |
410 | try { | |
411 | ||
412 | var title = getFeedName(id); | |
413 | ||
414 | var str = __("Mark all articles in %s as read?").replace("%s", title); | |
415 | ||
416 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
417 | return viewCurrentFeed('MarkAllReadGR:' + id); | |
418 | } | |
419 | ||
420 | } catch (e) { | |
421 | exception_error("catchupFeedInGroup", e); | |
422 | } | |
423 | } | |
424 | ||
425 | function catchupFeed(feed, is_cat, mode) { | |
426 | try { | |
427 | if (is_cat == undefined) is_cat = false; | |
428 | ||
429 | var str = false; | |
430 | ||
431 | switch (mode) { | |
432 | case "1day": | |
433 | str = __("Mark all articles in %s older than 1 day as read?"); | |
434 | break; | |
435 | case "1week": | |
436 | str = __("Mark all articles in %s older than 1 week as read?"); | |
437 | break; | |
438 | case "2week": | |
439 | str = __("Mark all articles in %s older than 2 weeks as read?"); | |
440 | break; | |
441 | default: | |
442 | str = __("Mark all articles in %s as read?"); | |
443 | } | |
444 | ||
445 | var fn = getFeedName(feed, is_cat); | |
446 | ||
447 | str = str.replace("%s", fn); | |
448 | ||
449 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
450 | return; | |
451 | } | |
452 | ||
453 | var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + | |
454 | feed + "&is_cat=" + is_cat + "&mode=" + mode; | |
455 | ||
456 | console.log(catchup_query); | |
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); | |
464 | ||
465 | var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; | |
466 | ||
467 | if (show_next_feed) { | |
468 | var nuf = getNextUnreadFeed(feed, is_cat); | |
469 | ||
470 | if (nuf) { | |
471 | viewfeed(nuf, '', is_cat); | |
472 | } | |
473 | } else { | |
474 | if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { | |
475 | viewCurrentFeed(); | |
476 | } | |
477 | } | |
478 | ||
479 | notify(""); | |
480 | } }); | |
481 | ||
482 | } catch (e) { | |
483 | exception_error("catchupFeed", e); | |
484 | } | |
485 | } | |
486 | ||
487 | function decrementFeedCounter(feed, is_cat) { | |
488 | try { | |
489 | var ctr = getFeedUnread(feed, is_cat); | |
490 | ||
491 | if (ctr > 0) { | |
492 | setFeedUnread(feed, is_cat, ctr - 1); | |
493 | global_unread = global_unread - 1; | |
494 | updateTitle(); | |
495 | ||
496 | if (!is_cat) { | |
497 | var cat = parseInt(getFeedCategory(feed)); | |
498 | ||
499 | if (!isNaN(cat)) { | |
500 | ctr = getFeedUnread(cat, true); | |
501 | ||
502 | if (ctr > 0) { | |
503 | setFeedUnread(cat, true, ctr - 1); | |
504 | } | |
505 | } | |
506 | } | |
507 | } | |
508 | ||
509 | } catch (e) { | |
510 | exception_error("decrement_feed_counter", e); | |
511 | } | |
512 | } | |
513 | ||
514 |