diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index ad1f12b29b..4692a93321 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -69,7 +69,7 @@ var globals = + ' select_message select_message_by_id' + ' scroll_to_selected disable_pointer_movement get_private_message_recipient' + ' load_old_messages' - + ' selected_message selected_message_id' + + ' selected_message selected_message_id persistent_message_id' + ' at_top_of_viewport at_bottom_of_viewport' + ' viewport' + ' load_more_messages reset_load_more_status have_scrolled_away_from_top' diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index 06015d8f6f..229c07af47 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -2,9 +2,6 @@ var narrow = (function () { var exports = {}; -// For tracking where you were before you narrowed. -var persistent_message_id = 0; - // For narrowing based on a particular message var target_id = 0; @@ -214,11 +211,6 @@ exports.activate = function (operators, opts) { allow_collapse = opts.allow_collapse; - // Your pointer isn't changed when narrowed. - if (! was_narrowed) { - persistent_message_id = selected_message_id; - } - // Before we clear the table, check if anything was highlighted. var highlighted = search.something_is_highlighted(); diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 688e476668..25fdf0cccf 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -6,6 +6,9 @@ var people_dict = {}; var viewport = $(window); +// For tracking where you are in the home view +var persistent_message_id = -1; + var selected_message_id = -1; /* to be filled in on document.ready */ var selected_message = $(); /* = rows.get(selected_message_id) */ var get_updates_params = { @@ -155,6 +158,7 @@ function send_pointer_update() { } $(function () { + persistent_message_id = initial_pointer; furthest_read = initial_pointer; server_furthest_read = initial_pointer; $(document).idle({idle: 1000, @@ -168,13 +172,17 @@ function update_selected_message(message, opts) { message.addClass(cls); var new_selected_id = rows.id(message); - if (! narrow.active() && lurk_stream === undefined && new_selected_id > furthest_read) - { - // Narrowing is a temporary view on top of the home view and - // doesn't permanently affect where you are. - // Similarly, lurk mode does not affect your pointer. - furthest_read = new_selected_id; + // Narrowing is a temporary view on top of the home view and + // doesn't affect your pointer in the home view. + // Similarly, lurk mode does not affect your pointer. + if (! narrow.active() && lurk_stream === undefined) { + persistent_message_id = new_selected_id; + if (new_selected_id > furthest_read) + { + furthest_read = new_selected_id; + } } + selected_message_id = new_selected_id; selected_message = message; } @@ -484,11 +492,12 @@ function add_messages(messages, add_to_home) { messages = $.map(messages, add_message_metadata); if (add_to_home) { + // persistent_message_id is guaranteed to be between the top and bottom var top_messages_home = $.grep(messages, function (elem, idx) { - return (elem.id < selected_message_id && ! message_in_table.zhome[elem.id]); + return (elem.id < persistent_message_id && ! message_in_table.zhome[elem.id]); }); var bottom_messages_home = $.grep(messages, function (elem, idx) { - return (elem.id >= selected_message_id && ! message_in_table.zhome[elem.id]); + return (elem.id >= persistent_message_id && ! message_in_table.zhome[elem.id]); }); message_array = top_messages_home.concat(message_array).concat(bottom_messages_home); add_to_table(top_messages_home, 'zhome', narrow.in_home, "top", true); @@ -499,6 +508,7 @@ function add_messages(messages, add_to_home) { } if (narrow.active()) { + // selected_message_id is guaranteed to be between the top and bottom var top_messages_narrow = $.grep(messages, function (elem, idx) { return (elem.id < selected_message_id && ! message_in_table.zfilt[elem.id]); });