Fix the selected message when narrowing to a stream that has no messages loaded

We would previously scroll you to the top of the just-loaded block of
messages

(imported from commit 520e5588aa078313649677663c7feea4ca1d7145)
This commit is contained in:
Zev Benjamin
2013-02-20 16:59:56 -05:00
parent 4c9e3a167e
commit 48e7fed00f
3 changed files with 22 additions and 13 deletions

View File

@@ -12,7 +12,7 @@
{{#if narrowed}} {{#if narrowed}}
<li> <li>
<a onclick="ui.hide_actions_popover(); narrow.activate([], {target_id: {{message.id}} });"> <a onclick="ui.hide_actions_popover(); narrow.activate([], {then_select_id: {{message.id}} });">
<i class="icon-time"></i> Narrow to messages around this time <i class="icon-time"></i> Narrow to messages around this time
</a> </a>
</li> </li>

View File

@@ -39,7 +39,13 @@ function parse_narrow(hash) {
var operand = decodeURIComponent(hash[i+1] || ''); var operand = decodeURIComponent(hash[i+1] || '');
operators.push([operator, operand]); operators.push([operator, operand]);
} }
narrow.activate(operators, {target_id: initial_pointer}); var new_selection;
if (current_msg_list.selected_id() !== -1) {
new_selection = current_msg_list.selected_id();
} else {
new_selection = initial_pointer;
}
narrow.activate(operators, {then_select_id: new_selection});
} }
// Returns true if this function performed a narrow // Returns true if this function performed a narrow

View File

@@ -210,11 +210,11 @@ function build_filter(operators_mixed_case) {
exports.activate = function (operators, opts) { exports.activate = function (operators, opts) {
opts = $.extend({}, { opts = $.extend({}, {
allow_collapse: true, allow_collapse: true,
target_id: current_msg_list.selected_id() then_select_id: current_msg_list.selected_id()
}, opts); }, opts);
var was_narrowed = exports.active(); var was_narrowed = exports.active();
var target_id = opts.target_id; var then_select_id = opts.then_select_id;
filter_function = build_filter(operators); filter_function = build_filter(operators);
current_operators = operators; current_operators = operators;
@@ -230,19 +230,22 @@ exports.activate = function (operators, opts) {
function maybe_select_closest() { function maybe_select_closest() {
if (! narrowed_msg_list.empty()) { if (! narrowed_msg_list.empty()) {
var id = narrowed_msg_list.closest_id(target_id); var id = narrowed_msg_list.closest_id(then_select_id);
narrowed_msg_list.select_id(id, {then_scroll: true}); narrowed_msg_list.select_id(id, {then_scroll: true});
} }
} }
// If our message id is not in range of the loaded message list, // Don't bother populating a message list when it won't contain
// we need to fetch the messages around the target message time // the message we want anyway
if (all_msg_list.get(target_id) === undefined) { if (all_msg_list.get(then_select_id) !== undefined) {
load_old_messages(target_id, 200, 200, narrowed_msg_list, function (messages) { add_messages(all_msg_list.all(), narrowed_msg_list);
}
if (narrowed_msg_list.empty()) {
load_old_messages(then_select_id, 200, 200, narrowed_msg_list, function (messages) {
maybe_select_closest(); maybe_select_closest();
}, true, false); }, true, false);
} else { } else {
add_messages(all_msg_list.all(), narrowed_msg_list);
maybe_select_closest(); maybe_select_closest();
} }
@@ -306,7 +309,7 @@ exports.by_subject = function (target_id) {
exports.activate([ exports.activate([
['stream', original.display_recipient], ['stream', original.display_recipient],
['subject', original.subject] ['subject', original.subject]
], { target_id: target_id }); ], { then_select_id: target_id });
}; };
// Called for the 'narrow by stream' hotkey. // Called for the 'narrow by stream' hotkey.
@@ -315,11 +318,11 @@ exports.by_recipient = function (target_id) {
var new_narrow, emails; var new_narrow, emails;
switch (message.type) { switch (message.type) {
case 'private': case 'private':
exports.by('pm-with', message.reply_to, { target_id: target_id }); exports.by('pm-with', message.reply_to, { then_select_id: target_id });
break; break;
case 'stream': case 'stream':
exports.by('stream', message.display_recipient, { target_id: target_id }); exports.by('stream', message.display_recipient, { then_select_id: target_id });
break; break;
} }
}; };