Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

buddy list: Rename key to more accurate user_id.

evykassirer02845a1d59f6
diff --git a/web/src/activity_ui.js b/web/src/activity_ui.js
index 9a8a56aa248..ac5abf8db11 100644
--- a/web/src/activity_ui.js
+++ b/web/src/activity_ui.js
@@ -68,7 +68,7 @@ export function redraw_user(user_id) {
const info = buddy_data.get_item(user_id);
buddy_list.insert_or_move({
- key: user_id,
+ user_id,
item: info,
});
}
@@ -95,13 +95,13 @@ export function build_user_sidebar() {
const filter_text = get_filter_text();
- const user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
+ const all_user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
- buddy_list.populate({keys: user_ids});
+ buddy_list.populate({all_user_ids});
render_empty_user_list_message_if_needed(buddy_list.$container);
- return user_ids; // for testing
+ return all_user_ids; // for testing
}
function do_update_users_for_search() {
@@ -155,7 +155,7 @@ export function reset_users() {
}
export function narrow_for_user(opts) {
- const user_id = buddy_list.get_key_from_li({$li: opts.$li});
+ const user_id = buddy_list.get_user_id_from_li({$li: opts.$li});
return narrow_for_user_id({user_id});
}
diff --git a/web/src/buddy_list.js b/web/src/buddy_list.js
index 94961e8f75d..d314a101a6d 100644
--- a/web/src/buddy_list.js
+++ b/web/src/buddy_list.js
@@ -25,18 +25,18 @@ class BuddyListConf {
return html;
}
- get_li_from_key(opts) {
- const user_id = opts.key;
+ get_li_from_user_id(opts) {
+ const user_id = opts.user_id;
const $container = $(this.container_selector);
return $container.find(`${this.item_selector}[data-user-id='${CSS.escape(user_id)}']`);
}
- get_key_from_li(opts) {
+ get_user_id_from_li(opts) {
return Number.parseInt(opts.$li.expectOne().attr("data-user-id"), 10);
}
- get_data_from_keys(keys) {
- const data = buddy_data.get_items_for_users(keys);
+ get_data_from_user_ids(user_ids) {
+ const data = buddy_data.get_items_for_users(user_ids);
return data;
}
@@ -54,7 +54,7 @@ class BuddyListConf {
}
export class BuddyList extends BuddyListConf {
- keys = [];
+ all_user_ids = [];
populate(opts) {
this.render_count = 0;
@@ -62,7 +62,7 @@ export class BuddyList extends BuddyListConf {
// We rely on our caller to give us items
// in already-sorted order.
- this.keys = opts.keys;
+ this.all_user_ids = opts.all_user_ids;
this.fill_screen_with_content();
}
@@ -73,13 +73,13 @@ export class BuddyList extends BuddyListConf {
const begin = this.render_count;
const end = begin + chunk_size;
- const more_keys = this.keys.slice(begin, end);
+ const more_user_ids = this.all_user_ids.slice(begin, end);
- if (more_keys.length === 0) {
+ if (more_user_ids.length === 0) {
return;
}
- const items = this.get_data_from_keys(more_keys);
+ const items = this.get_data_from_user_ids(more_user_ids);
const html = this.items_to_html({
items,
@@ -87,13 +87,13 @@ export class BuddyList extends BuddyListConf {
this.$container = $(this.container_selector);
this.$container.append(html);
- // Invariant: more_keys.length >= items.length.
- // (Usually they're the same, but occasionally keys
+ // Invariant: more_user_ids.length >= items.length.
+ // (Usually they're the same, but occasionally user ids
// won't return valid items. Even though we don't
- // actually render these keys, we still "count" them
+ // actually render these user ids, we still "count" them
// as rendered.
- this.render_count += more_keys.length;
+ this.render_count += more_user_ids.length;
this.update_padding();
}
@@ -102,60 +102,63 @@ export class BuddyList extends BuddyListConf {
return $obj.map((_i, elem) => $(elem));
}
+ // From `type List<Key>`, where the key is a user_id.
first_key() {
- return this.keys[0];
+ return this.all_user_ids[0];
}
+ // From `type List<Key>`, where the key is a user_id.
prev_key(key) {
- const i = this.keys.indexOf(key);
+ const i = this.all_user_ids.indexOf(key);
if (i <= 0) {
return undefined;
}
- return this.keys[i - 1];
+ return this.all_user_ids[i - 1];
}
+ // From `type List<Key>`, where the key is a user_id.
next_key(key) {
- const i = this.keys.indexOf(key);
+ const i = this.all_user_ids.indexOf(key);
if (i < 0) {
return undefined;
}
- return this.keys[i + 1];
+ return this.all_user_ids[i + 1];
}
- maybe_remove_key(opts) {
- const pos = this.keys.indexOf(opts.key);
+ maybe_remove_user_id(opts) {
+ const pos = this.all_user_ids.indexOf(opts.user_id);
if (pos < 0) {
return;
}
- this.keys.splice(pos, 1);
+ this.all_user_ids.splice(pos, 1);
if (pos < this.render_count) {
this.render_count -= 1;
- const $li = this.find_li({key: opts.key});
+ const $li = this.find_li({key: opts.user_id});
$li.remove();
this.update_padding();
}
}
find_position(opts) {
- const key = opts.key;
+ const user_id = opts.user_id;
let i;
- for (i = 0; i < this.keys.length; i += 1) {
- const list_key = this.keys[i];
+ for (i = 0; i < this.all_user_ids.length; i += 1) {
+ const list_user_id = this.all_user_ids[i];
- if (this.compare_function(key, list_key) < 0) {
+ if (this.compare_function(user_id, list_user_id) < 0) {
return i;
}
}
- return this.keys.length;
+ return this.all_user_ids.length;
}
force_render(opts) {
@@ -166,7 +169,7 @@ export class BuddyList extends BuddyListConf {
const chunk_size = pos + cushion_size - this.render_count;
if (chunk_size <= 0) {
- blueslip.error("cannot show key at this position", {
+ blueslip.error("cannot show user id at this position", {
pos,
render_count: this.render_count,
chunk_size,
@@ -179,11 +182,11 @@ export class BuddyList extends BuddyListConf {
}
find_li(opts) {
- const key = opts.key;
+ const user_id = opts.key;
// Try direct DOM lookup first for speed.
- let $li = this.get_li_from_key({
- key,
+ let $li = this.get_li_from_user_id({
+ user_id,
});
if ($li.length === 1) {
@@ -196,7 +199,7 @@ export class BuddyList extends BuddyListConf {
return $li;
}
- const pos = this.keys.indexOf(key);
+ const pos = this.all_user_ids.indexOf(user_id);
if (pos < 0) {
// TODO: See ListCursor.get_row() for why this is
@@ -208,19 +211,19 @@ export class BuddyList extends BuddyListConf {
pos,
});
- $li = this.get_li_from_key({
- key,
+ $li = this.get_li_from_user_id({
+ user_id,
});
return $li;
}
insert_new_html(opts) {
- const key_following_insertion = opts.new_key;
+ const user_id_following_insertion = opts.new_user_id;
const html = opts.html;
const new_pos_in_all_users = opts.pos;
- if (key_following_insertion === undefined) {
+ if (user_id_following_insertion === undefined) {
if (new_pos_in_all_users === this.render_count) {
this.render_count += 1;
this.$container.append(html);
@@ -231,34 +234,34 @@ export class BuddyList extends BuddyListConf {
if (new_pos_in_all_users < this.render_count) {
this.render_count += 1;
- const $li = this.find_li({key: key_following_insertion});
+ const $li = this.find_li({key: user_id_following_insertion});
$li.before(html);
this.update_padding();
}
}
insert_or_move(opts) {
- const key = opts.key;
+ const user_id = opts.user_id;
const item = opts.item;
- this.maybe_remove_key({key});
+ this.maybe_remove_user_id({user_id});
const pos = this.find_position({
- key,
+ user_id,
});
- // Order is important here--get the new_key
+ // Order is important here--get the new_user_id
// before mutating our list. An undefined value
// corresponds to appending.
- const new_key = this.keys[pos];
+ const new_user_id = this.all_user_ids[pos];
- this.keys.splice(pos, 0, key);
+ this.all_user_ids.splice(pos, 0, user_id);
const html = this.item_to_html({item});
this.insert_new_html({
pos,
html,
- new_key,
+ new_user_id,
});
}
@@ -272,7 +275,7 @@ export class BuddyList extends BuddyListConf {
// Add a fudge factor.
height += 10;
- while (this.render_count < this.keys.length) {
+ while (this.render_count < this.all_user_ids.length) {
const padding_height = $(this.padding_selector).height();
const bottom_offset = elem.scrollHeight - elem.scrollTop - padding_height;
@@ -305,7 +308,7 @@ export class BuddyList extends BuddyListConf {
update_padding() {
padded_widget.update_padding({
shown_rows: this.render_count,
- total_rows: this.keys.length,
+ total_rows: this.all_user_ids.length,
content_sel: this.container_selector,
padding_selector: this.padding_selector,
});
diff --git a/web/src/compose_fade.js b/web/src/compose_fade.js
index f22cd962179..f1be5c50dcb 100644
--- a/web/src/compose_fade.js
+++ b/web/src/compose_fade.js
@@ -109,7 +109,7 @@ function fade_messages() {
const user_fade_config = {
get_user_id($li) {
- return buddy_list.get_key_from_li({$li});
+ return buddy_list.get_user_id_from_li({$li});
},
fade($li) {
return $li.addClass("user-fade");
diff --git a/web/src/user_events.js b/web/src/user_events.js
index eab38e266f9..3b4e6c15214 100644
--- a/web/src/user_events.js
+++ b/web/src/user_events.js
@@ -145,7 +145,7 @@ export const update_person = function update(person) {
people.deactivate(person_obj);
stream_events.remove_deactivated_user_from_all_streams(person.user_id);
settings_users.update_view_on_deactivate(person.user_id);
- buddy_list.maybe_remove_key({key: person.user_id});
+ buddy_list.maybe_remove_user_id({user_id: person.user_id});
}
settings_account.maybe_update_deactivate_account_button();
if (people.user_is_bot(person.user_id)) {
diff --git a/web/tests/activity.test.js b/web/tests/activity.test.js
index a2836781dee..7402c453d1c 100644
--- a/web/tests/activity.test.js
+++ b/web/tests/activity.test.js
@@ -91,7 +91,7 @@ people.initialize_current_user(me.user_id);
function clear_buddy_list() {
buddy_list.populate({
- keys: [],
+ all_user_ids: [],
});
}
@@ -302,7 +302,7 @@ test("handlers", ({override, override_rewire, mock_template}) => {
function init() {
$.clear_all_elements();
buddy_list.populate({
- keys: [me.user_id, alice.user_id, fred.user_id],
+ all_user_ids: [me.user_id, alice.user_id, fred.user_id],
});
buddy_list.start_scroll_handler = () => {};
diff --git a/web/tests/buddy_list.test.js b/web/tests/buddy_list.test.js
index 8fa4b092f12..0c536ae94a1 100644
--- a/web/tests/buddy_list.test.js
+++ b/web/tests/buddy_list.test.js
@@ -57,8 +57,8 @@ run_test("basics", ({override}) => {
const buddy_list = new BuddyList();
init_simulated_scrolling();
- override(buddy_list, "get_data_from_keys", (keys) => {
- assert.deepEqual(keys, [alice.user_id]);
+ override(buddy_list, "get_data_from_user_ids", (user_ids) => {
+ assert.deepEqual(user_ids, [alice.user_id]);
return "data-stub";
});
@@ -78,16 +78,16 @@ run_test("basics", ({override}) => {
};
buddy_list.populate({
- keys: [alice.user_id],
+ all_user_ids: [alice.user_id],
});
assert.ok(appended);
const $alice_li = {length: 1};
- override(buddy_list, "get_li_from_key", (opts) => {
- const key = opts.key;
+ override(buddy_list, "get_li_from_user_id", (opts) => {
+ const user_id = opts.user_id;
- assert.equal(key, alice.user_id);
+ assert.equal(user_id, alice.user_id);
return $alice_li;
});
@@ -127,7 +127,7 @@ run_test("big_list", ({override}) => {
});
buddy_list.populate({
- keys: user_ids,
+ all_user_ids: user_ids,
});
assert.equal(chunks_inserted, 6);
@@ -149,7 +149,7 @@ run_test("force_render", ({override}) => {
assert.equal(num_rendered, 60 - 50 + 3);
// Force a contrived error case for line coverage.
- blueslip.expect("error", "cannot show key at this position");
+ blueslip.expect("error", "cannot show user id at this position");
buddy_list.force_render({
pos: 10,
});
@@ -161,15 +161,15 @@ run_test("find_li w/force_render", ({override}) => {
// If we call find_li w/force_render set, and the
// key is not already rendered in DOM, then the
// widget will call show_key to force-render it.
- const key = "999";
+ const user_id = "999";
const $stub_li = {length: 0};
- override(buddy_list, "get_li_from_key", (opts) => {
- assert.equal(opts.key, key);
+ override(buddy_list, "get_li_from_user_id", (opts) => {
+ assert.equal(opts.user_id, user_id);
return $stub_li;
});
- buddy_list.keys = ["foo", "bar", key, "baz"];
+ buddy_list.all_user_ids = ["foo", "bar", user_id, "baz"];
let shown;
@@ -179,13 +179,13 @@ run_test("find_li w/force_render", ({override}) => {
});
const $empty_li = buddy_list.find_li({
- key,
+ key: user_id,
});
assert.equal($empty_li, $stub_li);
assert.ok(!shown);
const $li = buddy_list.find_li({
- key,
+ key: user_id,
force_render: true,
});
@@ -195,7 +195,7 @@ run_test("find_li w/force_render", ({override}) => {
run_test("find_li w/bad key", ({override}) => {
const buddy_list = new BuddyList();
- override(buddy_list, "get_li_from_key", () => ({length: 0}));
+ override(buddy_list, "get_li_from_user_id", () => ({length: 0}));
const $undefined_li = buddy_list.find_li({
key: "not-there",
@@ -212,7 +212,7 @@ run_test("scrolling", ({override}) => {
override(message_viewport, "height", () => 550);
buddy_list.populate({
- keys: [],
+ all_user_ids: [],
});
let tried_to_fill;
diff --git a/web/tests/user_search.test.js b/web/tests/user_search.test.js
index 6f8681c0aa6..03e066b556e 100644
--- a/web/tests/user_search.test.js
+++ b/web/tests/user_search.test.js
@@ -84,14 +84,14 @@ test("clear_search", ({override}) => {
// Empty because no users match this search string.
override(fake_buddy_list, "populate", (user_ids) => {
- assert.deepEqual(user_ids, {keys: []});
+ assert.deepEqual(user_ids, {all_user_ids: []});
});
set_input_val("somevalue");
assert.ok(!$("#user_search_section").hasClass("notdisplayed"));
// Now we're clearing the search string and everyone shows up again.
override(fake_buddy_list, "populate", (user_ids) => {
- assert.deepEqual(user_ids, {keys: ordered_user_ids});
+ assert.deepEqual(user_ids, {all_user_ids: ordered_user_ids});
});
$("#clear_search_people_button").trigger("click");
assert.equal($(".user-list-filter").val(), "");
@@ -166,7 +166,7 @@ test("filter_user_ids", ({override}) => {
expected_user_ids,
);
- override(fake_buddy_list, "populate", ({keys: user_ids}) => {
+ override(fake_buddy_list, "populate", ({all_user_ids: user_ids}) => {
assert.deepEqual(user_ids, expected_user_ids);
});