From 35cc206dcc4cbd563ac1a1d262c4c6e7abb92f4b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 9 Feb 2018 17:04:20 -0500 Subject: [PATCH] Add narrow.narrow_to_next_pm_string(). This helper function will allow us to cycle through PM narrows that are unread, once we map it to a hotkey and/or other UI. (We intend to make something like the "n" key for topics, but that works on PM narrows instead.) --- static/js/narrow.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/static/js/narrow.js b/static/js/narrow.js index a3ad1d8b84..3305f4a169 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -362,6 +362,31 @@ exports.narrow_to_next_topic = function () { }; +exports.narrow_to_next_pm_string = function () { + var curr_pm = narrow_state.pm_string(); + + var next_pm = topic_generator.get_next_unread_pm_string(curr_pm); + + if (!next_pm) { + return; + } + + // Hopefully someday we can narrow by user_ids_string instead of + // mapping back to emails. + var pm_with = people.user_ids_string_to_emails_string(next_pm); + + var filter_expr = [ + {operator: 'pm-with', operand: pm_with}, + ]; + + var opts = { + select_first_unread: true, + }; + + exports.activate(filter_expr, opts); +}; + + // Activate narrowing with a single operator. // This is just for syntactic convenience. exports.by = function (operator, operand, opts) {