diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js index 8df07738ea..3fc5398443 100644 --- a/frontend_tests/node_tests/narrow.js +++ b/frontend_tests/node_tests/narrow.js @@ -14,6 +14,18 @@ function set_filter(operators) { narrow_state.set_current_filter(new Filter(operators)); } +var alice = { + email: 'alice@example.com', + user_id: 23, + full_name: 'Alice Smith', +}; + +var ray = { + email: 'ray@example.com', + user_id: 22, + full_name: 'Raymond', +}; + run_test('stream_topic', () => { set_filter([['stream', 'Foo'], ['topic', 'Bar'], ['search', 'Yo']]); @@ -46,18 +58,7 @@ run_test('stream_topic', () => { }); run_test('uris', () => { - var ray = { - email: 'ray@example.com', - user_id: 22, - full_name: 'Raymond', - }; people.add(ray); - - var alice = { - email: 'alice@example.com', - user_id: 23, - full_name: 'Alice Smith', - }; people.add(alice); var uri = narrow.pm_with_uri(ray.email); @@ -122,10 +123,16 @@ run_test('show_empty_narrow_message', () => { assert.equal(hide_id,'.empty_feed_notice'); assert.equal(show_id, '#no_unread_narrow_message'); + set_filter([['pm-with', ['Yo']]]); + narrow.show_empty_narrow_message(); + assert.equal(hide_id,'.empty_feed_notice'); + assert.equal(show_id, '#non_existing_user'); + + people.add_in_realm(alice); set_filter([['pm-with', ['alice@example.com', 'Yo']]]); narrow.show_empty_narrow_message(); assert.equal(hide_id,'.empty_feed_notice'); - assert.equal(show_id, '#empty_narrow_multi_private_message'); + assert.equal(show_id, '#non_existing_users'); set_filter([['pm-with', 'alice@example.com']]); narrow.show_empty_narrow_message(); diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index a02868288a..d425fef260 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -700,6 +700,8 @@ run_test('initialize', () => { assert(people.is_valid_email_for_compose('alice@example.com')); assert(!people.is_valid_email_for_compose('retiree@example.com')); assert(!people.is_valid_email_for_compose('totally-bogus-username@example.com')); + assert(people.is_valid_bulk_emails_for_compose(['bot@example.com', 'alice@example.com'])); + assert(!people.is_valid_bulk_emails_for_compose(['not@valid.com', 'alice@example.com'])); assert(people.is_my_user_id(42)); var fetched_retiree = people.get_person_from_user_id(15); diff --git a/static/js/narrow.js b/static/js/narrow.js index b55cf2268e..bb178f997d 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -683,6 +683,12 @@ function pick_empty_narrow_banner() { // You are narrowed to empty search results. return $("#empty_search_narrow_message"); } else if (first_operator === "pm-with") { + if (!people.is_valid_bulk_emails_for_compose(first_operand.split(','))) { + if (first_operand.indexOf(',') === -1) { + return $("#non_existing_user"); + } + return $("#non_existing_users"); + } if (first_operand.indexOf(',') === -1) { // You have no private messages with this person return $("#empty_narrow_private_message"); diff --git a/static/js/narrow_state.js b/static/js/narrow_state.js index de665eeada..32dbf4a4ef 100644 --- a/static/js/narrow_state.js +++ b/static/js/narrow_state.js @@ -90,13 +90,7 @@ exports.set_compose_defaults = function () { if (single.has('pm-with')) { var private_message_recipient = single.get('pm-with'); - var is_valid_op = _.every(private_message_recipient.split(','), function (op) { - if (!people.is_valid_email_for_compose(op)) { - return false; - } - return true; - }); - if (is_valid_op) { + if (people.is_valid_bulk_emails_for_compose(private_message_recipient.split(','))) { opts.private_message_recipient = private_message_recipient; } } diff --git a/static/js/people.js b/static/js/people.js index 216d5f8d82..870e723962 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -571,6 +571,16 @@ exports.is_valid_email_for_compose = function (email) { return active_user_dict.has(person.user_id); }; +exports.is_valid_bulk_emails_for_compose = function (emails) { + // Returns false if at least one of the emails is invalid. + return _.every(emails, function (email) { + if (!people.is_valid_email_for_compose(email)) { + return false; + } + return true; + }); +}; + exports.get_active_user_for_email = function (email) { var person = people.get_by_email(email); if (!person) { diff --git a/templates/zerver/app/home.html b/templates/zerver/app/home.html index aa11d3ed22..d9673c7ae3 100644 --- a/templates/zerver/app/home.html +++ b/templates/zerver/app/home.html @@ -84,6 +84,9 @@

{{ _("This user does not exist!") }}

+
+

{{ _("One or more of these users do not exist!") }}

+

{{ _("You aren't subscribed to this stream and nobody has talked about that yet!") }}