Try loading older messages after user is idle

(imported from commit bb3c39f9b5a9b7befb353647af75001ec168fc8d)
This commit is contained in:
Zev Benjamin
2012-10-26 13:30:42 -04:00
parent 807303a325
commit 652c524777

View File

@@ -735,22 +735,25 @@ function load_old_messages(start, which, number, cont) {
// get the initial message list // get the initial message list
$(function () { $(function () {
function load_to_end(messages) { function load_more(messages) {
// catch the user up // catch the user up
if (messages.length !== 0) { if (messages.length !== 0) {
var latest_id = messages[messages.length-1].id; var latest_id = messages[messages.length-1].id;
load_old_messages(latest_id + 1, "newer", 400, load_to_end); load_old_messages(latest_id + 1, "newer", 400, load_more);
return; return;
} }
// now start subscribing to updates // now start subscribing to updates
get_updates(); get_updates();
// backfill more messages after the user is idle
$(document).idle({'idle': 1000*10,
'onIdle': function () {
var first_id = message_array[0].id;
load_old_messages(first_id - 1, "older", 1000);
}});
} }
function load_around(messages) { load_old_messages(initial_pointer, "around", 400, load_more);
load_old_messages(initial_pointer, "around", 400, load_to_end);
}
load_around();
}); });
function restart_get_updates() { function restart_get_updates() {