bot settings: Load bots independently.

We no longer use `/json/users` in the codepath
for bot settings (admin side).

We also specifically don't load human users when
we load bots, so you no longer have to pay for
the server round trip as a side effect of loading
bots.  Instead, there is a dedicated `set_up_bots`
entry point.

We also get the bot ids directly from `bot_data` now.

This commit, to some degree, builds on the prior commit
that had us hydrate data from `people.js` instead
of the payload from `/json/users`.
This commit is contained in:
Steve Howell
2020-05-09 18:06:14 +00:00
committed by Tim Abbott
parent f6b1176045
commit 5c16bb9c99
4 changed files with 28 additions and 10 deletions

View File

@@ -113,6 +113,12 @@ run_test('test_basics', () => {
assert.equal(bot.is_active, false);
}());
(function test_all_user_ids() {
const all_ids = bot_data.all_user_ids();
all_ids.sort();
assert.deepEqual(all_ids, [143, 314, 42, 43]);
}());
(function test_delete() {
let bot;

View File

@@ -23,6 +23,10 @@ const send_change_event = _.debounce(function () {
settings_bots.render_bots();
}, 50);
exports.all_user_ids = function () {
return Array.from(bots.keys());
};
exports.add = function (bot) {
const clean_bot = _.pick(bot, bot_fields);
bots.set(bot.user_id, clean_bot);

View File

@@ -12,6 +12,8 @@ exports.get_group = function (section) {
return 'org_misc';
case 'bot-list-admin':
return 'org_bots';
case 'user-list-admin':
case 'deactivated-users-admin':
return 'org_users';
@@ -33,7 +35,8 @@ exports.initialize = function () {
// org
load_func_dict.set('org_misc', settings_org.set_up);
load_func_dict.set('org_users', settings_users.set_up);
load_func_dict.set('org_bots', settings_users.set_up_bots);
load_func_dict.set('org_users', settings_users.set_up_humans);
load_func_dict.set('emoji-settings', settings_emoji.set_up);
load_func_dict.set('default-streams-list', settings_streams.set_up);
load_func_dict.set('filter-settings', settings_linkifiers.set_up);

View File

@@ -120,17 +120,19 @@ function get_status_field() {
function failed_listing_users(xhr) {
loading.destroy_indicator($('#subs_page_loading_indicator'));
const status = get_status_field();
ui_report.error(i18n.t("Error listing users or bots"), xhr, status);
ui_report.error(i18n.t("Error listing users"), xhr, status);
}
function populate_users(realm_people_data) {
let active_users = [];
let deactivated_users = [];
let bots = [];
for (const user of realm_people_data.members) {
if (user.is_bot) {
bots.push(user);
} else if (user.is_active) {
continue;
}
if (user.is_active) {
active_users.push(user);
} else {
deactivated_users.push(user);
@@ -139,11 +141,9 @@ function populate_users(realm_people_data) {
active_users = _.sortBy(active_users, 'full_name');
deactivated_users = _.sortBy(deactivated_users, 'full_name');
bots = _.sortBy(bots, 'full_name');
section.active.create_table(active_users);
section.deactivated.create_table(deactivated_users);
section.bots.create_table(bots);
}
function reset_scrollbar($sel) {
@@ -237,9 +237,10 @@ function human_info(person) {
return info;
}
section.bots.create_table = (bots) => {
section.bots.create_table = () => {
const $bots_table = $("#admin_bots_table");
const bot_user_ids = bots.map(b => b.user_id);
const bot_user_ids = bot_data.all_user_ids();
list_render.create($bots_table, bot_user_ids, {
name: "admin_bot_list",
get_item: bot_info,
@@ -660,11 +661,15 @@ section.bots.handle_events = () => {
handle_bot_form(tbody, status_field);
};
exports.set_up = function () {
exports.set_up_humans = function () {
start_data_load();
section.active.handle_events();
section.deactivated.handle_events();
};
exports.set_up_bots = function () {
section.bots.handle_events();
section.bots.create_table();
};
window.settings_users = exports;