mirror of https://github.com/zulip/zulip.git
refactor: Rename people.get_rest_of_realm().
We want to mostly deprecate this function (see the comment I added), so I gave it a more specific name. Ideally I'd just fix `stream_create`, but it does use this function in a couple places, and it's helpful to reuse the same sort here. In one place stream_create actually unshifts the "me" user back to the top of the list, which makes sense for its use case.
This commit is contained in:
parent
405a529340
commit
54cb857fee
|
@ -264,7 +264,7 @@ run_test('set_custom_profile_field_data', () => {
|
|||
assert.equal(person.profile_data[field.id].rendered_value, '<p>Field value</p>');
|
||||
});
|
||||
|
||||
run_test('get_rest_of_realm', () => {
|
||||
run_test('get_people_for_stream_create', () => {
|
||||
const alice1 = {
|
||||
email: 'alice1@example.com',
|
||||
user_id: 202,
|
||||
|
@ -285,7 +285,7 @@ run_test('get_rest_of_realm', () => {
|
|||
people.add_in_realm(alice2);
|
||||
assert.equal(people.get_realm_count(), 3);
|
||||
|
||||
const others = people.get_rest_of_realm();
|
||||
const others = people.get_people_for_stream_create();
|
||||
const expected = [
|
||||
{ email: 'alice1@example.com', user_id: 202, full_name: 'Alice' },
|
||||
{ email: 'alice2@example.com', user_id: 203, full_name: 'Alice' },
|
||||
|
@ -347,7 +347,7 @@ run_test('filtered_users', () => {
|
|||
people.add_in_realm(plain_noah);
|
||||
|
||||
const search_term = 'a';
|
||||
const users = people.get_rest_of_realm();
|
||||
const users = people.get_people_for_stream_create();
|
||||
let filtered_people = people.filter_people_by_search_terms(users, [search_term]);
|
||||
assert.equal(filtered_people.num_items(), 2);
|
||||
assert(filtered_people.has(ashton.user_id));
|
||||
|
|
|
@ -846,7 +846,18 @@ function people_cmp(person1, person2) {
|
|||
return util.strcmp(person1.email, person2.email);
|
||||
}
|
||||
|
||||
exports.get_rest_of_realm = function get_rest_of_realm() {
|
||||
exports.get_people_for_stream_create = function () {
|
||||
/*
|
||||
If you are thinking of reusing this function,
|
||||
a better option in most cases is to just
|
||||
call `exports.get_realm_persons()` and then
|
||||
filter out the "me" user yourself as part of
|
||||
any other filtering that you are doing.
|
||||
|
||||
In particular, this function does a sort
|
||||
that is kinda expensive and may not apply
|
||||
to your use case.
|
||||
*/
|
||||
const people_minus_you = [];
|
||||
active_user_dict.each(function (person) {
|
||||
if (!exports.is_current_user(person.email)) {
|
||||
|
|
|
@ -254,7 +254,7 @@ exports.show_new_stream_modal = function () {
|
|||
$("#stream-creation").removeClass("hide");
|
||||
$(".right .settings").hide();
|
||||
|
||||
const all_users = people.get_rest_of_realm();
|
||||
const all_users = people.get_people_for_stream_create();
|
||||
// Add current user on top of list
|
||||
all_users.unshift(people.get_person_from_user_id(page_params.user_id));
|
||||
const html = render_new_stream_users({
|
||||
|
@ -352,7 +352,7 @@ exports.create_handlers_for_users = function (container) {
|
|||
return;
|
||||
}
|
||||
|
||||
const users = people.get_rest_of_realm();
|
||||
const users = people.get_people_for_stream_create();
|
||||
const filtered_users = people.filter_people_by_search_terms(users, search_terms);
|
||||
|
||||
// Be careful about modifying the follow code. A naive implementation
|
||||
|
|
Loading…
Reference in New Issue