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: Wire diacritic prefix matching through sort_recipients.

Aadyot1d3438ab845a9
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.ts
index 23d01636497..e0d79c7acd7 100644
--- a/web/src/composebox_typeahead.ts
+++ b/web/src/composebox_typeahead.ts
@@ -713,11 +713,10 @@ function filter_persons<T>(
export function get_person_suggestion_for_topic_typeahead(query: string): UserPillData[] {
query = typeahead.clean_query_lowercase(query, false);
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
const filterer = (person_items: UserPillData[]): UserPillData[] =>
person_items.filter((item) =>
- typeahead_helper.query_matches_person_name(query, item, should_remove_diacritics, true),
+ typeahead_helper.query_matches_person_name(query, item, true),
);
const current_narrow_participant_ids = message_lists.current?.data.participants.visible();
@@ -785,7 +784,6 @@ export function get_person_suggestions(
exclude_non_welcome_bots = false,
): (UserOrMentionPillData | UserGroupPillData)[] {
query = typeahead.clean_query_lowercase(query, false);
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
let groups: UserGroup[];
if (opts.filter_groups_for_mention) {
@@ -824,7 +822,7 @@ export function get_person_suggestions(
}));
const filtered_groups = group_pill_data.filter((item) =>
- typeahead_helper.query_matches_group_name(query, item, should_remove_diacritics),
+ typeahead_helper.query_matches_group_name(query, item),
);
const user = people.get_from_unique_full_name(query);
@@ -881,7 +879,6 @@ export function get_person_suggestions(
typeahead_helper.query_matches_person(
query,
item,
- should_remove_diacritics,
undefined,
opts.allow_custom_profile_field_matching,
),
@@ -1280,9 +1277,8 @@ export function get_candidates(
}
export function content_item_html(
- query: string,
+ _query: string,
): (item: TypeaheadSuggestion) => string | undefined {
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
return function (item: TypeaheadSuggestion): string | undefined {
switch (item.type) {
case "emoji":
@@ -1292,7 +1288,6 @@ export function content_item_html(
case "broadcast":
return typeahead_helper.render_person_or_user_group(item, {
query: token,
- should_remove_diacritics,
});
case "slash":
return typeahead_helper.render_typeahead_item({
diff --git a/web/src/pill_typeahead.ts b/web/src/pill_typeahead.ts
index 637d5e5ffb2..d966686825e 100644
--- a/web/src/pill_typeahead.ts
+++ b/web/src/pill_typeahead.ts
@@ -16,23 +16,15 @@ import type {UserGroup} from "./user_groups.ts";
import * as user_pill from "./user_pill.ts";
import type {UserPillData, UserPillWidget} from "./user_pill.ts";
-function person_matcher(
- query: string,
- item: UserPillData,
- should_remove_diacritics: boolean,
-): boolean {
+function person_matcher(query: string, item: UserPillData): boolean {
return (
people.is_known_user_id(item.user.user_id) &&
- typeahead_helper.query_matches_person(query, item, should_remove_diacritics)
+ typeahead_helper.query_matches_person(query, item)
);
}
-function group_matcher(
- query: string,
- item: UserGroupPillData,
- should_remove_diacritics: boolean,
-): boolean {
- return typeahead_helper.query_matches_group_name(query, item, should_remove_diacritics);
+function group_matcher(query: string, item: UserGroupPillData): boolean {
+ return typeahead_helper.query_matches_group_name(query, item);
}
type TypeaheadItem = UserGroupPillData | StreamPillData | UserPillData;
@@ -60,8 +52,7 @@ export function set_up_user(
},
matcher(query: string): (item: UserPillData) => boolean {
query = typeahead.clean_query_lowercase(query, false);
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
- return (item: UserPillData) => person_matcher(query, item, should_remove_diacritics);
+ return (item: UserPillData) => person_matcher(query, item);
},
sorter(matches: UserPillData[], query: string): UserPillData[] {
const users = matches.filter((match) => people.is_known_user_id(match.user.user_id));
@@ -156,10 +147,7 @@ export function set_up_user_group(
},
matcher(query: string): (item: UserGroupPillData) => boolean {
query = typeahead.clean_query_lowercase(query, false);
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
-
- return (item: UserGroupPillData) =>
- group_matcher(query, item, should_remove_diacritics);
+ return (item: UserGroupPillData) => group_matcher(query, item);
},
sorter(matches: UserGroupPillData[], query: string): UserGroupPillData[] {
return typeahead_helper.sort_user_groups(matches, query);
@@ -207,14 +195,13 @@ export function set_up_group_setting_typeahead(
},
matcher(query: string): (item: GroupSettingTypeaheadItem) => boolean {
query = typeahead.clean_query_lowercase(query, false);
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
return (item: GroupSettingTypeaheadItem): boolean => {
let matches = false;
if (item.type === "user_group") {
- matches ||= group_matcher(query, item, should_remove_diacritics);
+ matches ||= group_matcher(query, item);
} else if (item.type === "user") {
- matches ||= person_matcher(query, item, should_remove_diacritics);
+ matches ||= person_matcher(query, item);
}
return matches;
};
@@ -352,7 +339,6 @@ export function set_up_combined(
},
matcher(query: string): (item: TypeaheadItem) => boolean {
query = typeahead.clean_query_lowercase(query, false);
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
return (item: TypeaheadItem): boolean => {
if (include_streams(query) && item.type === "stream") {
@@ -363,18 +349,18 @@ export function set_up_combined(
if (include_user_groups && query.startsWith("@")) {
if (item.type === "user_group") {
const normalized_query = query.slice(1);
- return group_matcher(normalized_query, item, should_remove_diacritics);
+ return group_matcher(normalized_query, item);
}
return false;
}
let matches = false;
if (include_user_groups && item.type === "user_group") {
- matches = group_matcher(query, item, should_remove_diacritics);
+ matches = group_matcher(query, item);
}
if (include_users && item.type === "user") {
- matches ||= person_matcher(query, item, should_remove_diacritics);
+ matches ||= person_matcher(query, item);
}
return matches;
};
diff --git a/web/src/settings_playgrounds.ts b/web/src/settings_playgrounds.ts
index 46417264e77..90c28c9b0ce 100644
--- a/web/src/settings_playgrounds.ts
+++ b/web/src/settings_playgrounds.ts
@@ -190,6 +190,7 @@ function build_page(): void {
const {
exact_matches,
+ begins_with_case_insensitive_diacritic_matches,
begins_with_case_sensitive_matches,
begins_with_case_insensitive_matches,
} = typeahead.triage_raw(q, items, (item) => [
@@ -199,6 +200,7 @@ function build_page(): void {
const begins_with = [
...exact_matches,
+ ...begins_with_case_insensitive_diacritic_matches,
...begins_with_case_sensitive_matches,
...begins_with_case_insensitive_matches,
];
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts
index 8d537e7ce03..c90ae93591e 100644
--- a/web/src/typeahead_helper.ts
+++ b/web/src/typeahead_helper.ts
@@ -96,7 +96,6 @@ export let render_person = (
person: UserPillData | UserOrMentionPillData,
opts?: {
query: string;
- should_remove_diacritics: boolean;
},
): string => {
if (person.type === "broadcast") {
@@ -123,11 +122,14 @@ export let render_person = (
let secondary_text = user_email;
if (opts) {
+ // Strip diacritics as query_matches_person does, so the email or
+ // field that made this user match is the one we show.
+ const diacritic_stripped_query = typeahead.remove_diacritics(opts.query);
const email_matches = typeahead.query_matches_string_in_order(
- opts.query,
+ diacritic_stripped_query,
user_email ?? "",
"",
- opts.should_remove_diacritics,
+ true,
);
let matched_custom_field;
@@ -140,10 +142,10 @@ export let render_person = (
if (
typeahead.query_matches_string_in_order(
- opts.query,
+ diacritic_stripped_query,
value ?? "",
"",
- opts.should_remove_diacritics,
+ true,
)
) {
matched_custom_field = value;
@@ -205,7 +207,6 @@ export function render_person_or_user_group(
item: UserGroupPillData | UserPillData | UserOrMentionPillData,
opts?: {
query: string;
- should_remove_diacritics: boolean;
},
): string {
if (item.type === "user_group") {
@@ -542,11 +543,6 @@ const get_user_matches_with_quality = <UserType extends UserOrMentionPillData |
worst_users: () => UserType[];
} => {
const users_name_results = typeahead.triage_raw(query, users, (p) => [p.user.full_name]);
- const users_name_good_matches = [
- ...users_name_results.exact_matches,
- ...users_name_results.begins_with_case_sensitive_matches,
- ...users_name_results.begins_with_case_insensitive_matches,
- ];
const users_name_okay_matches = [...users_name_results.word_boundary_matches];
const email_results = typeahead.triage_raw(query, users_name_results.no_matches, (p) => [
@@ -554,14 +550,42 @@ const get_user_matches_with_quality = <UserType extends UserOrMentionPillData |
]);
const email_good_matches = [
...email_results.exact_matches,
+ ...email_results.begins_with_case_insensitive_diacritic_matches,
...email_results.begins_with_case_sensitive_matches,
...email_results.begins_with_case_insensitive_matches,
];
const email_okay_matches = [...email_results.word_boundary_matches];
- const best_users = (): UserType[] => [
- ...sort_relevance(users_name_good_matches),
- ...sort_relevance(users_name_okay_matches),
- ];
+ const query_has_diacritics = typeahead.contains_diacritics(query);
+ const best_users = (): UserType[] => {
+ if (query_has_diacritics) {
+ // Sort exact and diacritic-prefix matches together as one tier, and
+ // case-sensitive + case-insensitive (including the diacritic-stripped
+ // fallback) as a second tier. The separate sort calls ensure relevance
+ // sorting within the second tier can't bubble a diacritic-stripped
+ // fallback above a diacritic prefix match.
+ return [
+ ...sort_relevance([
+ ...users_name_results.exact_matches,
+ ...users_name_results.begins_with_case_insensitive_diacritic_matches,
+ ]),
+ ...sort_relevance([
+ ...users_name_results.begins_with_case_sensitive_matches,
+ ...users_name_results.begins_with_case_insensitive_matches,
+ ]),
+ ...sort_relevance(users_name_okay_matches),
+ ];
+ }
+
+ const users_name_good_matches = [
+ ...users_name_results.exact_matches,
+ ...users_name_results.begins_with_case_sensitive_matches,
+ ...users_name_results.begins_with_case_insensitive_matches,
+ ];
+ return [
+ ...sort_relevance(users_name_good_matches),
+ ...sort_relevance(users_name_okay_matches),
+ ];
+ };
const ok_users = (): UserType[] => [
...sort_relevance(email_good_matches),
...sort_relevance(email_okay_matches),
@@ -619,6 +643,7 @@ export let sort_recipients = <UserType extends UserOrMentionPillData | UserPillD
});
const groups_good_matches = [
...groups_results.exact_matches,
+ ...groups_results.begins_with_case_insensitive_diacritic_matches,
...groups_results.begins_with_case_sensitive_matches,
...groups_results.begins_with_case_insensitive_matches,
];
@@ -843,6 +868,9 @@ export const sort_users_and_groups_options = ({
]);
const prefix_matches = sort_items([
+ ...groups_results.begins_with_case_insensitive_diacritic_matches,
+ ...users_name_results.begins_with_case_insensitive_diacritic_matches,
+ ...email_results.begins_with_case_insensitive_diacritic_matches,
...groups_results.begins_with_case_sensitive_matches,
...groups_results.begins_with_case_insensitive_matches,
...users_name_results.begins_with_case_sensitive_matches,
@@ -1146,19 +1174,19 @@ export function rewire_sort_user_groups(value: typeof sort_user_groups): void {
export function query_matches_person_name(
query: string,
person: UserPillData,
- should_remove_diacritics: boolean,
match_prefix?: boolean,
): boolean {
- query = query.toLowerCase();
-
- const full_name = people.maybe_remove_diacritics_from_name(
- person.user,
- should_remove_diacritics,
- );
-
+ // Filtering is diacritics-agnostic: we strip diacritics from both the query
+ // and the name so ASCII and diacritic spellings match each other. Ranking is
+ // not -- triage_raw/sort_recipients keep exact diacritic-prefix matches above
+ // the diacritic-stripped ones.
+ const diacritic_stripped_query = typeahead.remove_diacritics(query.toLowerCase());
+ const diacritic_stripped_name = people
+ .maybe_remove_diacritics_from_name(person.user, true)
+ .toLowerCase();
return typeahead.query_matches_string_in_order_assume_canonicalized(
- query,
- full_name.toLowerCase(),
+ diacritic_stripped_query,
+ diacritic_stripped_name,
" ",
match_prefix,
);
@@ -1167,24 +1195,18 @@ export function query_matches_person_name(
export function query_matches_person(
query: string,
person: UserPillData | UserOrMentionPillData,
- should_remove_diacritics: boolean,
match_prefix?: boolean,
allow_custom_profile_field_matching = false,
): boolean {
if (
person.type === "broadcast" &&
- typeahead.query_matches_string_in_order(
- query,
- person.user.full_name,
- " ",
- should_remove_diacritics,
- )
+ typeahead.query_matches_string_in_order(query, person.user.full_name, " ", true)
) {
return true;
}
if (person.type === "user") {
- if (query_matches_person_name(query, person, should_remove_diacritics, match_prefix)) {
+ if (query_matches_person_name(query, person, match_prefix)) {
return true;
}
@@ -1196,10 +1218,10 @@ export function query_matches_person(
people.get_custom_profile_data(person.user.user_id, field.id)?.value ?? "";
if (
typeahead.query_matches_string_in_order(
- query,
+ typeahead.remove_diacritics(query),
field_value,
" ",
- should_remove_diacritics,
+ true,
)
) {
return true;
@@ -1210,10 +1232,10 @@ export function query_matches_person(
if (person.user.delivery_email) {
return typeahead.query_matches_string_in_order(
- query,
+ typeahead.remove_diacritics(query),
people.get_visible_email(person.user),
" ",
- should_remove_diacritics,
+ true,
);
}
}
@@ -1233,31 +1255,23 @@ export function query_matches_stream_name(
);
}
-export function query_matches_group_name(
- query: string,
- user_group: UserGroupPillData,
- should_remove_diacritics: boolean,
-): boolean {
+export function query_matches_group_name(query: string, user_group: UserGroupPillData): boolean {
+ // Filtering is diacritics-agnostic, like query_matches_person_name: we
+ // strip diacritics from both the query and the group name so ASCII and
+ // diacritic spellings match each other. Ranking (sort_recipients) stays
+ // diacritic-aware.
+ const diacritic_stripped_query = typeahead.remove_diacritics(query.toLowerCase());
+ const matches_group_name = (group_name: string): boolean =>
+ typeahead.query_matches_string_in_order_assume_canonicalized(
+ diacritic_stripped_query,
+ typeahead.remove_diacritics(group_name.toLowerCase()),
+ "",
+ );
if (user_group.name === "role:members") {
return (
- typeahead.query_matches_string_in_order(
- query,
- user_groups.get_display_group_name(user_group.name),
- "",
- should_remove_diacritics,
- ) ||
- typeahead.query_matches_string_in_order(
- query,
- settings_config.alternate_members_group_typeahead_matching_name,
- "",
- should_remove_diacritics,
- )
+ matches_group_name(user_groups.get_display_group_name(user_group.name)) ||
+ matches_group_name(settings_config.alternate_members_group_typeahead_matching_name)
);
}
- return typeahead.query_matches_string_in_order(
- query,
- user_groups.get_display_group_name(user_group.name),
- "",
- should_remove_diacritics,
- );
+ return matches_group_name(user_groups.get_display_group_name(user_group.name));
}
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index c5bc1f53a40..0fd1a7fa206 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -1603,12 +1603,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
function matcher(query, person) {
query = typeahead.clean_query_lowercase(query, false);
- const should_remove_diacritics = !typeahead.contains_diacritics(query);
- return typeahead_helper.query_matches_person(
- query,
- person,
- should_remove_diacritics,
- );
+ return typeahead_helper.query_matches_person(query, person);
}
let query;
@@ -2274,6 +2269,33 @@ test("get_person_suggestion_for_topic_typeahead respects DM permissions", ({over
assert.deepEqual(results, []);
});
+test("get_person_suggestion_for_topic_typeahead: diacritic query prioritizes exact diacritic matches", ({
+ override,
+}) => {
+ // "Gael" has the shorter name, so the within-bucket tiebreaker would rank
+ // it above "Gaël Twin" -- only the diacritic-prefix bucket puts "Gaël
+ // Twin" first.
+ const gael_ascii = make_user({
+ full_name: "Gael",
+ user_id: 112,
+ email: "[email protected]",
+ });
+ people.add_active_user(gael_ascii);
+
+ message_lists.current = undefined;
+ override(pm_conversations, "get_partners", () => [
+ gael.user_id,
+ gael_ascii.user_id,
+ lear.user_id,
+ ]);
+
+ const results = ct.get_person_suggestion_for_topic_typeahead("gaë");
+ assert.deepEqual(
+ results.map((result) => result.user.user_id),
+ [gael.user_id, gael_ascii.user_id],
+ );
+});
+
test("begins_typeahead", ({override, override_rewire}) => {
override(stream_topic_history_util, "get_server_history", noop);
diff --git a/web/tests/typeahead_helper.test.cjs b/web/tests/typeahead_helper.test.cjs
index 94e92bc1ba5..fb14a768d05 100644
--- a/web/tests/typeahead_helper.test.cjs
+++ b/web/tests/typeahead_helper.test.cjs
@@ -1781,10 +1781,7 @@ test("render_person shows value of custom profile fields in secondary", ({
return "typeahead-item-stub";
});
- assert.equal(
- th.render_person(a_user_item, {query: "Alpha", should_remove_diacritics: true}),
- "typeahead-item-stub",
- );
+ assert.equal(th.render_person(a_user_item, {query: "Alpha"}), "typeahead-item-stub");
assert.ok(rendered);
});
@@ -1818,10 +1815,43 @@ test("render_person shows both email and custom profile fields as secondary if b
return "typeahead-item-stub";
});
- assert.equal(
- th.render_person(a_user_item, {query: "a_user", should_remove_diacritics: true}),
- "typeahead-item-stub",
- );
+ assert.equal(th.render_person(a_user_item, {query: "a_user"}), "typeahead-item-stub");
+ assert.ok(rendered);
+});
+
+test("render_person shows the email and custom profile field a diacritic query matched", ({
+ mock_template,
+ override,
+}) => {
+ // "a_usèr" matches this user's email and field once diacritics are
+ // stripped, so the secondary line has to show both rather than hide them.
+ 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,
+ },
+ ]);
+
+ people.set_custom_profile_field_data(a_user.user_id, {
+ id: 1,
+ value: "a_user",
+ });
+
+ let rendered = false;
+ mock_template("typeahead_list_item.hbs", false, (args) => {
+ assert.equal(args.secondary, "[email protected], a_user");
+ rendered = true;
+ return "typeahead-item-stub";
+ });
+
+ assert.equal(th.render_person(a_user_item, {query: "a_usèr"}), "typeahead-item-stub");
assert.ok(rendered);
});
@@ -1856,10 +1886,7 @@ test("render_person skips custom profile fields not used for user matching", ({
return "typeahead-item-stub";
});
- assert.equal(
- th.render_person(a_user_item, {query: "Alpha", should_remove_diacritics: true}),
- "typeahead-item-stub",
- );
+ assert.equal(th.render_person(a_user_item, {query: "Alpha"}), "typeahead-item-stub");
assert.ok(rendered);
});
@@ -1897,17 +1924,14 @@ test("render_person with matching custom profile field but email hidden", ({
return "typeahead-item-stub";
});
- assert.equal(
- th.render_person(b_user_1_item, {query: "", should_remove_diacritics: true}),
- "typeahead-item-stub",
- );
+ assert.equal(th.render_person(b_user_1_item, {query: ""}), "typeahead-item-stub");
assert.ok(rendered);
});
-test("query_matches_person_name keeps diacritics when the query has them", () => {
- // When should_remove_diacritics is false (used when the query itself has
- // diacritics), the name keeps its diacritics, so a diacritic query matches
- // a name with the same diacritics but not its ASCII counterpart.
+test("query_matches_person_name strips diacritics from both query and name", () => {
+ // query_matches_person_name now always strips diacritics from both sides,
+ // so a diacritic query matches an ASCII name and an ASCII query matches a
+ // name with diacritics.
const adam_diacritic = make_user({
full_name: "Ądam",
@@ -1919,8 +1943,37 @@ test("query_matches_person_name keeps diacritics when the query has them", () =>
user_id: 102,
});
- assert.equal(th.query_matches_person_name("ądam", user_item(adam_diacritic), false), true);
- assert.equal(th.query_matches_person_name("ądam", user_item(adam_ascii), false), false);
+ assert.equal(th.query_matches_person_name("ądam", user_item(adam_diacritic)), true);
+ assert.equal(th.query_matches_person_name("ądam", user_item(adam_ascii)), true);
+ assert.equal(th.query_matches_person_name("adam", user_item(adam_diacritic)), true);
+ assert.equal(th.query_matches_person_name("zoe", user_item(adam_ascii)), false);
+});
+
+test("query_matches_group_name strips diacritics from both query and name", () => {
+ // Like query_matches_person_name, group-name filtering is
+ // diacritics-agnostic: a diacritic query matches an ASCII group name
+ // and an ASCII query matches a group name with diacritics.
+ const diacritic_group = make_user_group({
+ id: 200,
+ name: "Ągents",
+ description: "",
+ members: new Set([b_user_2.user_id]),
+ is_system_group: false,
+ });
+ const ascii_group = make_user_group({
+ id: 201,
+ name: "agents",
+ description: "",
+ members: new Set([b_user_2.user_id]),
+ is_system_group: false,
+ });
+ user_groups.add(diacritic_group);
+ user_groups.add(ascii_group);
+
+ assert.equal(th.query_matches_group_name("ągents", user_group_item(diacritic_group)), true);
+ assert.equal(th.query_matches_group_name("ągents", user_group_item(ascii_group)), true);
+ assert.equal(th.query_matches_group_name("agents", user_group_item(diacritic_group)), true);
+ assert.equal(th.query_matches_group_name("zoe", user_group_item(ascii_group)), false);
});
test("query_matches_person matches custom profile fields when they are enabled for user matching ", ({
@@ -1956,6 +2009,113 @@ test("query_matches_person matches custom profile fields when they are enabled f
value: "Beta",
});
- assert.equal(th.query_matches_person("alpha", a_user_item, undefined, undefined, true), true);
- assert.equal(th.query_matches_person("beta", a_user_item, undefined, undefined, true), false);
+ assert.equal(th.query_matches_person("alpha", a_user_item, undefined, true), true);
+ assert.equal(th.query_matches_person("beta", a_user_item, undefined, true), false);
+});
+
+test("sort_recipients prioritizes exact diacritic matches", () => {
+ const aaron_item = {
+ type: "user",
+ user: {full_name: "aaron", email: "[email protected]", is_bot: false},
+ };
+
+ const aaron_diacritic_item = {
+ type: "user",
+ user: {full_name: "Ąaron", email: "[email protected]", is_bot: false},
+ };
+
+ const users = [aaron_item, aaron_diacritic_item];
+
+ const result = th.sort_recipients({
+ users,
+ query: "ą",
+ groups: [],
+ max_num_items: 10,
+ });
+
+ assert.deepEqual(result, [aaron_diacritic_item, aaron_item]);
+});
+
+test("sort_recipients: diacritic query allows diacritic-stripped ASCII fallback", () => {
+ const adam_item = {
+ type: "user",
+ user: {full_name: "adam", email: "[email protected]", is_bot: false},
+ };
+ const zoe_item = {
+ type: "user",
+ user: {full_name: "zoe", email: "[email protected]", is_bot: false},
+ };
+
+ const result = th.sort_recipients({
+ users: [adam_item, zoe_item],
+ query: "ą",
+ groups: [],
+ max_num_items: 10,
+ });
+
+ assert.deepEqual(result, [adam_item, zoe_item]);
+});
+
+test("sort_recipients: plain ASCII query ranks diacritic names below matches", () => {
+ const adam_item = {
+ type: "user",
+ user: {full_name: "adam", email: "[email protected]", is_bot: false},
+ };
+ const adam_diacritic_item = {
+ type: "user",
+ user: {full_name: "Ądam", email: "[email protected]", is_bot: false},
+ };
+
+ const result = th.sort_recipients({
+ users: [adam_item, adam_diacritic_item],
+ query: "a",
+ groups: [],
+ max_num_items: 10,
+ });
+
+ assert.deepEqual(result, [adam_item, adam_diacritic_item]);
+});
+
+test("sort_recipients: diacritic query matches via word boundary (diacritic-stripped)", () => {
+ const john_adam_item = {
+ type: "user",
+ user: {full_name: "John adam", email: "[email protected]", is_bot: false},
+ };
+ const zoe_item = {
+ type: "user",
+ user: {full_name: "zoe", email: "[email protected]", is_bot: false},
+ };
+
+ const result = th.sort_recipients({
+ users: [john_adam_item, zoe_item],
+ query: "ą",
+ groups: [],
+ max_num_items: 10,
+ });
+
+ assert.deepEqual(result, [john_adam_item, zoe_item]);
+});
+
+test("sort_recipients surfaces groups whose names match a diacritic query", () => {
+ // Regression test: a group whose display name begins with a
+ // diacritic query lands in the diacritic-prefix bucket, which
+ // sort_recipients must still surface rather than drop.
+ const diacritic_group = make_user_group({
+ id: 100,
+ name: "Ągents",
+ description: "",
+ members: new Set([b_user_2.user_id]),
+ is_system_group: false,
+ });
+ user_groups.add(diacritic_group);
+
+ const result = th.sort_recipients({
+ users: [],
+ query: "ą",
+ groups: [user_group_item(diacritic_group)],
+ max_num_items: 10,
+ });
+
+ assert.equal(result.length, 1);
+ assert.equal(result[0].id, diacritic_group.id);
});