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