diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index 80dc0a35a3..103d9cec76 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -64,15 +64,23 @@ initialize(); var human_user_ids = people.get_realm_human_user_ids(); assert.deepEqual(human_user_ids, [isaac.user_id]); - assert.equal(people.realm_user_is_active_human(isaac.user_id), true); + assert.equal(people.realm_user_is_active_human_or_bot(isaac.user_id), true); // Now deactivate isaac people.deactivate(isaac); person = people.realm_get(email); assert(!person); assert.equal(people.get_realm_count(), 0); - assert.equal(people.realm_user_is_active_human(isaac.user_id), false); + assert.equal(people.realm_user_is_active_human_or_bot(isaac.user_id), false); + var bot_botson = { + email: 'botson-bot@example.com', + user_id: 35, + full_name: 'Bot Botson', + is_bot: true, + }; + people.add(bot_botson); + assert.equal(people.realm_user_is_active_human_or_bot(bot_botson.user_id), true); // We can still get their info for non-realm needs. person = people.get_by_email(email); diff --git a/static/js/people.js b/static/js/people.js index 7cfe17df24..f658a2f48a 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -530,8 +530,19 @@ exports.realm_get = function realm_get(email) { return realm_people_dict.get(person.user_id); }; -exports.realm_user_is_active_human = function (id) { - return !!realm_people_dict.get(id); +exports.realm_user_is_active_human_or_bot = function (id) { + if (realm_people_dict.get(id) !== undefined) { + return true; + } + // TODO: Technically, we should probably treat deactivated bots + // like deactivated users here. But we don't have the data to do + // that. See #7153 for notes on fixing this. + var person = exports.get_person_from_user_id(id); + if (person === undefined) { + blueslip.error("Unexpectedly invalid user ID in user popover query " + id); + return false; + } + return !!person.is_bot; }; exports.get_all_persons = function () { diff --git a/static/js/popovers.js b/static/js/popovers.js index fb324e5c60..861e1a97ba 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -100,7 +100,7 @@ function show_user_info_popover(element, user, message) { sent_by_uri: narrow.by_sender_uri(user.email), narrowed: narrow_state.active(), private_message_class: "respond_personal_button", - is_active: people.realm_user_is_active_human(user.user_id), + is_active: people.realm_user_is_active_human_or_bot(user.user_id), }; var ypos = elt.offset().top; @@ -448,7 +448,7 @@ exports.register_click_handlers = function () { pm_with_uri: narrow.pm_with_uri(user_email), sent_by_uri: narrow.by_sender_uri(user_email), private_message_class: "compose_private_message", - is_active: people.realm_user_is_active_human(user_id), + is_active: people.realm_user_is_active_human_or_bot(user_id), }; target.popover({