mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
refactor: Move user-sorting code to people.js.
We also remove the blueslip check, since it is pretty easy to audit the callers here.
This commit is contained in:
@@ -372,6 +372,31 @@ test_people("basics", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test_people("sort_but_pin_current_user_on_top with me", () => {
|
||||||
|
people.add_active_user(maria);
|
||||||
|
people.add_active_user(steven);
|
||||||
|
|
||||||
|
// We need the actual object from people.js, not the
|
||||||
|
// "me" object we made a copy of.
|
||||||
|
const my_user = people.get_by_user_id(me.user_id);
|
||||||
|
const users = [steven, debbie, maria, my_user];
|
||||||
|
|
||||||
|
people.sort_but_pin_current_user_on_top(users);
|
||||||
|
|
||||||
|
assert.deepEqual(users, [my_user, debbie, maria, steven]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test_people("sort_but_pin_current_user_on_top without me", () => {
|
||||||
|
people.add_active_user(maria);
|
||||||
|
people.add_active_user(steven);
|
||||||
|
|
||||||
|
const users = [steven, maria];
|
||||||
|
|
||||||
|
people.sort_but_pin_current_user_on_top(users);
|
||||||
|
|
||||||
|
assert.deepEqual(users, [maria, steven]);
|
||||||
|
});
|
||||||
|
|
||||||
test_people("check_active_non_active_users", () => {
|
test_people("check_active_non_active_users", () => {
|
||||||
people.add_active_user(bot_botson);
|
people.add_active_user(bot_botson);
|
||||||
people.add_active_user(isaac);
|
people.add_active_user(isaac);
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ test_ui("subscriber_pills", ({override, mock_template}) => {
|
|||||||
() => "stream_subscription_request_result",
|
() => "stream_subscription_request_result",
|
||||||
);
|
);
|
||||||
|
|
||||||
override(stream_edit, "sort_but_pin_current_user_on_top", noop);
|
override(people, "sort_but_pin_current_user_on_top", noop);
|
||||||
|
|
||||||
const subscriptions_table_selector = "#subscriptions_table";
|
const subscriptions_table_selector = "#subscriptions_table";
|
||||||
const input_field_stub = $.create(".input");
|
const input_field_stub = $.create(".input");
|
||||||
|
|||||||
@@ -1387,6 +1387,21 @@ export function is_my_user_id(user_id) {
|
|||||||
return user_id === my_user_id;
|
return user_id === my_user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compare_by_name(a, b) {
|
||||||
|
return util.strcmp(a.full_name, b.full_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sort_but_pin_current_user_on_top(users) {
|
||||||
|
const my_user = people_by_user_id_dict.get(my_user_id);
|
||||||
|
if (users.includes(my_user)) {
|
||||||
|
users.splice(users.indexOf(my_user), 1);
|
||||||
|
users.sort(compare_by_name);
|
||||||
|
users.unshift(my_user);
|
||||||
|
} else {
|
||||||
|
users.sort(compare_by_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function initialize(my_user_id, params) {
|
export function initialize(my_user_id, params) {
|
||||||
for (const person of params.realm_users) {
|
for (const person of params.realm_users) {
|
||||||
add_active_user(person);
|
add_active_user(person);
|
||||||
|
|||||||
@@ -51,10 +51,6 @@ function setup_subscriptions_stream_hash(sub) {
|
|||||||
browser_history.update(hash);
|
browser_history.update(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
function compare_by_name(a, b) {
|
|
||||||
return util.strcmp(a.full_name, b.full_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setup_subscriptions_tab_hash(tab_key_value) {
|
export function setup_subscriptions_tab_hash(tab_key_value) {
|
||||||
if (tab_key_value === "all-streams") {
|
if (tab_key_value === "all-streams") {
|
||||||
browser_history.update("#streams/all");
|
browser_history.update("#streams/all");
|
||||||
@@ -341,23 +337,6 @@ export function remove_user_from_stream(user_id, sub, success, failure) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sort_but_pin_current_user_on_top(users) {
|
|
||||||
if (users === undefined) {
|
|
||||||
blueslip.error("Undefined users are passed to function sort_but_pin_current_user_on_top");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const my_user = people.get_by_email(people.my_current_email());
|
|
||||||
const compare_function = compare_by_name;
|
|
||||||
if (users.includes(my_user)) {
|
|
||||||
users.splice(users.indexOf(my_user), 1);
|
|
||||||
users.sort(compare_function);
|
|
||||||
users.unshift(my_user);
|
|
||||||
} else {
|
|
||||||
users.sort(compare_function);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function create_item_from_text(text, current_items) {
|
export function create_item_from_text(text, current_items) {
|
||||||
const funcs = [
|
const funcs = [
|
||||||
stream_pill.create_item_from_stream_name,
|
stream_pill.create_item_from_stream_name,
|
||||||
@@ -423,7 +402,7 @@ function enable_subscriber_management({sub, parent_container}) {
|
|||||||
|
|
||||||
const user_ids = peer_data.get_subscribers(stream_id);
|
const user_ids = peer_data.get_subscribers(stream_id);
|
||||||
const users = get_users_from_subscribers(user_ids);
|
const users = get_users_from_subscribers(user_ids);
|
||||||
sort_but_pin_current_user_on_top(users);
|
people.sort_but_pin_current_user_on_top(users);
|
||||||
|
|
||||||
function get_users_for_subscriber_typeahead() {
|
function get_users_for_subscriber_typeahead() {
|
||||||
const potential_subscribers = peer_data.potential_subscribers(stream_id);
|
const potential_subscribers = peer_data.potential_subscribers(stream_id);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {$t} from "./i18n";
|
|||||||
import * as ListWidget from "./list_widget";
|
import * as ListWidget from "./list_widget";
|
||||||
import {page_params} from "./page_params";
|
import {page_params} from "./page_params";
|
||||||
import * as peer_data from "./peer_data";
|
import * as peer_data from "./peer_data";
|
||||||
|
import * as people from "./people";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as stream_edit from "./stream_edit";
|
import * as stream_edit from "./stream_edit";
|
||||||
import * as stream_settings_containers from "./stream_settings_containers";
|
import * as stream_settings_containers from "./stream_settings_containers";
|
||||||
@@ -193,7 +194,7 @@ export function update_subscribers_list(sub) {
|
|||||||
// Perform re-rendering only when the stream settings form of the corresponding
|
// Perform re-rendering only when the stream settings form of the corresponding
|
||||||
// stream is open.
|
// stream is open.
|
||||||
if (subscribers_list) {
|
if (subscribers_list) {
|
||||||
stream_edit.sort_but_pin_current_user_on_top(users);
|
people.sort_but_pin_current_user_on_top(users);
|
||||||
subscribers_list.replace_list_data(users);
|
subscribers_list.replace_list_data(users);
|
||||||
}
|
}
|
||||||
$(".subscriber_list_settings_container").show();
|
$(".subscriber_list_settings_container").show();
|
||||||
|
|||||||
Reference in New Issue
Block a user