diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 82ebe95bbb..bf4ec69bd8 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -1481,6 +1481,15 @@ test("navbar_helpers", () => { // not common narrows, but used for browser title updates const is_alerted = [{operator: "is", operand: "alerted"}]; const is_unread = [{operator: "is", operand: "unread"}]; + const stream_topic_near = [ + {operator: "stream", operand: "foo"}, + {operator: "topic", operand: "bar"}, + {operator: "near", operand: "12"}, + ]; + const pm_with_near = [ + {operator: "pm-with", operand: "joe@example.com"}, + {operator: "near", operand: "12"}, + ]; const test_cases = [ { @@ -1615,6 +1624,20 @@ test("navbar_helpers", () => { title: "translated: Unread messages", redirect_url_with_search: "#", }, + { + operator: stream_topic_near, + is_common_narrow: false, + icon: "hashtag", + title: "Foo", + redirect_url_with_search: "#", + }, + { + operator: pm_with_near, + is_common_narrow: false, + icon: "envelope", + title: properly_separated_names([joe.full_name]), + redirect_url_with_search: "#", + }, ]; for (const test_case of test_cases) { diff --git a/static/js/filter.js b/static/js/filter.js index 1576e27779..0a1a6f892b 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -672,6 +672,23 @@ export class Filter { } return this._sub.name; } + if ( + (term_types.length === 2 && _.isEqual(term_types, ["pm-with", "near"])) || + (term_types.length === 1 && _.isEqual(term_types, ["pm-with"])) + ) { + const emails = this.operands("pm-with")[0].split(","); + const names = emails.map((email) => { + if (!people.get_by_email(email)) { + return email; + } + return people.get_by_email(email).full_name; + }); + + // We use join to handle the addition of a comma and space after every name + // and also to ensure that we return a string and not an array so that we + // can have the same return type as other cases. + return names.join(", "); + } if (term_types.length === 1) { switch (term_types[0]) { case "in-home": @@ -692,20 +709,6 @@ export class Filter { return $t({defaultMessage: "Mentions"}); case "is-private": return $t({defaultMessage: "Private messages"}); - case "pm-with": { - const emails = this.operands("pm-with")[0].split(","); - const names = emails.map((email) => { - if (!people.get_by_email(email)) { - return email; - } - return people.get_by_email(email).full_name; - }); - - // We use join to handle the addition of a comma and space after every name - // and also to ensure that we return a string and not an array so that we - // can have the same return type as other cases. - return names.join(", "); - } case "is-resolved": return $t({defaultMessage: "Topics marked as resolved"}); // These cases return false for is_common_narrow, and therefore are not