buddy list: Show self in search results.

We should search for what the user asked us to search for.
CZO conversation:
https://chat.zulip.org/#narrow/stream/101-design/topic/search.20buddy.20list.20for.20self/near/1630454

This commit also stops the user from being at the top of
the search list, so that the search list is fully
alphabetical (though still sorted by online status).

We switch to not having the user at the top of the list
only when there's search text in the search bar, otherwise
there'd be a visual jump that would happen just by opening
the search bar. There's almost always visual change when
entering text into the search input field, so that seems
like the time to change the sorting.
This commit is contained in:
evykassirer 2023-08-23 16:33:39 -07:00 committed by Tim Abbott
parent 35e4be0b68
commit 605c4688b1
4 changed files with 43 additions and 19 deletions

View File

@ -23,6 +23,11 @@ import * as util from "./util";
export const max_size_before_shrinking = 600;
let is_searching_users = false;
export function set_is_searching_users(val) {
is_searching_users = val;
}
const fade_config = {
get_user_id(item) {
return item.user_id;
@ -49,8 +54,8 @@ export function get_user_circle_class(user_id) {
}
export function level(user_id) {
if (people.is_my_user_id(user_id)) {
// Always put current user at the top.
// Put current user at the top, unless we're in a user search view.
if (people.is_my_user_id(user_id) && !is_searching_users) {
return 0;
}
@ -280,8 +285,6 @@ function filter_user_ids(user_filter_text, user_ids) {
}
// If a query is present in "Search people", we return matches.
user_ids = user_ids.filter((user_id) => !people.is_my_user_id(user_id));
let search_terms = user_filter_text.toLowerCase().split(/[,|]+/);
search_terms = search_terms.map((s) => s.trim());

View File

@ -1,5 +1,6 @@
import $ from "jquery";
import * as buddy_data from "./buddy_data";
import * as popovers from "./popovers";
import * as resize from "./resize";
import * as sidebar_ui from "./sidebar_ui";
@ -20,7 +21,10 @@ export class UserSearch {
$("#clear_search_people_button").on("click", () => this.clear_search());
$("#userlist-header").on("click", () => this.toggle_filter_displayed());
this.$input.on("input", opts.update_list);
this.$input.on("input", () => {
buddy_data.set_is_searching_users(this.$input.val() !== "");
opts.update_list();
});
this.$input.on("focus", (e) => this.on_focus(e));
}
@ -41,6 +45,8 @@ export class UserSearch {
}
clear_search() {
buddy_data.set_is_searching_users(false);
if (this.empty()) {
this.close_widget();
return;

View File

@ -334,7 +334,7 @@ test("simple search", () => {
set_presence(selma.user_id, "active");
set_presence(me.user_id, "active");
const user_ids = buddy_data.get_filtered_and_sorted_user_ids("sel");
const user_ids = buddy_data.get_filtered_and_sorted_user_ids("selm");
assert.deepEqual(user_ids, [selma.user_id]);
});
@ -345,14 +345,14 @@ test("muted users excluded from search", () => {
let user_ids = buddy_data.get_filtered_and_sorted_user_ids();
assert.equal(user_ids.includes(selma.user_id), false);
user_ids = buddy_data.get_filtered_and_sorted_user_ids("sel");
user_ids = buddy_data.get_filtered_and_sorted_user_ids("selm");
assert.deepEqual(user_ids, []);
assert.ok(!buddy_data.matches_filter("sel", selma.user_id));
assert.ok(!buddy_data.matches_filter("selm", selma.user_id));
muted_users.remove_muted_user(selma.user_id);
user_ids = buddy_data.get_filtered_and_sorted_user_ids("sel");
user_ids = buddy_data.get_filtered_and_sorted_user_ids("selm");
assert.deepEqual(user_ids, [selma.user_id]);
assert.ok(buddy_data.matches_filter("sel", selma.user_id));
assert.ok(buddy_data.matches_filter("selm", selma.user_id));
});
test("bulk_data_hacks", ({override_rewire}) => {
@ -398,9 +398,9 @@ test("bulk_data_hacks", ({override_rewire}) => {
assert.equal(user_ids.length, 0);
// We match on "h" for the first name, and the result limit
// is relaxed for searches. (We exclude "me", though.)
// is relaxed for searches.
user_ids = buddy_data.get_filtered_and_sorted_user_ids("h");
assert.equal(user_ids.length, 996);
assert.equal(user_ids.length, 997);
// We match on "p" for the email.
user_ids = buddy_data.get_filtered_and_sorted_user_ids("p");

View File

@ -76,16 +76,28 @@ function test(label, f) {
});
}
function set_input_val(val) {
$(".user-list-filter").val(val);
$(".user-list-filter").trigger("input");
}
test("clear_search", ({override}) => {
override(presence, "get_status", () => "active");
override(presence, "get_user_ids", () => all_user_ids);
override(popovers, "hide_all_except_sidebars", () => {});
override(resize, "resize_sidebars", () => {});
// Empty because no users match this search string.
override(fake_buddy_list, "populate", (user_ids) => {
assert.deepEqual(user_ids, {keys: []});
});
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});
});
override(presence, "get_status", () => "active");
override(presence, "get_user_ids", () => all_user_ids);
override(resize, "resize_sidebars", () => {});
$(".user-list-filter").val("somevalue");
assert.ok(!$("#user_search_section").hasClass("notdisplayed"));
$("#clear_search_people_button").trigger("click");
assert.equal($(".user-list-filter").val(), "");
$("#clear_search_people_button").trigger("click");
@ -98,11 +110,14 @@ test("escape_search", ({override}) => {
override(resize, "resize_sidebars", () => {});
override(popovers, "hide_all_except_sidebars", () => {});
$(".user-list-filter").val("somevalue");
set_input_val("somevalue");
activity.escape_search();
assert.equal($(".user-list-filter").val(), "");
activity.escape_search();
assert.ok($("#user_search_section").hasClass("notdisplayed"));
// We need to reset this because the unit tests aren't isolated from each other.
set_input_val("");
});
test("blur search right", ({override}) => {