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.

typeahead: Show email only when it's not null.

Amit Patild5271259ba08
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts
index e8ebaddef7a..17c15128e5c 100644
--- a/web/src/typeahead_helper.ts
+++ b/web/src/typeahead_helper.ts
@@ -120,12 +120,13 @@ export let render_person = (
// Show the email or a matched custom profile field in the secondary text.
// If both the email and a custom profile field match the query, show both.
- let secondary_text = person.user.delivery_email;
+ const user_email = person.user.delivery_email;
+ let secondary_text = user_email;
if (opts) {
const email_matches = typeahead.query_matches_string_in_order(
opts.query,
- secondary_text ?? "",
+ user_email ?? "",
"",
opts.should_remove_diacritics,
);
@@ -152,10 +153,12 @@ export let render_person = (
}
// if both email and custom field matches, show both.
- if (email_matches && matched_custom_field) {
- secondary_text = `${secondary_text}, ${matched_custom_field}`;
- } else if (matched_custom_field) {
- secondary_text = matched_custom_field;
+ if (matched_custom_field) {
+ if (user_email !== null && email_matches) {
+ secondary_text = `${user_email}, ${matched_custom_field}`;
+ } else {
+ secondary_text = matched_custom_field;
+ }
}
}
const typeahead_arguments = {
diff --git a/web/tests/typeahead_helper.test.cjs b/web/tests/typeahead_helper.test.cjs
index 616f88bb8c9..c909af8f458 100644
--- a/web/tests/typeahead_helper.test.cjs
+++ b/web/tests/typeahead_helper.test.cjs
@@ -1802,6 +1802,47 @@ test("render_person skips custom profile fields not used for user matching", ({
assert.ok(rendered);
});
+test("render_person with matching custom profile field but email hidden", ({
+ mock_template,
+ override,
+}) => {
+ override(realm, "custom_profile_field_types", {
+ SHORT_TEXT: {id: 1, name: "Short text"},
+ PRONOUNS: {id: 3, name: "Pronouns"},
+ });
+
+ override(realm, "custom_profile_fields", [
+ {
+ id: 1,
+ name: "Alpha field",
+ type: realm.custom_profile_field_types.SHORT_TEXT.id,
+ use_for_user_matching: true,
+ },
+ ]);
+
+ b_user_1.delivery_email = null;
+
+ people.set_custom_profile_field_data(b_user_1.user_id, {
+ id: 1,
+ value: "Alpha",
+ });
+
+ let rendered = false;
+ mock_template("typeahead_list_item.hbs", false, (args) => {
+ // When email is null and custom field matches,
+ // secondary should only show the custom field value, not "null, value"
+ assert.equal(args.secondary, "Alpha");
+ rendered = true;
+ return "typeahead-item-stub";
+ });
+
+ assert.equal(
+ th.render_person(b_user_1_item, {query: "", should_remove_diacritics: true}),
+ "typeahead-item-stub",
+ );
+ assert.ok(rendered);
+});
+
test("query_matches_person matches custom profile fields when they are enabled for user matching ", ({
override,
}) => {