diff --git a/web/src/filter.js b/web/src/filter.js index 47eabad331..a9ebd7662d 100644 --- a/web/src/filter.js +++ b/web/src/filter.js @@ -575,6 +575,9 @@ export class Filter { if (_.isEqual(term_types, ["streams-public"])) { return true; } + if (_.isEqual(term_types, ["sender"])) { + return true; + } return false; } @@ -714,6 +717,23 @@ export class Filter { // can have the same return type as other cases. return names.join(", "); } + if (term_types.length === 1 && _.isEqual(term_types, ["sender"])) { + const email = this.operands("sender")[0]; + const user = people.get_by_email(email); + let sender = email; + if (user) { + if (people.is_my_user_id(user.user_id)) { + return $t({defaultMessage: "Messages sent by you"}); + } + sender = user.full_name; + } + return $t( + {defaultMessage: "Messages sent by {sender}"}, + { + sender, + }, + ); + } if (term_types.length === 1) { switch (term_types[0]) { case "in-home": diff --git a/web/src/narrow.js b/web/src/narrow.js index ee50213338..7dba6791fa 100644 --- a/web/src/narrow.js +++ b/web/src/narrow.js @@ -120,6 +120,22 @@ export function compute_narrow_title(filter) { return $t({defaultMessage: "Invalid user"}); } + if (filter.has_operator("sender")) { + const user = people.get_by_email(filter.operands("sender")[0]); + if (user) { + if (people.is_my_user_id(user.user_id)) { + return $t({defaultMessage: "Messages sent by you"}); + } + return $t( + {defaultMessage: "Messages sent by {sender}"}, + { + sender: user.full_name, + }, + ); + } + return $t({defaultMessage: "Invalid user"}); + } + return filter_title; } diff --git a/web/tests/filter.test.js b/web/tests/filter.test.js index d8aaa149f0..48a4b96196 100644 --- a/web/tests/filter.test.js +++ b/web/tests/filter.test.js @@ -1522,6 +1522,7 @@ test("navbar_helpers", () => { test_redirect_url_with_search(test_case); } + const sender = [{operator: "sender", operand: joe.email}]; const in_home = [{operator: "in", operand: "home"}]; const in_all = [{operator: "in", operand: "all"}]; const is_starred = [{operator: "is", operand: "starred"}]; @@ -1563,6 +1564,13 @@ test("navbar_helpers", () => { ]; const test_cases = [ + { + operator: sender, + is_common_narrow: true, + icon: undefined, + title: "translated: Messages sent by " + joe.full_name, + redirect_url_with_search: "/#narrow/sender/" + joe.user_id + "-joe", + }, { operator: is_starred, is_common_narrow: true, @@ -1722,12 +1730,12 @@ test("navbar_helpers", () => { { operator: sender_me, redirect_url_with_search: "/#narrow/sender/" + me.user_id + "-Me-Myself", - is_common_narrow: false, + is_common_narrow: true, }, { operator: sender_joe, redirect_url_with_search: "/#narrow/sender/" + joe.user_id + "-joe", - is_common_narrow: false, + is_common_narrow: true, }, ]; diff --git a/web/tests/narrow.test.js b/web/tests/narrow.test.js index ebf41285a9..fb232797e7 100644 --- a/web/tests/narrow.test.js +++ b/web/tests/narrow.test.js @@ -786,7 +786,7 @@ run_test("narrow_compute_title", ({override}) => { assert.equal(narrow.compute_narrow_title(filter), "translated: Search results"); filter = new Filter([{operator: "sender", operand: "me"}]); - assert.equal(narrow.compute_narrow_title(filter), "translated: Search results"); + assert.equal(narrow.compute_narrow_title(filter), "translated: Messages sent by you"); // Stream narrows const sub = {