diff --git a/static/js/zulip.js b/static/js/zulip.js index f1486b41b3..fb9ca4e07e 100644 --- a/static/js/zulip.js +++ b/static/js/zulip.js @@ -1205,6 +1205,22 @@ function fast_forward_pointer() { }); } +function consider_bankruptcy() { + if (!page_params.furthest_read_time) { + // We've never read a message. + return; + } + + var now = new XDate(true).getTime() / 1000; + if ((page_params.unread_count > 500) && + (now - page_params.furthest_read_time > 60 * 60 * 24 * 2)) { // 2 days. + var unread_info = templates.render('bankruptcy_modal', + {"unread_count": page_params.unread_count}); + $('#bankruptcy-unread-count').html(unread_info); + $('#bankruptcy').modal('show'); + } +} + function main() { _.each(page_params.people_list, function (person) { people_dict.set(person.email, person); @@ -1224,6 +1240,9 @@ function main() { furthest_read = page_params.initial_pointer; server_furthest_read = page_params.initial_pointer; + // Before trying to load messages: is this user way behind? + consider_bankruptcy(); + // We only send pointer updates when the user has been idle for a // short while to avoid hammering the server $(document).idle({idle: 1000, @@ -1262,22 +1281,6 @@ function main() { // get the initial message list function load_more(messages) { - - // Before trying to load anything: is this user way behind? - var last_read_message = home_msg_list.get(home_msg_list.closest_id(page_params.initial_pointer)); - if (last_read_message !== undefined) { - var now = new XDate().getTime() / 1000; - var num_unread = unread.get_counts().home_unread_messages; - - if ((num_unread > 500) && - (now - last_read_message.timestamp > 60 * 60 * 24 * 2)) { // 2 days. - var unread_info = templates.render('bankruptcy_modal', - {"unread_count": num_unread}); - $('#bankruptcy-unread-count').html(unread_info); - $('#bankruptcy').modal('show'); - } - } - // If we received the initially selected message, select it on the client side, // but not if the user has already selected another one during load. //