Rename get_realm_persons() to get_realm_users().

The function's name was misleading, since it includes
any bots in your realm.
This commit is contained in:
Steve Howell
2020-03-21 18:53:16 +00:00
committed by Tim Abbott
parent 7ac5d0602b
commit 25d2e2e122
9 changed files with 26 additions and 13 deletions

View File

@@ -50,7 +50,7 @@ And then in `user_pill.js`...
```js ```js
exports.typeahead_source = function (pill_widget) { exports.typeahead_source = function (pill_widget) {
const persons = people.get_realm_persons(); const persons = people.get_realm_users();
return exports.filter_taken_users(persons, pill_widget); return exports.filter_taken_users(persons, pill_widget);
}; };

View File

@@ -35,7 +35,7 @@ run_test('pills', () => {
full_name: 'Hamlet', full_name: 'Hamlet',
}; };
people.get_realm_persons = function () { people.get_realm_users = function () {
return [iago, othello, hamlet]; return [iago, othello, hamlet];
}; };

View File

@@ -50,13 +50,15 @@ function get_all_persons() {
run_test('basics', () => { run_test('basics', () => {
const persons = get_all_persons(); const persons = get_all_persons();
assert.deepEqual(people.get_realm_users(), [me]);
assert.equal(persons.length, 1); assert.equal(persons.length, 1);
assert.equal(persons[0].full_name, 'Me Myself'); assert.equal(persons[0].full_name, 'Me Myself');
let realm_persons = people.get_realm_persons(); let realm_persons = people.get_realm_users();
assert.equal(realm_persons[0].full_name, 'Me Myself'); assert.equal(realm_persons[0].full_name, 'Me Myself');
realm_persons = people.get_realm_persons(); realm_persons = people.get_realm_users();
assert.equal(realm_persons.length, 1); assert.equal(realm_persons.length, 1);
assert.equal(people.get_active_human_count(), 1); assert.equal(people.get_active_human_count(), 1);
@@ -89,7 +91,7 @@ run_test('basics', () => {
person = people.get_active_user_for_email(email); person = people.get_active_user_for_email(email);
assert.equal(person.email, email); assert.equal(person.email, email);
realm_persons = people.get_realm_persons(); realm_persons = people.get_realm_users();
assert.equal(realm_persons.length, 2); assert.equal(realm_persons.length, 2);
const active_user_ids = people.get_active_user_ids().sort(); const active_user_ids = people.get_active_user_ids().sort();
@@ -114,6 +116,16 @@ run_test('basics', () => {
people.add_in_realm(bot_botson); people.add_in_realm(bot_botson);
assert.equal(people.is_active_user_for_popover(bot_botson.user_id), true); assert.equal(people.is_active_user_for_popover(bot_botson.user_id), true);
// get_realm_users() will include our active bot,
// but will exclude isaac (who is deactivated)
assert.deepEqual(
people.get_realm_users().map((u) => u.user_id).sort(),
[
me.user_id,
bot_botson.user_id,
]
);
// The bot doesn't add to our human count. // The bot doesn't add to our human count.
assert.equal(people.get_active_human_count(), 1); assert.equal(people.get_active_human_count(), 1);

View File

@@ -112,7 +112,7 @@ run_test('populate_user_groups', () => {
full_name: 'Bob', full_name: 'Bob',
}; };
people.get_realm_persons = function () { people.get_realm_users = function () {
return [iago, alice, bob]; return [iago, alice, bob];
}; };
@@ -344,7 +344,7 @@ run_test('with_external_user', () => {
}; };
// We return noop because these are already tested, so we skip them // We return noop because these are already tested, so we skip them
people.get_realm_persons = function () { people.get_realm_users = function () {
return noop; return noop;
}; };

View File

@@ -207,7 +207,7 @@ for (const person of matches) {
function get_typeahead_result(query, current_stream, current_topic) { function get_typeahead_result(query, current_stream, current_topic) {
const result = th.sort_recipients( const result = th.sort_recipients(
global.people.get_realm_persons(), global.people.get_realm_users(),
query, query,
current_stream, current_stream,
current_topic current_topic

View File

@@ -470,7 +470,7 @@ exports.get_person_suggestions = function (query, opts) {
filtered_persons = filtered_message_persons; filtered_persons = filtered_message_persons;
} else { } else {
filtered_persons = filter_persons( filtered_persons = filter_persons(
people.get_realm_persons() people.get_realm_users()
); );
} }

View File

@@ -685,7 +685,8 @@ exports.filter_all_users = function (pred) {
return ret; return ret;
}; };
exports.get_realm_persons = function () { exports.get_realm_users = function () {
// includes humans and bots from your realm
return Array.from(active_user_dict.values()); return Array.from(active_user_dict.values());
}; };
@@ -921,7 +922,7 @@ exports.get_people_for_stream_create = function () {
/* /*
If you are thinking of reusing this function, If you are thinking of reusing this function,
a better option in most cases is to just a better option in most cases is to just
call `exports.get_realm_persons()` and then call `exports.get_realm_users()` and then
filter out the "me" user yourself as part of filter out the "me" user yourself as part of
any other filtering that you are doing. any other filtering that you are doing.

View File

@@ -147,7 +147,7 @@ exports.update_info_for_small_realm = function () {
// For small realms, we create presence info for users // For small realms, we create presence info for users
// that the server didn't include in its presence update. // that the server didn't include in its presence update.
const persons = people.get_realm_persons(); const persons = people.get_realm_users();
for (const person of persons) { for (const person of persons) {
const user_id = person.user_id; const user_id = person.user_id;

View File

@@ -86,7 +86,7 @@ exports.has_unconverted_data = function (pill_widget) {
}; };
exports.typeahead_source = function (pill_widget) { exports.typeahead_source = function (pill_widget) {
const persons = people.get_realm_persons(); const persons = people.get_realm_users();
return exports.filter_taken_users(persons, pill_widget); return exports.filter_taken_users(persons, pill_widget);
}; };