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

@@ -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);
});