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.

compose: Show pronouns in compose typeaheads.

Sayam Samal24d74f68ee04
diff --git a/web/src/page_params.ts b/web/src/page_params.ts
index 1a15f8bebef..3fa87ba6bd8 100644
--- a/web/src/page_params.ts
+++ b/web/src/page_params.ts
@@ -10,6 +10,15 @@ export const page_params: {
allowed: boolean;
}[];
corporate_enabled: boolean;
+ custom_profile_fields: {
+ display_in_profile_summary?: boolean;
+ field_data: string;
+ hint: string;
+ id: number;
+ name: string;
+ order: number;
+ type: number;
+ }[];
delivery_email: string;
development_environment: boolean;
is_admin: boolean;
diff --git a/web/src/people.ts b/web/src/people.ts
index 070d41bc601..78eab8a4cdc 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -1636,6 +1636,24 @@ export function get_custom_profile_data(user_id: number, field_id: number): Prof
return profile_data[field_id];
}
+export function get_custom_fields_by_type(
+ user_id: number,
+ field_type: number,
+): ProfileData[] | null {
+ const person = get_by_user_id(user_id);
+ const profile_data = person.profile_data;
+ if (profile_data === undefined) {
+ return null;
+ }
+ const filteredProfileData: ProfileData[] = [];
+ for (const field of page_params.custom_profile_fields) {
+ if (field.type === field_type) {
+ filteredProfileData.push(profile_data[field.id]);
+ }
+ }
+ return filteredProfileData;
+}
+
export function is_my_user_id(user_id: number | string): boolean {
if (!user_id) {
return false;
diff --git a/web/src/typeahead_helper.js b/web/src/typeahead_helper.js
index cdc9b6da277..12736cfb656 100644
--- a/web/src/typeahead_helper.js
+++ b/web/src/typeahead_helper.js
@@ -7,6 +7,7 @@ import render_typeahead_list_item from "../templates/typeahead_list_item.hbs";
import * as buddy_data from "./buddy_data";
import * as compose_state from "./compose_state";
+import {page_params} from "./page_params";
import * as people from "./people";
import * as pm_conversations from "./pm_conversations";
import * as recent_senders from "./recent_senders";
@@ -70,6 +71,7 @@ export function render_typeahead_item(args) {
args.has_image = args.img_src !== undefined;
args.has_status = args.status_emoji_info !== undefined;
args.has_secondary = args.secondary !== undefined;
+ args.has_pronouns = args.pronouns !== undefined;
return render_typeahead_list_item(args);
}
@@ -86,6 +88,11 @@ export function render_person(person) {
const status_emoji_info = user_status.get_status_emoji(person.user_id);
+ const PRONOUNS_ID = page_params.custom_profile_field_types.PRONOUNS.id;
+ const pronouns_list = people.get_custom_fields_by_type(person.user_id, PRONOUNS_ID);
+
+ const pronouns = pronouns_list?.[0]?.value;
+
const typeahead_arguments = {
primary: person.full_name,
img_src: avatar_url,
@@ -93,6 +100,7 @@ export function render_person(person) {
is_person: true,
status_emoji_info,
should_add_guest_user_indicator: people.should_add_guest_user_indicator(person.user_id),
+ pronouns,
};
typeahead_arguments.secondary = person.delivery_email;
diff --git a/web/templates/typeahead_list_item.hbs b/web/templates/typeahead_list_item.hbs
index e4a7f542c82..0ea0289da0f 100644
--- a/web/templates/typeahead_list_item.hbs
+++ b/web/templates/typeahead_list_item.hbs
@@ -24,6 +24,9 @@
{{~ primary ~}}
{{/if}}
</strong>
+{{~#if has_pronouns}}
+ <span class="pronouns">({{pronouns}})</span>
+{{~/if}}
{{~#if should_add_guest_user_indicator}}
<i>({{t 'guest'}})</i>
{{~/if}}
diff --git a/web/tests/composebox_typeahead.test.js b/web/tests/composebox_typeahead.test.js
index 84fc19dd981..9831c5df064 100644
--- a/web/tests/composebox_typeahead.test.js
+++ b/web/tests/composebox_typeahead.test.js
@@ -723,6 +723,9 @@ test("initialize", ({override, override_rewire, mock_template}) => {
});
let expected_value;
+ page_params.custom_profile_field_types = {
+ PRONOUNS: {id: 8, name: "Pronouns"},
+ };
mock_template("typeahead_list_item.hbs", true, (data, html) => {
assert.equal(typeof data.primary, "string");
diff --git a/web/tests/people.test.js b/web/tests/people.test.js
index 0b678e6c250..333bbbeae83 100644
--- a/web/tests/people.test.js
+++ b/web/tests/people.test.js
@@ -241,6 +241,17 @@ const all2 = {
full_name: "all",
};
+const stewie = {
+ email: "[email protected]",
+ user_id: 1204,
+ full_name: "Stewart Gilligan",
+ profile_data: {
+ 1: "(888) 888-8888",
+ 2: "(555) 555-5555",
+ 3: "he/him",
+ },
+};
+
// This is for error checking--never actually
// tell people.js about this user.
const invalid_user = {
@@ -525,6 +536,45 @@ test_people("my_custom_profile_data", () => {
assert.equal(people.my_custom_profile_data(4), "My phone number");
});
+test_people("get_custom_fields_by_type", () => {
+ people.add_active_user(stewie);
+ const person = people.get_by_user_id(stewie.user_id);
+ page_params.custom_profile_field_types = {
+ SHORT_TEXT: {
+ id: 1,
+ name: "Short text",
+ },
+ PRONOUNS: {
+ id: 8,
+ name: "Pronouns",
+ },
+ };
+ page_params.custom_profile_fields = [
+ {
+ id: 1,
+ name: "Phone number (mobile)",
+ type: 1,
+ },
+ {
+ id: 2,
+ name: "Phone number (office)",
+ type: 1,
+ },
+ {
+ id: 3,
+ name: "Pronouns",
+ type: 8,
+ },
+ ];
+ const SHORT_TEXT_ID = 1;
+ assert.deepEqual(people.get_custom_fields_by_type(person.user_id, SHORT_TEXT_ID), [
+ "(888) 888-8888",
+ "(555) 555-5555",
+ ]);
+ assert.deepEqual(people.get_custom_fields_by_type(person.user_id, 8), ["he/him"]);
+ assert.deepEqual(people.get_custom_fields_by_type(person.user_id, 100), []);
+});
+
test_people("bot_custom_profile_data", () => {
// If this test fails, then try opening organization settings > bots
// http://localhost:9991/#organization/bot-list-admin
diff --git a/web/tests/typeahead_helper.test.js b/web/tests/typeahead_helper.test.js
index f8a7d8b9d9b..08a5e2f635a 100644
--- a/web/tests/typeahead_helper.test.js
+++ b/web/tests/typeahead_helper.test.js
@@ -680,6 +680,9 @@ test("highlight_with_escaping", () => {
test("render_person when emails hidden", ({mock_template}) => {
// Test render_person with regular person, under hidden email visibility case
+ page_params.custom_profile_field_types = {
+ PRONOUNS: {id: 8, name: "Pronouns"},
+ };
let rendered = false;
mock_template("typeahead_list_item.hbs", false, (args) => {
assert.equal(args.primary, b_user_1.full_name);
@@ -694,6 +697,9 @@ test("render_person when emails hidden", ({mock_template}) => {
test("render_person", ({mock_template}) => {
// Test render_person with regular person
a_user.delivery_email = "[email protected]";
+ page_params.custom_profile_field_types = {
+ PRONOUNS: {id: 8, name: "Pronouns"},
+ };
let rendered = false;
mock_template("typeahead_list_item.hbs", false, (args) => {
assert.equal(args.primary, a_user.full_name);
@@ -774,6 +780,7 @@ test("render_emoji", ({mock_template}) => {
emoji_code: "1f44d",
is_emoji: true,
has_image: false,
+ has_pronouns: false,
has_secondary: false,
has_status: false,
};
@@ -800,6 +807,7 @@ test("render_emoji", ({mock_template}) => {
img_src: "TBD",
is_emoji: true,
has_image: true,
+ has_pronouns: false,
has_secondary: false,
has_status: false,
};