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: Add dm_matches_search_string for DM filter.

Shubham Padia188dd87eec5d
diff --git a/web/src/people.ts b/web/src/people.ts
index e74902d9c40..9c2509e3b6c 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -1209,6 +1209,12 @@ export function filter_people_by_search_terms(users: User[], search_string: stri
return filtered_users;
}
+export function dm_matches_search_string(users: User[], search_string: string): boolean {
+ const matcher = build_person_matcher(search_string);
+
+ return users.some((user) => matcher(user));
+}
+
export const is_valid_full_name_and_user_id = (full_name: string, user_id: number): boolean => {
/*
This function is currently only used for checking
diff --git a/web/tests/people.test.js b/web/tests/people.test.js
index 58fd957ce78..4fdce5b42ba 100644
--- a/web/tests/people.test.js
+++ b/web/tests/people.test.js
@@ -757,6 +757,47 @@ test_people("filtered_users", () => {
assert.ok(filtered_people.has(noah.user_id));
});
+test_people("dm_matches_search_string", () => {
+ people.add_active_user(charles);
+ people.add_active_user(maria);
+ people.add_active_user(ashton);
+ people.add_active_user(linus);
+ people.add_active_user(noah);
+ people.add_active_user(plain_noah);
+
+ let result = people.dm_matches_search_string([ashton], "a");
+ assert.ok(result);
+ // Maria's email starts with `a`.
+ result = people.dm_matches_search_string([maria], "a");
+ assert.ok(result);
+ // Neither Charles' full name or email start with `a`.
+ result = people.dm_matches_search_string([charles], "a");
+ assert.ok(!result);
+
+ // Empty search terms should always return true
+ result = people.dm_matches_search_string([charles], "");
+ assert.ok(result);
+ result = people.dm_matches_search_string([charles, maria, noah], "");
+ assert.ok(result);
+
+ // Match with email.
+ result = people.dm_matches_search_string([linus], "ltorv");
+ assert.ok(result);
+
+ // Test filtering of names with diacritics. This should match
+ // Nöôáàh by ignoring diacritics, and also match Nooaah.
+ result = people.dm_matches_search_string([noah], "noOa");
+ assert.ok(result);
+ result = people.dm_matches_search_string([plain_noah], "noOa");
+ assert.ok(result);
+
+ // This should match ëmerson, but not emerson.
+ result = people.dm_matches_search_string([noah], "ëm");
+ assert.ok(result);
+ result = people.dm_matches_search_string([plain_noah], "ëm");
+ assert.ok(!result);
+});
+
test_people("multi_user_methods", () => {
people.add_active_user(emp401);
people.add_active_user(emp402);