From 28164d68b4c97832195a2e9eb057d118d1604ef7 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 20 Jan 2017 15:02:28 -0800 Subject: [PATCH] Extract people.set_full_name(). --- frontend_tests/node_tests/people.js | 6 ++++++ static/js/people.js | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index e1c6d07d09..222f054e54 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -96,6 +96,12 @@ initialize(); people.update({email: me.email, full_name: 'Me V2'}); assert.equal(people.my_full_name(), 'Me V2'); + + var person = people.get_by_email('me@example.com'); + people.set_full_name(person, 'Me the Third'); + assert.equal(people.my_full_name(), 'Me the Third'); + assert.equal(person.full_name, 'Me the Third'); + assert.equal(people.get_by_name('Me the Third').email, 'me@example.com'); }()); diff --git a/static/js/people.js b/static/js/people.js index 19e8acc89f..63e4b720af 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -299,6 +299,14 @@ exports.extract_people_from_message = function (message) { }); }; +exports.set_full_name = function (person_obj, new_full_name) { + if (people_by_name_dict.has(person_obj.full_name)) { + people_by_name_dict.del(person_obj.full_name); + } + people_by_name_dict.set(new_full_name, person_obj); + person_obj.full_name = new_full_name; +}; + exports.update = function update(person) { if (! people_dict.has(person.email)) { blueslip.error("Got update_person event for unexpected user", @@ -308,12 +316,7 @@ exports.update = function update(person) { var person_obj = people_dict.get(person.email); if (_.has(person, 'full_name')) { - 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; + exports.set_full_name(person_obj, person.full_name); activity.redraw(); // TODO: update sender names on messages