From ed6f5ac4707e406f7996de897ed7ad3738eae88e Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 31 Jul 2013 14:33:38 -0400 Subject: [PATCH] Fix time travel by adding new near: operator. (imported from commit 727a68016090164b586cbe59e692676a00e8cd3a) --- static/js/narrow.js | 12 ++++++++++-- static/js/search.js | 3 +++ static/js/tab_bar.js | 2 ++ zephyr/views.py | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/static/js/narrow.js b/static/js/narrow.js index 92e2b98acd..07c5e29320 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -119,6 +119,9 @@ Filter.prototype = { } break; + case 'near': + return true; + case 'stream': if (message.type !== 'stream') return false; @@ -333,6 +336,7 @@ exports.activate = function (operators, opts) { if (operators.length === 0) { return exports.deactivate(); } + var filter = new Filter(operators); opts = _.defaults({}, opts, { then_select_id: home_msg_list.selected_id(), @@ -340,6 +344,10 @@ exports.activate = function (operators, opts) { change_hash: true, trigger: 'unknown' }); + if (filter.has_operator("near")) { + opts.then_select_id = filter.operands("near")[0]; + opts.select_first_unread = false; + } if (opts.then_select_id === -1) { // If we're loading the page via a narrowed URL, we may not @@ -366,7 +374,7 @@ exports.activate = function (operators, opts) { message_tour.start_tour(current_msg_list.selected_id()); } - current_filter = new Filter(operators); + current_filter = filter; // Save how far from the pointer the top of the message list was. if (current_msg_list.selected_id() !== -1) { @@ -504,7 +512,7 @@ exports.by_recipient = function (target_id, opts) { exports.by_time_travel = function (target_id, opts) { opts = _.defaults({}, opts, {then_select_id: target_id}); - narrow.activate([], opts); + narrow.activate([["near", target_id]], opts); }; exports.deactivate = function () { diff --git a/static/js/search.js b/static/js/search.js index 076b613769..b2ae93efae 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -68,6 +68,9 @@ function describe(operators) { case 'stream': return 'Narrow to stream ' + operand; + case 'near': + return 'Narrow to messages around ' + operand; + case 'topic': return 'Narrow to topic ' + operand; diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js index 2b2ce52235..f3b0e74546 100644 --- a/static/js/tab_bar.js +++ b/static/js/tab_bar.js @@ -52,6 +52,8 @@ function make_tab_data() { } else if (filter.has_operand("is", "starred")) { tabs.push(make_tab("Starred", hashed)); + } else if (filter.has_operator("near")) { + tabs.push(make_tab("Near " + filter.operands("near")[0], hashed)); } else if (filter.has_operand("is", "mentioned")) { tabs.push(make_tab("Mentions", hashed)); } else if (filter.has_operator("sender")) { diff --git a/zephyr/views.py b/zephyr/views.py index a09761f673..e9ace35da8 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -713,6 +713,9 @@ class NarrowBuilder(object): def by_sender(self, operand): return self.pQ(sender__email__iexact=operand) + def by_near(self, operand): + return Q() + def by_pm_with(self, operand): if ',' in operand: # Huddle