]> git.wh0rd.org - tt-rss.git/blame - feedlist.js
viewfeed: fix typo
[tt-rss.git] / feedlist.js
CommitLineData
29dfb258 1var _infscroll_disable = 0;
82764a41 2var _infscroll_request_sent = 0;
973fe3c6 3var _search_query = false;
ac541432 4
5225d420
AD
5var counter_timeout_id = false;
6
9922d56b 7var counters_last_request = 0;
91cdbe52 8
ff2c6e6a 9function viewCategory(cat) {
767e2486 10 viewfeed(cat, '', true);
0c3d1219 11 return false;
ff2c6e6a
AD
12}
13
71317973 14function loadMoreHeadlines() {
ac541432 15 try {
71317973
AD
16 var offset = 0;
17
18 var view_mode = document.forms["main_toolbar_form"].view_mode.value;
19 var num_unread = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
20 var num_all = $$("#headlines-frame > div[id*=RROW]").length;
21
22 // TODO implement marked & published
23
24 if (view_mode == "marked") {
25 console.warn("loadMoreHeadlines: marked is not implemented, falling back.");
26 offset = num_all;
27 } else if (view_mode == "published") {
28 console.warn("loadMoreHeadlines: published is not implemented, falling back.");
29 offset = num_all;
30 } else if (view_mode == "unread") {
31 offset = num_unread;
32 } else if (view_mode == "adaptive") {
33 if (num_unread > 0)
34 offset = num_unread;
35 else
36 offset = num_all;
37 } else {
38 offset = num_all;
39 }
2a8534a0 40
71317973 41 viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset);
ac541432
AD
42
43 } catch (e) {
8b365031 44 exception_error("viewNextFeedPage", e);
ac541432
AD
45 }
46}
47
6a2034f9 48
37c03d3a 49function viewfeed(feed, subop, is_cat, offset, background) {
7719618b 50 try {
78b2c6ce
AD
51 if (is_cat == undefined)
52 is_cat = false;
53 else
54 is_cat = !!is_cat;
55
cd1bb36d 56 if (subop == undefined) subop = '';
71317973 57 if (offset == undefined) offset = 0;
37c03d3a 58 if (background == undefined) background = false;
c50e2b30 59
32f0c8b0
AD
60 last_requested_article = 0;
61
78b2c6ce
AD
62 var cached_headlines = false;
63
64 if (feed == getActiveFeedId())
65 cache_delete("feed:" + feed + ":" + is_cat);
66 else
67 cached_headlines = cache_get("feed:" + feed + ":" + is_cat);
b8e6acea 68
0612ce23
AD
69 if (offset == 0)
70 dijit.byId("content-tabs").selectChild(
71 dijit.byId("content-tabs").getChildren()[0]);
f92d7c2b 72
52d7e7da
AD
73 var force_nocache = false;
74
37c03d3a
AD
75 if (!background) {
76 if (getActiveFeedId() != feed || offset == 0) {
77 active_post_id = 0;
78 _infscroll_disable = 0;
79 }
203de776 80
37c03d3a
AD
81 if (!offset && !subop && cached_headlines && !background) {
82 try {
83 render_local_headlines(feed, is_cat, JSON.parse(cached_headlines));
84 return;
85 } catch (e) {
86 console.warn("render_local_headlines failed: " + e);
87 }
78b2c6ce 88 }
78b2c6ce 89
37c03d3a
AD
90 if (offset != 0 && !subop) {
91 var date = new Date();
92 var timestamp = Math.round(date.getTime() / 1000);
82764a41 93
37c03d3a
AD
94 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
95 //console.log("infscroll request in progress, aborting");
96 return;
97 }
98
99 _infscroll_request_sent = timestamp;
82764a41
AD
100 }
101
37c03d3a 102 hideAuxDlg();
82764a41
AD
103 }
104
fd98576c
AD
105 Form.enable("main_toolbar_form");
106
fd98576c 107 var toolbar_query = Form.serialize("main_toolbar_form");
86b682ce 108
37c03d3a
AD
109 var query = "?op=viewfeed&feed=" + feed + "&" +
110 toolbar_query + "&subop=" + param_escape(subop);
111
112 if (!background) {
113 if (_search_query) {
52d7e7da 114 force_nocache = true;
37c03d3a
AD
115 query = query + "&" + _search_query;
116 _search_query = false;
52d7e7da 117 }
164f4738 118
37c03d3a 119 if (subop == "MarkAllRead") {
86b682ce 120
37c03d3a 121 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
86b682ce 122
37c03d3a
AD
123 if (show_next_feed) {
124 var nuf = getNextUnreadFeed(feed, is_cat);
e0998414 125
37c03d3a
AD
126 if (nuf) {
127 var cached_nuf = cache_get("feed:" + nuf + ":false");
3ac2b520 128
37c03d3a 129 if (cached_nuf) {
692de159 130
37c03d3a 131 render_local_headlines(nuf, false, JSON.parse(cached_nuf));
692de159 132
37c03d3a
AD
133 var catchup_query = "?op=rpc&subop=catchupFeed&feed_id=" +
134 feed + "&is_cat=" + is_cat;
135
136 console.log(catchup_query);
137
138 new Ajax.Request("backend.php", {
139 parameters: catchup_query,
140 onComplete: function(transport) {
141 handle_rpc_json(transport);
142 } });
143
144 return;
145 } else {
146 query += "&nuf=" + param_escape(nuf);
147 }
148 }
692de159 149 }
e0998414 150 }
ff2c6e6a 151
37c03d3a
AD
152 if (offset != 0) {
153 query = query + "&skip=" + offset;
60d4df4d 154
37c03d3a
AD
155 // to prevent duplicate feed titles when showing grouped vfeeds
156 if (vgroup_last_feed) {
157 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
158 }
60d4df4d 159 }
37c03d3a
AD
160
161 Form.enable("main_toolbar_form");
162
163 if (!offset)
164 if (!is_cat) {
165 if (!setFeedExpandoIcon(feed, is_cat, 'images/indicator_white.gif'))
166 notify_progress("Loading, please wait...", true);
167 } else {
168 notify_progress("Loading, please wait...", true);
169 }
203de776
AD
170 }
171
37c03d3a 172 query += "&cat=" + is_cat;
6b4163cb 173
84c7b824 174 console.log(query);
081e527d 175
71317973
AD
176 new Ajax.Request("backend.php", {
177 parameters: query,
178 onComplete: function(transport) {
179 setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
37c03d3a 180 headlines_callback2(transport, offset, background);
71317973 181 } });
6b4163cb 182
7719618b
AD
183 } catch (e) {
184 exception_error("viewfeed", e);
bd202c3f 185 }
1a66d16e
AD
186}
187
6b4163cb 188function feedlist_init() {
1b0809ae 189 try {
fcf70c51 190 console.log("in feedlist init");
bd202c3f 191
60ea2377 192 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1b0809ae 193 document.onkeydown = hotkey_handler;
164469f9
AD
194 setTimeout("hotkey_prefix_timeout()", 5*1000);
195
6e88da82 196 if (!getActiveFeedId()) {
bd202c3f
AD
197 setTimeout("viewfeed(-3)", 100);
198 }
fcf70c51 199
bd202c3f 200 console.log("T:" +
6e88da82 201 getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3));
7086277c 202
a73e6b97 203 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
782ddd70 204
cd1bb36d 205 setTimeout("timeout()", 5000);
452e75cc 206 setTimeout("precache_headlines_idle()", 3000);
cd1bb36d 207
1b0809ae 208 } catch (e) {
bbf4d0b2 209 exception_error("feedlist/init", e);
1b0809ae 210 }
3745788e 211}
22e06406 212
997d9d7c 213function request_counters_real() {
5aaf9b34 214 try {
84c7b824 215 console.log("requesting counters...");
06c88b8d 216
6237ea05 217 var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
5aaf9b34 218
9c99281f 219 query = query + "&omode=flc";
5aaf9b34 220
b4e75b2a
AD
221 new Ajax.Request("backend.php", {
222 parameters: query,
bd202c3f 223 onComplete: function(transport) {
5aaf9b34 224 try {
563b9c78 225 handle_rpc_json(transport);
5aaf9b34
AD
226 } catch (e) {
227 exception_error("viewfeed/getcounters", e);
228 }
229 } });
230
997d9d7c
AD
231 } catch (e) {
232 exception_error("request_counters_real", e);
233 }
234}
235
997d9d7c
AD
236
237function request_counters() {
238
239 try {
240
a598370d
AD
241 if (getInitParam("bw_limit") == "1") return;
242
997d9d7c
AD
243 var date = new Date();
244 var timestamp = Math.round(date.getTime() / 1000);
245
b39b57ac 246 if (timestamp - counters_last_request > 5) {
84c7b824 247 console.log("scheduling request of counters...");
5225d420
AD
248
249 window.clearTimeout(counter_timeout_id);
250 counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
251
997d9d7c
AD
252 counters_last_request = timestamp;
253 } else {
84c7b824 254 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
f55b0b12 255 }
997d9d7c 256
5aaf9b34
AD
257 } catch (e) {
258 exception_error("request_counters", e);
259 }
260}
a4b906ec 261
e69fb880
AD
262function displayNewContentPrompt(id) {
263 try {
264
a8328019 265 var msg = "<a href='#' onclick='viewCurrentFeed()'>" +
e69fb880
AD
266 __("New articles available in this feed (click to show)") + "</a>";
267
268 msg = msg.replace("%s", getFeedName(id));
269
270 $('auxDlg').innerHTML = msg;
271
272 new Effect.Appear('auxDlg', {duration : 0.5});
273
274 } catch (e) {
275 exception_error("displayNewContentPrompt", e);
276 }
277}
278
563b9c78 279function parse_counters(elems, scheduled_call) {
e69fb880
AD
280 try {
281
282 var feeds_found = 0;
283
e69fb880
AD
284 for (var l = 0; l < elems.length; l++) {
285
286 var id = elems[l].id
287 var kind = elems[l].kind;
288 var ctr = parseInt(elems[l].counter)
289 var error = elems[l].error;
290 var has_img = elems[l].has_img;
291 var updated = elems[l].updated;
292 var title = elems[l].title;
563b9c78 293
e69fb880 294 if (id == "global-unread") {
e69fb880
AD
295 global_unread = ctr;
296 updateTitle();
297 continue;
298 }
299
300 if (id == "subscribed-feeds") {
301 feeds_found = ctr;
302 continue;
303 }
13e785e0
AD
304
305 var treeItem;
306
179db4a0
AD
307 // TODO: enable new content notification for categories
308
bd202c3f 309 if (!activeFeedIsCat() && id == getActiveFeedId()
179db4a0 310 && ctr > getFeedUnread(id) && scheduled_call) {
6e88da82
AD
311 displayNewContentPrompt(id);
312 }
313
78b2c6ce
AD
314 if (getFeedUnread(id, (kind == "cat")) != ctr)
315 cache_delete("feed:" + id + ":" + (kind == "cat"));
316
13e785e0 317 setFeedUnread(id, (kind == "cat"), ctr);
e69fb880 318
fcf70c51 319 if (kind != "cat") {
700f1426 320 setFeedValue(id, false, 'error', error);
fcf70c51 321 setFeedValue(id, false, 'updated', updated);
2ef5c21f
AD
322
323 if (id > 0) {
324 if (has_img) {
bd202c3f 325 setFeedIcon(id, false,
2ef5c21f
AD
326 getInitParam("icons_url") + "/" + id + ".ico");
327 } else {
328 setFeedIcon(id, false, 'images/blank_icon.gif');
329 }
330 }
e69fb880 331 }
fcf70c51 332 }
bd202c3f 333
e69fb880
AD
334 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
335
e69fb880
AD
336 } catch (e) {
337 exception_error("parse_counters", e);
338 }
339}
340
6e88da82 341function getFeedUnread(feed, is_cat) {
e69fb880 342 try {
e032e2e7
AD
343 var tree = dijit.byId("feedTree");
344
bd202c3f 345 if (tree && tree.model)
e032e2e7
AD
346 return tree.model.getFeedUnread(feed, is_cat);
347
e69fb880 348 } catch (e) {
fcf70c51 349 //
e69fb880 350 }
fcf70c51
AD
351
352 return -1;
e69fb880
AD
353}
354
e69fb880 355function resort_feedlist() {
6e88da82 356 console.warn("resort_feedlist: function not implemented");
e69fb880
AD
357}
358
359function hideOrShowFeeds(hide) {
fcf70c51
AD
360 var tree = dijit.byId("feedTree");
361
05f224a3
AD
362 if (tree)
363 return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
e69fb880
AD
364}
365
bd202c3f 366function getFeedName(feed, is_cat) {
e032e2e7
AD
367 var tree = dijit.byId("feedTree");
368
bd202c3f 369 if (tree && tree.model)
e032e2e7 370 return tree.model.getFeedValue(feed, is_cat, 'name');
fcf70c51 371}
e69fb880 372
bd202c3f 373function getFeedValue(feed, is_cat, key) {
fcf70c51 374 try {
e032e2e7 375 var tree = dijit.byId("feedTree");
fcf70c51 376
bd202c3f 377 if (tree && tree.model)
e032e2e7 378 return tree.model.getFeedValue(feed, is_cat, key);
bd202c3f 379
fcf70c51
AD
380 } catch (e) {
381 //
e69fb880 382 }
fcf70c51 383 return '';
e69fb880
AD
384}
385
13e785e0
AD
386function setFeedUnread(feed, is_cat, unread) {
387 try {
e032e2e7
AD
388 var tree = dijit.byId("feedTree");
389
bd202c3f 390 if (tree && tree.model)
e032e2e7
AD
391 return tree.model.setFeedUnread(feed, is_cat, unread);
392
fcf70c51
AD
393 } catch (e) {
394 exception_error("setFeedUnread", e);
395 }
396}
397
398function setFeedValue(feed, is_cat, key, value) {
399 try {
e032e2e7 400 var tree = dijit.byId("feedTree");
13e785e0 401
bd202c3f 402 if (tree && tree.model)
e032e2e7 403 return tree.model.setFeedValue(feed, is_cat, key, value);
c8a9fe5b 404
13e785e0 405 } catch (e) {
e032e2e7 406 //
fcf70c51
AD
407 }
408}
409
fcf70c51
AD
410function selectFeed(feed, is_cat) {
411 try {
412 var tree = dijit.byId("feedTree");
413
e032e2e7 414 if (tree) return tree.selectFeed(feed, is_cat);
fcf70c51
AD
415
416 } catch (e) {
417 exception_error("selectFeed", e);
13e785e0
AD
418 }
419}
2ef5c21f
AD
420
421function setFeedIcon(feed, is_cat, src) {
422 try {
423 var tree = dijit.byId("feedTree");
424
e032e2e7 425 if (tree) return tree.setFeedIcon(feed, is_cat, src);
2ef5c21f
AD
426
427 } catch (e) {
428 exception_error("setFeedIcon", e);
429 }
430}
9c99281f
AD
431
432function setFeedExpandoIcon(feed, is_cat, src) {
433 try {
434 var tree = dijit.byId("feedTree");
435
e032e2e7 436 if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
9c99281f
AD
437
438 } catch (e) {
439 exception_error("setFeedIcon", e);
440 }
f92d7c2b 441 return false;
9c99281f 442}
37c03d3a
AD
443
444function getNextUnreadFeed(feed, is_cat) {
445 try {
446 var tree = dijit.byId("feedTree");
447 var nuf = tree.model.getNextUnreadFeed(feed, is_cat);
448
449 if (nuf)
450 return tree.model.store.getValue(nuf, 'bare_id');
451
452 } catch (e) {
453 exception_error("getNextUnreadFeed", e);
454 }
455}
456