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