From 362a63ea5d271335f8ebd9a86369af81b2bb2ac6 Mon Sep 17 00:00:00 2001 From: nicmar-8 Date: Wed, 17 May 2023 11:45:39 +0200 Subject: [PATCH] pill_typeahead: Remove bots in person picker custom profile fields. In `user_pill.js` add parameter to allow for excluding bots when getting the users for the pill typeahead. For `custom_user_field` typeahead exclude bots by default. Fixes #25092. --- web/src/pill_typeahead.js | 3 ++- web/src/settings_account.js | 8 ++++++-- web/src/user_pill.js | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/web/src/pill_typeahead.js b/web/src/pill_typeahead.js index 17dfb7b41d..a4b72265c5 100644 --- a/web/src/pill_typeahead.js +++ b/web/src/pill_typeahead.js @@ -29,6 +29,7 @@ export function set_up($input, pills, opts) { const include_streams = (query) => opts.stream && query.trim().startsWith("#"); const include_user_groups = opts.user_group; const include_users = opts.user; + const exclude_bots = opts.exclude_bots; $input.typeahead({ items: 5, @@ -54,7 +55,7 @@ export function set_up($input, pills, opts) { // default user_pill.typeahead_source. source = [...source, ...opts.user_source()]; } else { - source = [...source, ...user_pill.typeahead_source(pills)]; + source = [...source, ...user_pill.typeahead_source(pills, exclude_bots)]; } } return source; diff --git a/web/src/settings_account.js b/web/src/settings_account.js index 1fed85d7df..b7eb4a6f04 100644 --- a/web/src/settings_account.js +++ b/web/src/settings_account.js @@ -347,13 +347,17 @@ export function initialize_custom_user_type_fields( if (is_editable) { const $input = $pill_container.children(".input"); if (set_handler_on_update) { - const opts = {update_func: update_custom_user_field, user: true}; + const opts = { + update_func: update_custom_user_field, + user: true, + exclude_bots: true, + }; pill_typeahead.set_up($input, pills, opts); pills.onPillRemove(() => { update_custom_user_field(); }); } else { - pill_typeahead.set_up($input, pills, {user: true}); + pill_typeahead.set_up($input, pills, {user: true, exclude_bots: true}); } } user_pills.set(field.id, pills); diff --git a/web/src/user_pill.js b/web/src/user_pill.js index 5e8e583674..a4ea3977bc 100644 --- a/web/src/user_pill.js +++ b/web/src/user_pill.js @@ -108,9 +108,9 @@ export function has_unconverted_data(pill_widget) { return has_unknown_items; } -export function typeahead_source(pill_widget) { - const persons = people.get_realm_users(); - return filter_taken_users(persons, pill_widget); +export function typeahead_source(pill_widget, exclude_bots) { + const users = exclude_bots ? people.get_realm_active_human_users() : people.get_realm_users(); + return filter_taken_users(users, pill_widget); } export function filter_taken_users(items, pill_widget) {