Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

people: Extract emails_to_full_names_string helper.

evykassirerbc2149d1ef6b
diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js
index 502b6b31dd5..67b51079f71 100644
--- a/frontend_tests/node_tests/people.js
+++ b/frontend_tests/node_tests/people.js
@@ -664,6 +664,24 @@ test_people("multi_user_methods", () => {
assert.equal(people.reply_to_to_user_ids_string("[email protected]"), undefined);
});
+test_people("emails_to_full_names_string", () => {
+ people.add_active_user(charles);
+ people.add_active_user(maria);
+ assert.equal(
+ people.emails_to_full_names_string([charles.email, maria.email]),
+ `${charles.full_name}, ${maria.full_name}`,
+ );
+
+ assert.equal(
+ people.emails_to_full_names_string([
+ charles.email,
+ maria.email,
+ ]),
+ `${charles.full_name}, [email protected], ${maria.full_name}`,
+ );
+});
+
test_people("concat_huddle", () => {
/*
We assume that user_ids passed in
diff --git a/static/js/drafts.js b/static/js/drafts.js
index 3cfcdb251b6..fd54a00f2d0 100644
--- a/static/js/drafts.js
+++ b/static/js/drafts.js
@@ -324,16 +324,7 @@ export function format_draft(draft) {
};
} else {
const emails = util.extract_pm_recipients(draft.private_message_recipient);
- const recipients = emails
- .map((email) => {
- email = email.trim();
- const person = people.get_by_email(email);
- if (person !== undefined) {
- return person.full_name;
- }
- return email;
- })
- .join(", ");
+ const recipients = people.emails_to_full_names_string(emails);
formatted = {
draft_id: draft.id,
diff --git a/static/js/people.js b/static/js/people.js
index 88acdbeddb7..43b21e173b6 100644
--- a/static/js/people.js
+++ b/static/js/people.js
@@ -256,6 +256,19 @@ export function reply_to_to_user_ids_string(emails_string) {
return user_ids.join(",");
}
+export function emails_to_full_names_string(emails) {
+ return emails
+ .map((email) => {
+ email = email.trim();
+ const person = get_by_email(email);
+ if (person !== undefined) {
+ return person.full_name;
+ }
+ return email;
+ })
+ .join(", ");
+}
+
export function get_user_time_preferences(user_id) {
const user_timezone = get_by_user_id(user_id).timezone;
if (user_timezone) {