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