From 651382b313a60650014537d4a94a253a89bd88a2 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 3 Jan 2014 18:17:09 -0600 Subject: [PATCH] Keep track of people by full name for client-side usermentions (imported from commit 6c88b53913ed7eca7d75ad0d2263d63e277ee65c) --- static/js/zulip.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/static/js/zulip.js b/static/js/zulip.js index 0556464d19..9c3c58776c 100644 --- a/static/js/zulip.js +++ b/static/js/zulip.js @@ -12,9 +12,10 @@ var home_msg_list = new MessageList('zhome', var narrowed_msg_list; var current_msg_list = home_msg_list; -// The following two Dicts point to the same objects +// The following three Dicts point to the same objects // All people we've seen var people_dict = new Dict(); +var people_by_name_dict = new Dict(); // People in this realm var realm_people_dict = new Dict(); @@ -55,6 +56,7 @@ var waiting_on_browser_scroll = true; function add_person(person, in_realm) { page_params.people_list.push(person); people_dict.set(person.email, person); + people_by_name_dict.set(person.full_name, person); person.pm_recipient_count = 0; } @@ -72,6 +74,7 @@ function remove_person(person) { } } people_dict.del(person.email); + people_by_name_dict.del(person.full_name); realm_people_dict.del(person.email); } @@ -86,7 +89,12 @@ function update_person(person) { {email: person.email}); return; } - people_dict.get(person.email).full_name = person.full_name; + var person_obj = people_dict.get(person.email); + if (people_by_name_dict.has(person_obj.full_name)) { + people_by_name_dict.set(person.full_name, person_obj); + people_by_name_dict.del(person_obj.full_name); + } + person_obj.full_name = person.full_name; // This should be the same object, but... realm_people_dict.get(person.email).full_name = person.full_name; for (i = 0; i < page_params.people_list.length; i++) { @@ -1243,6 +1251,7 @@ function consider_bankruptcy() { _.each(page_params.people_list, function (person) { people_dict.set(person.email, person); + people_by_name_dict.set(person.full_name, person); realm_people_dict.set(person.email, person); person.pm_recipient_count = 0; });