Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Extract people.get_display_full_names.
Abhijeet Prasad Bodas5bcc96508dcd
diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.jsindex 0b7c96575e3..f8ac4f1a935 100644--- a/frontend_tests/node_tests/people.js+++ b/frontend_tests/node_tests/people.js@@ -405,6 +405,23 @@ test_people("safe_full_names", () => {assert.equal(names, "Me Myself, Isaac Newton");});+test_people("get_display_full_names", () => {+ people.initialize_current_user(me.user_id);+ people.add_active_user(steven);+ people.add_active_user(bob);+ people.add_active_user(charles);+ const names = people.get_display_full_names([+ me.user_id,+ steven.user_id,+ bob.user_id,+ charles.user_id,+ ]);++ // This doesn't do anything special for the current user. The caller has+ // to take care of such cases and do the appropriate.+ assert.deepEqual(names, ["Me Myself", "Steven", "Bob van Roberts", "Charles Dickens"]);+});+test_people("my_custom_profile_data", () => {const person = people.get_by_email(me.email);person.profile_data = {3: "My address", 4: "My phone number"};diff --git a/static/js/message_store.js b/static/js/message_store.jsindex 983e17812b5..feaa994ccdc 100644--- a/static/js/message_store.js+++ b/static/js/message_store.js@@ -53,16 +53,7 @@ export function get_pm_emails(message) {export function get_pm_full_names(message) {const user_ids = people.pm_with_user_ids(message);- const names = user_ids- .map((user_id) => {- const person = people.get_by_user_id(user_id);- if (!person) {- blueslip.error("Unknown user id " + user_id);- return "?";- }- return person.full_name;- })- .sort();+ const names = people.get_display_full_names(user_ids).sort();return names.join(", ");}diff --git a/static/js/people.js b/static/js/people.jsindex 6a7a746bfbc..200ac2e78cb 100644--- a/static/js/people.js+++ b/static/js/people.js@@ -308,6 +308,18 @@ export function safe_full_names(user_ids) {return names.join(", ");}+export function get_display_full_names(user_ids) {+ return user_ids.map((user_id) => {+ const person = get_by_user_id(user_id);+ if (!person) {+ blueslip.error("Unknown user id " + user_id);+ return "?";+ }++ return person.full_name;+ });+}+export function get_full_name(user_id) {return people_by_user_id_dict.get(user_id).full_name;}diff --git a/static/js/reactions.js b/static/js/reactions.jsindex 7f430b948c5..5037890cb0b 100644--- a/static/js/reactions.js+++ b/static/js/reactions.js@@ -154,9 +154,9 @@ export function process_reaction_click(message_id, local_id) {}function generate_title(emoji_name, user_ids) {- const usernames = user_ids- .filter((user_id) => user_id !== page_params.user_id)- .map((user_id) => people.get_by_user_id(user_id).full_name);+ const usernames = people.get_display_full_names(+ user_ids.filter((user_id) => user_id !== page_params.user_id),+ );const current_user_reacted = user_ids.length !== usernames.length;const context = {