mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
narrow: Show non-existing user message for invalid emails.
Also adds people.is_valid_bulk_emails_for_compose and refactors narrow_state.set_compose_defaults to use it.
This commit is contained in:
committed by
Tim Abbott
parent
2ce7ef73e8
commit
d9b0ab2ae7
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -84,6 +84,9 @@
|
||||
<div id="non_existing_user" class="empty_feed_notice">
|
||||
<h4>{{ _("This user does not exist!") }}</h4>
|
||||
</div>
|
||||
<div id="non_existing_users" class="empty_feed_notice">
|
||||
<h4>{{ _("One or more of these users do not exist!") }}</h4>
|
||||
</div>
|
||||
<div id="nonsubbed_stream_narrow_message" class="empty_feed_notice">
|
||||
<h4>{{ _("You aren't subscribed to this stream and nobody has talked about that yet!") }}</h4>
|
||||
<div class="sub_button_row new-style">
|
||||
|
||||
Reference in New Issue
Block a user