mirror of https://github.com/zulip/zulip.git
people: Add new function `get_realm_active_human_users`.
There was no function to retrieve users while excluding bots, this was needed to allow for typeahead user fields that require to exclude bots from the autocomplete suggestions. Fixes part of #25092.
This commit is contained in:
parent
7be72e65e5
commit
f688dc4c85
|
@ -906,6 +906,19 @@ export function get_realm_users() {
|
|||
return [...active_user_dict.values()];
|
||||
}
|
||||
|
||||
export function get_realm_active_human_users() {
|
||||
// includes ONLY humans from your realm
|
||||
const humans = [];
|
||||
|
||||
for (const user of active_user_dict.values()) {
|
||||
if (!user.is_bot) {
|
||||
humans.push(user);
|
||||
}
|
||||
}
|
||||
|
||||
return humans;
|
||||
}
|
||||
|
||||
export function get_realm_active_human_user_ids() {
|
||||
const human_ids = [];
|
||||
|
||||
|
|
|
@ -1252,6 +1252,23 @@ test_people("huddle_string", () => {
|
|||
assert.equal(huddle([me.user_id, maria.user_id, bob.user_id]), "203,302");
|
||||
});
|
||||
|
||||
test_people("get_realm_active_human_users", () => {
|
||||
let humans = people.get_realm_active_human_users();
|
||||
assert.equal(humans.length, 1);
|
||||
assert.deepEqual(humans, [me]);
|
||||
|
||||
people.add_active_user(maria);
|
||||
people.add_active_user(bot_botson);
|
||||
humans = people.get_realm_active_human_users();
|
||||
assert.equal(humans.length, 2);
|
||||
assert.deepEqual(humans, [me, maria]);
|
||||
|
||||
people.deactivate(maria);
|
||||
humans = people.get_realm_active_human_users();
|
||||
assert.equal(humans.length, 1);
|
||||
assert.deepEqual(humans, [me]);
|
||||
});
|
||||
|
||||
// reset to native Date()
|
||||
run_test("reset MockDate", () => {
|
||||
MockDate.reset();
|
||||
|
|
Loading…
Reference in New Issue