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: Implement get_bot_ids.

Zixuan James Li5ecd0cecf4d2
diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js
index 1ddf7d4fa31..3bb1b20b07e 100644
--- a/frontend_tests/node_tests/people.js
+++ b/frontend_tests/node_tests/people.js
@@ -304,6 +304,9 @@ test_people("basics", () => {
assert.equal(people.is_active_user_for_popover(isaac.user_id), true);
assert.ok(people.is_valid_email_for_compose(isaac.email));
+ let bot_user_ids = people.get_bot_ids();
+ assert.equal(bot_user_ids.length, 0);
+
// Now deactivate isaac
people.deactivate(isaac);
assert.equal(people.get_non_active_human_ids().length, 1);
@@ -313,6 +316,8 @@ test_people("basics", () => {
people.add_active_user(bot_botson);
assert.equal(people.is_active_user_for_popover(bot_botson.user_id), true);
+ bot_user_ids = people.get_bot_ids();
+ assert.deepEqual(bot_user_ids, [bot_botson.user_id]);
assert.equal(people.get_bot_owner_user(bot_botson).full_name, "Isaac Newton");
@@ -336,6 +341,10 @@ test_people("basics", () => {
[me.user_id, bot_botson.user_id],
);
+ // get_bot_ids() includes all bot users.
+ bot_user_ids = people.get_bot_ids();
+ assert.deepEqual(bot_user_ids, [bot_botson.user_id, welcome_bot.user_id]);
+
// The bot doesn't add to our human count.
assert.equal(people.get_active_human_count(), 1);
diff --git a/static/js/people.js b/static/js/people.js
index 787a54fa94c..4f905076fe6 100644
--- a/static/js/people.js
+++ b/static/js/people.js
@@ -891,6 +891,18 @@ export function get_non_active_human_ids() {
return human_ids;
}
+export function get_bot_ids() {
+ const bot_ids = [];
+
+ for (const user of people_by_user_id_dict.values()) {
+ if (user.is_bot) {
+ bot_ids.push(user.user_id);
+ }
+ }
+
+ return bot_ids;
+}
+
export function get_active_human_count() {
let count = 0;
for (const person of active_user_dict.values()) {