Extract narrow.narrow_to_next_topic().

This borrows some code from a PR from Mahim Goyal.
This commit is contained in:
Steve Howell
2017-04-21 14:49:33 -07:00
committed by Tim Abbott
parent 73a1dd63d5
commit d938afaedc

View File

@@ -400,6 +400,31 @@ exports.stream_topic = function () {
};
};
exports.narrow_to_next_topic = function () {
var curr_info = exports.stream_topic();
if (!curr_info || !curr_info.stream) {
return;
}
var next_narrow = topic_generator.get_next_topic(
curr_info.stream,
curr_info.topic
);
if (!next_narrow) {
return;
}
var filter_expr = [
{operator: 'stream', operand: next_narrow.stream},
{operator: 'topic', operand: next_narrow.topic},
];
narrow.activate(filter_expr);
};
// Activate narrowing with a single operator.
// This is just for syntactic convenience.
exports.by = function (operator, operand, opts) {