email -> id: Make browser's filter for "sender" more robust.

This commit is contained in:
Steve Howell
2017-02-07 08:59:11 -08:00
committed by Tim Abbott
parent 64125a76e2
commit e6bcc01c33
3 changed files with 30 additions and 3 deletions

View File

@@ -21,7 +21,21 @@ var me = {
full_name: 'Me Myself',
};
var joe = {
email: 'joe@example.com',
user_id: 31,
full_name: 'joe',
};
var steve = {
email: 'STEVE@foo.com',
user_id: 32,
full_name: 'steve',
};
people.add(me);
people.add(joe);
people.add(steve);
people.initialize_current_user(me.user_id);
function assert_same_operators(result, terms) {
@@ -259,8 +273,8 @@ function get_predicate(operators) {
assert(!predicate({type: 'stream', id: 5, subject: 'dinner'}));
predicate = get_predicate([['sender', 'Joe@example.com']]);
assert(predicate({sender_email: 'JOE@example.com'}));
assert(!predicate({sender_email: 'steve@foo.com'}));
assert(predicate({sender_id: joe.user_id}));
assert(!predicate({sender_email: steve.user_id}));
predicate = get_predicate([['pm-with', 'Joe@example.com']]);
assert(predicate({type: 'private', reply_to: 'JOE@example.com'}));

View File

@@ -97,7 +97,7 @@ function message_matches_search_term(message, operator, operand) {
case 'sender':
return (message.sender_email.toLowerCase() === operand.toLowerCase());
return people.id_matches_email_operand(message.sender_id, operand);
case 'pm-with':
// TODO: use user_ids, not emails here

View File

@@ -54,6 +54,19 @@ exports.get_by_email = function (email) {
return person;
};
exports.id_matches_email_operand = function (user_id, email) {
var person = exports.get_by_email(email);
if (!person) {
// The user may type bad data into the search bar, so
// we don't complain too loud here.
blueslip.debug('User email operand unknown: ' + email);
return false;
}
return (person.user_id === user_id);
};
exports.update_email = function (user_id, new_email) {
var person = people_by_user_id_dict.get(user_id);
person.email = new_email;