From bcd0bb80e19964c91c74a011e2c339094c113f71 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Tue, 12 Feb 2013 17:38:08 -0500 Subject: [PATCH] Remove narrow.target() and pass the target explicitly This fixes #861 (imported from commit 244deaae84db2e8c7c5ce3f9b9b25cc33bdd234d) --- .../jstemplates/actions_popover_content.html | 6 ++-- zephyr/static/js/hotkey.js | 3 +- zephyr/static/js/narrow.js | 28 ++++++------------- zephyr/static/js/ui.js | 6 ++-- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/zephyr/jstemplates/actions_popover_content.html b/zephyr/jstemplates/actions_popover_content.html index 2812d2a082..64333d4c8a 100644 --- a/zephyr/jstemplates/actions_popover_content.html +++ b/zephyr/jstemplates/actions_popover_content.html @@ -12,7 +12,7 @@ {{#if narrowed}}
  • - + Narrow to messages around this time
  • @@ -20,14 +20,14 @@ {{#if message.is_stream}}
  • - + Narrow to this subject on stream {{message.display_recipient}}
  • {{else}}
  • - + Narrow to this private message conversation diff --git a/zephyr/static/js/hotkey.js b/zephyr/static/js/hotkey.js index e4f586ae2c..1badeec08d 100644 --- a/zephyr/static/js/hotkey.js +++ b/zephyr/static/js/hotkey.js @@ -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; } diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index 1b35152003..7f8103451f 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -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; } }; diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index 6aaf9baed1..41e70dbdc3 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -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) {