Remove narrow.target() and pass the target explicitly

This fixes #861

(imported from commit 244deaae84db2e8c7c5ce3f9b9b25cc33bdd234d)
This commit is contained in:
Zev Benjamin 2013-02-12 17:38:08 -05:00
parent bedf1dd563
commit bcd0bb80e1
4 changed files with 15 additions and 28 deletions

View File

@ -12,7 +12,7 @@
{{#if narrowed}}
<li>
<a onclick="narrow.from_popover({{message.id}}); narrow.activate([]);">
<a onclick="narrow.from_popover(); narrow.activate([], {target_id: {{message.id}} });">
<i class="icon-time"></i> Narrow to messages around this time
</a>
</li>
@ -20,14 +20,14 @@
{{#if message.is_stream}}
<li>
<a onclick="narrow.from_popover({{message.id}}); narrow.by_subject();">
<a onclick="narrow.from_popover(); narrow.by_subject({{message.id}});">
<i class="icon-bullhorn"></i>
Narrow to this subject on stream <b>{{message.display_recipient}}</b>
</a>
</li>
{{else}}
<li>
<a onclick="narrow.from_popover({{message.id}}); narrow.by_recipient();">
<a onclick="narrow.from_popover(); narrow.by_recipient({{message.id}});">
<i class="icon-user"></i>
Narrow to this private message conversation
</a>

View File

@ -79,8 +79,7 @@ function process_hotkey(e) {
}
if (narrow_hotkeys.hasOwnProperty(code)) {
narrow.target(selected_message_id);
narrow_hotkeys[code]();
narrow_hotkeys[code](selected_message_id);
return true;
}

View File

@ -2,9 +2,6 @@ var narrow = (function () {
var exports = {};
// For narrowing based on a particular message
var target_id = 0;
var filter_function = false;
var current_operators = false;
@ -201,10 +198,12 @@ function build_filter(operators_mixed_case) {
exports.activate = function (operators, opts) {
opts = $.extend({}, {
allow_collapse: true
allow_collapse: true,
target_id: selected_message_id
}, opts);
var was_narrowed = exports.active();
var target_id = opts.target_id;
filter_function = build_filter(operators);
current_operators = operators;
@ -278,40 +277,31 @@ exports.from_popover = function (message_id) {
exports.target(message_id);
};
// This is the message we're about to select, within the narrowed view.
// But it won't necessarily be selected once the user un-narrows.
//
// FIXME: We probably don't need this variable, selected_message_id, *and*
// persistent_message_id.
exports.target = function (id) {
target_id = id;
};
exports.by_subject = function () {
exports.by_subject = function (target_id) {
var original = message_dict[target_id];
if (original.type !== 'stream') {
// Only stream messages have subjects, but the
// user wants us to narrow in some way.
exports.by_recipient();
exports.by_recipient(target_id);
return;
}
exports.activate([
['stream', original.display_recipient],
['subject', original.subject]
]);
], { target_id: target_id });
};
// Called for the 'narrow by stream' hotkey.
exports.by_recipient = function () {
exports.by_recipient = function (target_id) {
var message = message_dict[target_id];
var new_narrow, emails;
switch (message.type) {
case 'private':
exports.by('pm-with', message.reply_to);
exports.by('pm-with', message.reply_to, { target_id: target_id });
break;
case 'stream':
exports.by('stream', message.display_recipient);
exports.by('stream', message.display_recipient, { target_id: target_id });
break;
}
};

View File

@ -828,14 +828,12 @@ $(function () {
$("#home").on("click", ".narrows_by_recipient", function (e) {
var row = $(this).closest(".recipient_row");
narrow.target(rows.id(row));
narrow.by_recipient();
narrow.by_recipient(rows.id(row));
});
$("#home").on("click", ".narrows_by_subject", function (e) {
var row = $(this).closest(".recipient_row");
narrow.target(rows.id(row));
narrow.by_subject();
narrow.by_subject(rows.id(row));
});
$("#subscriptions_table").on("mouseover", ".subscription_header", function (e) {