diff --git a/web/src/buddy_data.ts b/web/src/buddy_data.ts index e071ed0074..572c6e8898 100644 --- a/web/src/buddy_data.ts +++ b/web/src/buddy_data.ts @@ -339,11 +339,8 @@ function filter_user_ids(user_filter_text: string, user_ids: number[]): number[] } // If a query is present in "Search people", we return matches. - let search_terms = user_filter_text.toLowerCase().split(/[,|]+/); - search_terms = search_terms.map((s) => s.trim()); - const persons = user_ids.map((user_id) => people.get_by_user_id(user_id)); - return [...people.filter_people_by_search_terms(persons, search_terms)]; + return [...people.filter_people_by_search_terms(persons, user_filter_text)]; } function get_filtered_user_id_list(user_filter_text: string): number[] { diff --git a/web/src/people.ts b/web/src/people.ts index 8bba9f2096..b5cbde347a 100644 --- a/web/src/people.ts +++ b/web/src/people.ts @@ -1224,7 +1224,10 @@ export function build_person_matcher(query: string): (user: User) => boolean { }; } -export function filter_people_by_search_terms(users: User[], search_terms: string[]): Set { +export function filter_people_by_search_terms(users: User[], search_string: string): Set { + let search_terms = search_string.toLowerCase().split(/[,|]+/); + search_terms = search_terms.map((s) => s.trim()); + const filtered_users = new Set(); // Build our matchers outside the loop to avoid some diff --git a/web/tests/people.test.js b/web/tests/people.test.js index 3ce2a67730..aebf366506 100644 --- a/web/tests/people.test.js +++ b/web/tests/people.test.js @@ -726,33 +726,33 @@ test_people("filtered_users", () => { const search_term = "a"; const users = people.get_realm_users(); - let filtered_people = people.filter_people_by_search_terms(users, [search_term]); + let filtered_people = people.filter_people_by_search_terms(users, search_term); assert.equal(filtered_people.size, 2); assert.ok(filtered_people.has(ashton.user_id)); assert.ok(filtered_people.has(maria.user_id)); assert.ok(!filtered_people.has(charles.user_id)); - filtered_people = people.filter_people_by_search_terms(users, []); - assert.equal(filtered_people.size, 0); + filtered_people = people.filter_people_by_search_terms(users, ""); + assert.equal(filtered_people.size, 7); - filtered_people = people.filter_people_by_search_terms(users, ["ltorv"]); + filtered_people = people.filter_people_by_search_terms(users, "ltorv"); assert.equal(filtered_people.size, 1); assert.ok(filtered_people.has(linus.user_id)); - filtered_people = people.filter_people_by_search_terms(users, ["ch di", "maria"]); + filtered_people = people.filter_people_by_search_terms(users, "ch di, maria"); assert.equal(filtered_people.size, 2); assert.ok(filtered_people.has(charles.user_id)); assert.ok(filtered_people.has(maria.user_id)); // Test filtering of names with diacritics // This should match Nöôáàh by ignoring diacritics, and also match Nooaah - filtered_people = people.filter_people_by_search_terms(users, ["noOa"]); + filtered_people = people.filter_people_by_search_terms(users, "noOa"); assert.equal(filtered_people.size, 2); assert.ok(filtered_people.has(noah.user_id)); assert.ok(filtered_people.has(plain_noah.user_id)); // This should match ëmerson, but not emerson - filtered_people = people.filter_people_by_search_terms(users, ["ëm"]); + filtered_people = people.filter_people_by_search_terms(users, "ëm"); assert.equal(filtered_people.size, 1); assert.ok(filtered_people.has(noah.user_id)); });