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 new function `get_realm_active_human_users`.

nicmar-8f688dc4c85bc
diff --git a/web/src/people.js b/web/src/people.js
index 088d89a4520..cc582de4218 100644
--- a/web/src/people.js
+++ b/web/src/people.js
@@ -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 = [];
diff --git a/web/tests/people.test.js b/web/tests/people.test.js
index a1ea3294600..ad65c5ad0bd 100644
--- a/web/tests/people.test.js
+++ b/web/tests/people.test.js
@@ -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();