Fix time travel by adding new near: operator.

(imported from commit 727a68016090164b586cbe59e692676a00e8cd3a)
This commit is contained in:
Tim Abbott 2013-07-31 14:33:38 -04:00
parent 473a96fd1f
commit ed6f5ac470
4 changed files with 18 additions and 2 deletions

View File

@ -119,6 +119,9 @@ Filter.prototype = {
} }
break; break;
case 'near':
return true;
case 'stream': case 'stream':
if (message.type !== 'stream') if (message.type !== 'stream')
return false; return false;
@ -333,6 +336,7 @@ exports.activate = function (operators, opts) {
if (operators.length === 0) { if (operators.length === 0) {
return exports.deactivate(); return exports.deactivate();
} }
var filter = new Filter(operators);
opts = _.defaults({}, opts, { opts = _.defaults({}, opts, {
then_select_id: home_msg_list.selected_id(), then_select_id: home_msg_list.selected_id(),
@ -340,6 +344,10 @@ exports.activate = function (operators, opts) {
change_hash: true, change_hash: true,
trigger: 'unknown' 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 (opts.then_select_id === -1) {
// If we're loading the page via a narrowed URL, we may not // 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()); 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. // Save how far from the pointer the top of the message list was.
if (current_msg_list.selected_id() !== -1) { 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) { exports.by_time_travel = function (target_id, opts) {
opts = _.defaults({}, opts, {then_select_id: target_id}); opts = _.defaults({}, opts, {then_select_id: target_id});
narrow.activate([], opts); narrow.activate([["near", target_id]], opts);
}; };
exports.deactivate = function () { exports.deactivate = function () {

View File

@ -68,6 +68,9 @@ function describe(operators) {
case 'stream': case 'stream':
return 'Narrow to stream ' + operand; return 'Narrow to stream ' + operand;
case 'near':
return 'Narrow to messages around ' + operand;
case 'topic': case 'topic':
return 'Narrow to topic ' + operand; return 'Narrow to topic ' + operand;

View File

@ -52,6 +52,8 @@ function make_tab_data() {
} else if (filter.has_operand("is", "starred")) { } else if (filter.has_operand("is", "starred")) {
tabs.push(make_tab("Starred", hashed)); 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")) { } else if (filter.has_operand("is", "mentioned")) {
tabs.push(make_tab("Mentions", hashed)); tabs.push(make_tab("Mentions", hashed));
} else if (filter.has_operator("sender")) { } else if (filter.has_operator("sender")) {

View File

@ -713,6 +713,9 @@ class NarrowBuilder(object):
def by_sender(self, operand): def by_sender(self, operand):
return self.pQ(sender__email__iexact=operand) return self.pQ(sender__email__iexact=operand)
def by_near(self, operand):
return Q()
def by_pm_with(self, operand): def by_pm_with(self, operand):
if ',' in operand: if ',' in operand:
# Huddle # Huddle