people: Deduplicate get_full_names logic.

Share code between `safe_full_names` and `get_display_full_names`
functions, and rename `safe_full_names` to `get_full_names_for_poll`,
because that was the only place where this was used earlier.

This also has the nice side effect of showing "Muted user" instead
of the muted username in poll results.
This commit is contained in:
Abhijeet Prasad Bodas
2021-05-11 20:03:52 +05:30
committed by Tim Abbott
parent c637994612
commit 421cf05176
4 changed files with 6 additions and 13 deletions

View File

@@ -401,9 +401,9 @@ test_people("get_recipients", () => {
assert.equal(people.get_recipients("30,32"), "Isaac Newton");
});
test_people("safe_full_names", () => {
test_people("get_full_names_for_poll_option", () => {
people.add_active_user(isaac);
const names = people.safe_full_names([me.user_id, isaac.user_id]);
const names = people.get_full_names_for_poll_option([me.user_id, isaac.user_id]);
assert.equal(names, "Me Myself, Isaac Newton");
});

View File

@@ -39,7 +39,7 @@ run_test("PollData my question", () => {
is_my_poll,
question,
options: [],
comma_separated_names: people.safe_full_names,
comma_separated_names: people.get_full_names_for_poll_option,
report_error_function: blueslip.warn,
});

View File

@@ -298,15 +298,8 @@ export function email_list_to_user_ids_string(emails) {
return user_ids.join(",");
}
export function safe_full_names(user_ids) {
let names = user_ids.map((user_id) => {
const person = people_by_user_id_dict.get(user_id);
return person && person.full_name;
});
names = names.filter(Boolean);
return names.join(", ");
export function get_full_names_for_poll_option(user_ids) {
return get_display_full_names(user_ids).join(", ");
}
export function get_display_full_names(user_ids) {

View File

@@ -19,7 +19,7 @@ export function activate({
is_my_poll,
question,
options,
comma_separated_names: people.safe_full_names,
comma_separated_names: people.get_full_names_for_poll_option,
report_error_function: blueslip.warn,
});