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.

typeahead_helper: Place bots under group matches.

Aman Agrawal5c7a7740265e
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts
index 837ae4d2c08..f06a57b176a 100644
--- a/web/src/typeahead_helper.ts
+++ b/web/src/typeahead_helper.ts
@@ -260,12 +260,6 @@ export function compare_by_pms(user_a: User, user_b: User): number {
return 1;
}
- if (!user_a.is_bot && user_b.is_bot) {
- return -1;
- } else if (user_a.is_bot && !user_b.is_bot) {
- return 1;
- }
-
// We use alpha sort as a tiebreaker, which might be helpful for
// new users.
if (user_a.full_name < user_b.full_name) {
@@ -506,12 +500,25 @@ export let sort_recipients = <UserType extends UserOrMentionPillData | UserPillD
return sort_people_for_relevance(items, current_stream_id, current_topic);
}
+ function is_bot(user: UserType): boolean {
+ // broadcasts are not bots by definition.
+ return user.type !== "broadcast" && user.user.is_bot;
+ }
+
+ const [bots, non_bots] = _.partition(users, is_bot);
+
const {best_users, ok_users, worst_users} = get_user_matches_with_quality(
- users,
+ non_bots,
query,
sort_relevance,
);
+ const {
+ best_users: best_bots,
+ ok_users: ok_bots,
+ worst_users: worst_bots,
+ } = get_user_matches_with_quality(bots, query, sort_relevance);
+
const groups_results = typeahead.triage_raw_with_multiple_items(query, groups, (g) => {
if (g.name === "role:members") {
return [
@@ -549,10 +556,18 @@ export let sort_recipients = <UserType extends UserOrMentionPillData | UserPillD
getter: best_groups,
type: "groups",
},
+ {
+ getter: best_bots,
+ type: "users",
+ },
{
getter: ok_users,
type: "users",
},
+ {
+ getter: ok_bots,
+ type: "users",
+ },
{
getter: worst_users,
type: "users",
@@ -561,6 +576,10 @@ export let sort_recipients = <UserType extends UserOrMentionPillData | UserPillD
getter: worst_groups,
type: "groups",
},
+ {
+ getter: worst_bots,
+ type: "users",
+ },
];
// We suggest only the first matching stream wildcard mention,
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index f2de22ac5cd..e04ec6eff2a 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -311,6 +311,7 @@ const ali = {
user_id: 98,
full_name: "Ali",
is_moderator: false,
+ is_bot: false,
};
const ali_item = user_item(ali);
@@ -319,6 +320,7 @@ const alice = {
user_id: 99,
full_name: "Alice",
is_moderator: false,
+ is_bot: false,
};
const alice_item = user_item(alice);
@@ -327,6 +329,7 @@ const hamlet = {
user_id: 100,
full_name: "King Hamlet",
is_moderator: false,
+ is_bot: false,
};
const hamlet_item = user_item(hamlet);
@@ -336,6 +339,7 @@ const othello = {
full_name: "Othello, the Moor of Venice",
is_moderator: false,
delivery_email: null,
+ is_bot: false,
};
const othello_item = user_item(othello);
@@ -344,6 +348,7 @@ const cordelia = {
user_id: 102,
full_name: "Cordelia, Lear's daughter",
is_moderator: false,
+ is_bot: false,
};
const cordelia_item = user_item(cordelia);
@@ -352,6 +357,7 @@ const deactivated_user = {
user_id: 103,
full_name: "Deactivated User",
is_moderator: false,
+ is_bot: false,
};
const deactivated_user_item = user_item(deactivated_user);
@@ -360,6 +366,7 @@ const lear = {
user_id: 104,
full_name: "King Lear",
is_moderator: false,
+ is_bot: false,
};
const lear_item = user_item(lear);
@@ -368,6 +375,7 @@ const twin1 = {
is_moderator: false,
user_id: 105,
+ is_bot: false,
};
const twin1_item = user_item(twin1);
@@ -376,6 +384,7 @@ const twin2 = {
is_moderator: false,
user_id: 106,
+ is_bot: false,
};
const twin2_item = user_item(twin2);
@@ -384,6 +393,7 @@ const gael = {
is_moderator: false,
user_id: 107,
+ is_bot: false,
};
const gael_item = user_item(gael);
@@ -392,6 +402,7 @@ const hal = {
is_moderator: false,
user_id: 108,
+ is_bot: false,
};
const hal_item = user_item(hal);
@@ -400,6 +411,7 @@ const harry = {
is_moderator: false,
user_id: 109,
+ is_bot: false,
};
const harry_item = user_item(harry);
diff --git a/web/tests/typeahead_helper.test.cjs b/web/tests/typeahead_helper.test.cjs
index da94e9d845d..e7b56204a0c 100644
--- a/web/tests/typeahead_helper.test.cjs
+++ b/web/tests/typeahead_helper.test.cjs
@@ -504,6 +504,17 @@ test("sort_recipients", () => {
]);
+ // Test match by email (To get coverage for ok_users and ok_bots)
+ assert.deepEqual(get_typeahead_result("[email protected]", ""), [
+ ]);
+
// Typeahead for direct message [query, "", ""]
assert.deepEqual(get_typeahead_result("a", "", ""), [
@@ -550,10 +561,10 @@ test("sort_recipients", () => {
// Typeahead for stream message [query, stream-id, topic-name]
assert.deepEqual(get_typeahead_result("b", dev_sub.stream_id, "Dev topic"), [
- subscriber_email_3,
subscriber_email_2,
subscriber_email_1,
+ subscriber_email_3,
@@ -577,9 +588,9 @@ test("sort_recipients", () => {
]);
});
@@ -626,8 +637,8 @@ test("sort_recipients pm counts", () => {
assert.deepEqual(get_typeahead_result("b"), [