mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
people: Track users with same full names.
This commit exposes the function is_duplicate_full_name() that can be used to discern if we cannot identify a user just by their full name in the interface and have to use his user id as well to distinguish them from other users.
This commit is contained in:
committed by
Tim Abbott
parent
ef5940a864
commit
e497816a42
@@ -669,6 +669,35 @@ run_test('update_email_in_reply_to', () => {
|
||||
);
|
||||
});
|
||||
|
||||
initialize();
|
||||
|
||||
run_test('track_duplicate_full_names', () => {
|
||||
var stephen1 = {
|
||||
email: 'stephen-the-author@example.com',
|
||||
user_id: 601,
|
||||
full_name: 'Stephen King',
|
||||
};
|
||||
var stephen2 = {
|
||||
email: 'stephen-the-explorer@example.com',
|
||||
user_id: 602,
|
||||
full_name: 'Stephen King',
|
||||
};
|
||||
var maria = {
|
||||
email: 'athens@example.com',
|
||||
user_id: 603,
|
||||
full_name: 'Maria Athens',
|
||||
};
|
||||
people.add(stephen1);
|
||||
people.add(stephen2);
|
||||
people.add(maria);
|
||||
assert(people.is_duplicate_full_name('Stephen King'));
|
||||
assert(!people.is_duplicate_full_name('Maria Athens'));
|
||||
assert(!people.is_duplicate_full_name('Some Random Name'));
|
||||
people.set_full_name(stephen2, 'Stephen King JP');
|
||||
assert(!people.is_duplicate_full_name('Stephen King'));
|
||||
assert(!people.is_duplicate_full_name('Stephen King JP'));
|
||||
});
|
||||
|
||||
run_test('initialize', () => {
|
||||
people.init();
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ var people_by_user_id_dict;
|
||||
var active_user_dict;
|
||||
var cross_realm_dict;
|
||||
var pm_recipient_count_dict;
|
||||
var duplicate_full_name_data;
|
||||
var my_user_id;
|
||||
|
||||
// We have an init() function so that our automated tests
|
||||
@@ -27,6 +28,9 @@ exports.init = function () {
|
||||
active_user_dict = new Dict();
|
||||
cross_realm_dict = new Dict(); // keyed by user_id
|
||||
pm_recipient_count_dict = new Dict();
|
||||
|
||||
// The next Dict maintains a set of ids of people with same full names.
|
||||
duplicate_full_name_data = new Dict({fold_case: true});
|
||||
};
|
||||
|
||||
// WE INITIALIZE DATA STRUCTURES HERE!
|
||||
@@ -748,6 +752,27 @@ exports.get_rest_of_realm = function get_rest_of_realm() {
|
||||
return people_minus_you.sort(people_cmp);
|
||||
};
|
||||
|
||||
exports.track_duplicate_full_name = function (full_name, user_id, to_remove) {
|
||||
var ids = new Dict();
|
||||
if (duplicate_full_name_data.has(full_name)) {
|
||||
ids = duplicate_full_name_data.get(full_name);
|
||||
}
|
||||
if (!to_remove && user_id) {
|
||||
ids.set(user_id);
|
||||
}
|
||||
if (to_remove && user_id && ids.has(user_id)) {
|
||||
ids.del(user_id);
|
||||
}
|
||||
duplicate_full_name_data.set(full_name,ids);
|
||||
};
|
||||
|
||||
exports.is_duplicate_full_name = function (full_name) {
|
||||
if (duplicate_full_name_data.has(full_name)) {
|
||||
return duplicate_full_name_data.get(full_name).keys().length > 1;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.add = function add(person) {
|
||||
if (person.user_id) {
|
||||
people_by_user_id_dict.set(person.user_id, person);
|
||||
@@ -761,6 +786,7 @@ exports.add = function add(person) {
|
||||
blueslip.warn('No user_id provided for ' + person.email);
|
||||
}
|
||||
|
||||
exports.track_duplicate_full_name(person.full_name, person.user_id);
|
||||
people_dict.set(person.email, person);
|
||||
people_by_name_dict.set(person.full_name, person);
|
||||
};
|
||||
@@ -854,6 +880,9 @@ 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);
|
||||
}
|
||||
// Remove previous and add new full name to the duplicate full name tracker.
|
||||
exports.track_duplicate_full_name(person_obj.full_name, person_obj.user_id, true);
|
||||
exports.track_duplicate_full_name(new_full_name, person_obj.user_id);
|
||||
people_by_name_dict.set(new_full_name, person_obj);
|
||||
person_obj.full_name = new_full_name;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user