From d938afaedc23e9f5364fef1f0a630f07c95b8f72 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 21 Apr 2017 14:49:33 -0700 Subject: [PATCH] Extract narrow.narrow_to_next_topic(). This borrows some code from a PR from Mahim Goyal. --- static/js/narrow.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/static/js/narrow.js b/static/js/narrow.js index 10aad666bd..183aa2deea 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -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) {