diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index 1a916e9f05..10f95da62c 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -60,8 +60,21 @@ global.people.add({ assert_typeahead_equals("test no@o", false); assert_typeahead_equals("test :-P", false); - var all_items = [{ special_item_text: 'all (Notify everyone)', email: 'all', pm_recipient_count: Infinity, full_name: 'all' }, - { special_item_text: 'everyone (Notify everyone)', email: 'everyone', full_name: 'everyone' }]; + var all_items = [ + { + special_item_text: 'all (Notify everyone)', + email: 'all', + pm_recipient_count: Infinity, + full_name: 'all', + }, + { + special_item_text: 'everyone (Notify everyone)', + email: 'everyone', + pm_recipient_count: Infinity, + full_name: 'everyone', + }, + ]; + var people_with_all = global.people.get_realm_persons().concat(all_items); assert_typeahead_equals("test @o", people_with_all); diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index 844083967f..1470b9d876 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -135,11 +135,11 @@ initialize(); initialize(); (function test_recipient_counts() { - var email = 'anybody@example.com'; - assert.equal(people.get_recipient_count({email: email}), 0); - people.incr_recipient_count(email); - people.incr_recipient_count(email); - assert.equal(people.get_recipient_count({email: email}), 2); + var user_id = 99; + assert.equal(people.get_recipient_count({id: user_id}), 0); + people.incr_recipient_count(user_id); + people.incr_recipient_count(user_id); + assert.equal(people.get_recipient_count({user_id: user_id}), 2); assert.equal(people.get_recipient_count({pm_recipient_count: 5}), 5); }()); diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index a8f13b3057..47bea2a49b 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -286,6 +286,7 @@ exports.compose_content_begins_typeahead = function (query) { var everyone_item = { special_item_text: "everyone (Notify everyone)", email: "everyone", + pm_recipient_count: Infinity, full_name: "everyone", }; var persons = people.get_realm_persons(); diff --git a/static/js/people.js b/static/js/people.js index 0e05620ee8..8e6905e16c 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -21,7 +21,7 @@ exports.init = function () { // People in this realm realm_people_dict = new Dict({fold_case: true}); cross_realm_dict = new Dict({fold_case: true}); - pm_recipient_count_dict = new Dict({fold_case: true}); + pm_recipient_count_dict = new Dict(); }; // WE INITIALIZE DATA STRUCTURES HERE! @@ -249,14 +249,15 @@ exports.get_recipient_count = function (person) { return person.pm_recipient_count; } - var count = pm_recipient_count_dict.get(person.email); + var user_id = person.user_id || person.id; + var count = pm_recipient_count_dict.get(user_id); return count || 0; }; -exports.incr_recipient_count = function (email) { - var old_count = pm_recipient_count_dict.get(email) || 0; - pm_recipient_count_dict.set(email, old_count + 1); +exports.incr_recipient_count = function (user_id) { + var old_count = pm_recipient_count_dict.get(user_id) || 0; + pm_recipient_count_dict.set(user_id, old_count + 1); }; exports.filter_people_by_search_terms = function (users, search_terms) { @@ -386,10 +387,13 @@ exports.extract_people_from_message = function (message) { // Add new people involved in this message to the people list _.each(involved_people, function (person) { if (!person.unknown_local_echo_user) { + + var user_id = person.user_id || person.id; + if (! exports.get_by_email(person.email)) { exports.add({ email: person.email, - user_id: person.user_id || person.id, + user_id: user_id, full_name: person.full_name, is_admin: person.is_realm_admin || false, is_bot: person.is_bot || false, @@ -398,7 +402,7 @@ exports.extract_people_from_message = function (message) { if (message.type === 'private' && message.sent_by_me) { // Track the number of PMs we've sent to this person to improve autocomplete - exports.incr_recipient_count(person.email); + exports.incr_recipient_count(user_id); } } });