Extract people.set_full_name().

This commit is contained in:
Steve Howell
2017-01-20 15:02:28 -08:00
committed by Tim Abbott
parent ee00d848b9
commit 28164d68b4
2 changed files with 15 additions and 6 deletions

View File

@@ -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');
}());

View File

@@ -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