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.
This commit is contained in:
nicmar-8 2023-05-17 11:45:39 +02:00 committed by Tim Abbott
parent f688dc4c85
commit 362a63ea5d
3 changed files with 11 additions and 6 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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) {