Fix saving of pointer on server-initiated reload when narrowed.

Previously, we saved the current_msg_list selected id and then
restored it as the home_msg_list selected id, which could result in
the home view loading to the wrong place.

This takes some already bad code and makes it even more in need of
refactoring, but it does fix a pressing bug.  We should definitely
refactor both:

* the top of narrow.js
* the save/restore code in reload.js

after this, though.

(imported from commit bb2040219e4f545ba90bb04a696996cec2831484)
This commit is contained in:
Tim Abbott 2014-02-12 14:03:05 -05:00
parent f4c514fbf3
commit fcb8c106b1
3 changed files with 46 additions and 11 deletions

View File

@ -87,7 +87,7 @@ function activate_home_tab() {
}
// Returns true if this function performed a narrow
function do_hashchange() {
function do_hashchange(from_reload) {
// If window.location.hash changed because our app explicitly
// changed it, then we don't need to do anything.
// (This function only neds to jump into action if it changed
@ -119,12 +119,16 @@ function do_hashchange() {
activate_home_tab();
return false;
}
narrow.activate(operators, {
var narrow_opts = {
first_unread_from_server: true,
select_first_unread: true,
change_hash: false, // already set
trigger: 'hash change'
});
};
if (from_reload !== undefined && page_params.initial_narrow_pointer !== undefined) {
narrow_opts.from_reload = true;
}
narrow.activate(operators, narrow_opts);
ui.update_floating_recipient_bar();
return true;
case "":
@ -144,9 +148,9 @@ function do_hashchange() {
return false;
}
function hashchanged() {
function hashchanged(from_reload) {
changing_hash = true;
var ret = do_hashchange();
var ret = do_hashchange(from_reload);
changing_hash = false;
return ret;
}
@ -155,7 +159,7 @@ exports.initialize = function () {
// jQuery doesn't have a hashchange event, so we manually wrap
// our event handler
window.onhashchange = blueslip.wrap_function(hashchanged);
hashchanged();
hashchanged(true);
};
return exports;

View File

@ -118,6 +118,7 @@ function maybe_report_narrow_time(msg_list) {
exports.activate = function (raw_operators, opts) {
var start_time = new Date();
var was_narrowed_already = exports.active();
// most users aren't going to send a bunch of a out-of-narrow messages
// and expect to visit a list of narrows, so let's get these out of the way.
notifications.clear_compose_notifications();
@ -148,6 +149,7 @@ exports.activate = function (raw_operators, opts) {
then_select_id: home_msg_list.selected_id(),
select_first_unread: false,
first_unread_from_server: false,
from_reload: false,
change_hash: true,
trigger: 'unknown'
});
@ -167,7 +169,6 @@ exports.activate = function (raw_operators, opts) {
opts.select_first_unread = false;
}
var was_narrowed_already = exports.active();
var then_select_id = opts.then_select_id;
var then_select_offset;
@ -198,6 +199,14 @@ exports.activate = function (raw_operators, opts) {
current_msg_list.pre_narrow_offset = current_msg_list.selected_row().offset().top;
}
if (opts.first_unread_from_server && opts.from_reload) {
then_select_id = page_params.initial_narrow_pointer;
then_select_offset = page_params.initial_narrow_offset;
opts.first_unread_from_server = false;
opts.select_first_unread = false;
home_msg_list.pre_narrow_offset = page_params.initial_offset;
}
var msg_list = new MessageList('zfilt', current_filter, {
collapse_messages: ! current_filter.is_search(),
muting_enabled: muting_enabled,

View File

@ -33,13 +33,26 @@ function preserve_state(send_after_reload) {
url += "+msg=" + encodeURIComponent(compose.message_content());
}
var pointer = current_msg_list.selected_id();
var pointer = home_msg_list.selected_id();
if (pointer !== -1) {
url += "+pointer=" + pointer;
}
var row = current_msg_list.selected_row();
if (row.length > 0) {
url += "+offset=" + row.offset().top;
var row = home_msg_list.selected_row();
if (!narrow.active()) {
if (row.length > 0) {
url += "+offset=" + row.offset().top;
}
} else {
url += "+offset=" + home_msg_list.pre_narrow_offset;
var narrow_pointer = narrowed_msg_list.selected_id();
if (narrow_pointer !== -1) {
url += "+narrow_pointer=" + narrow_pointer;
}
var narrow_row = narrowed_msg_list.selected_row();
if (narrow_row.length > 0) {
url += "+narrow_offset=" + narrow_row.offset().top;
}
}
var oldhash = window.location.hash;
@ -97,6 +110,15 @@ $(function () {
page_params.initial_offset = offset;
}
var narrow_pointer = parseInt(vars.narrow_pointer, 10);
if (narrow_pointer) {
page_params.initial_narrow_pointer = narrow_pointer;
}
var narrow_offset = parseInt(vars.narrow_offset, 10);
if (narrow_offset) {
page_params.initial_narrow_offset = narrow_offset;
}
activity.new_user_input = false;
hashchange.changehash(vars.oldhash);
});