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: Suggest only the first matching wildcard mention.

Prakhar Pratyushfa063e4afc4e
diff --git a/web/src/typeahead_helper.js b/web/src/typeahead_helper.js
index 80f170c1b03..4a71004c6ac 100644
--- a/web/src/typeahead_helper.js
+++ b/web/src/typeahead_helper.js
@@ -390,12 +390,25 @@ export function sort_recipients({
}
}
+ // We suggest only the first matching wildcard mention,
+ // irrespective of how many equivalent wildcard mentions match.
+ const recipients = [];
+ let wildcard_mention_included = false;
+ for (const item of items) {
+ if (!item.is_broadcast || !wildcard_mention_included) {
+ recipients.push(item);
+ if (item.is_broadcast) {
+ wildcard_mention_included = true;
+ }
+ }
+ }
+
// We don't push exact matches to the top, like we do with other
// typeaheads, because in open organizations, it's not uncommon to
// have a bunch of inactive users with display names that are just
// FirstName, which we don't want to artificially prioritize over the
// the lone active user whose name is FirstName LastName.
- return items.slice(0, max_num_items);
+ return recipients.slice(0, max_num_items);
}
function slash_command_comparator(slash_command_a, slash_command_b) {
diff --git a/web/tests/composebox_typeahead.test.js b/web/tests/composebox_typeahead.test.js
index 12ae928633f..4236fa757fa 100644
--- a/web/tests/composebox_typeahead.test.js
+++ b/web/tests/composebox_typeahead.test.js
@@ -1694,6 +1694,24 @@ test("typeahead_results", () => {
// Verify we're not matching on a terms that only appear in the description.
assert_mentions_matches("characters of", []);
+ // Verify we suggest only the first matching wildcard mention,
+ // irrespective of how many equivalent wildcard mentions match.
+ const mention_everyone = ct.broadcast_mentions()[1];
+ // Here, we suggest only "everyone" instead of both the matching
+ // "everyone" and "stream" wildcard mentions.
+ assert_mentions_matches("e", [
+ mention_everyone,
+ hal,
+ alice,
+ cordelia,
+ gael,
+ hamlet,
+ lear,
+ othello,
+ hamletcharacters,
+ call_center,
+ ]);
+
// Autocomplete by slash commands.
assert_slash_matches("me", [me_slash]);
assert_slash_matches("dark", [dark_slash]);
diff --git a/web/tests/typeahead_helper.test.js b/web/tests/typeahead_helper.test.js
index be5d7ecd36d..b4e10e7a75a 100644
--- a/web/tests/typeahead_helper.test.js
+++ b/web/tests/typeahead_helper.test.js
@@ -529,7 +529,7 @@ test("sort_recipients dup alls", () => {
current_topic: "Linux topic",
});
- const expected = [all_obj, all_obj, a_user];
+ const expected = [all_obj, a_user];
assertSameEmails(recipients, expected);
});
@@ -545,7 +545,7 @@ test("sort_recipients dup alls direct message", () => {
query: "a",
});
- const expected = [a_user, all_obj, all_obj];
+ const expected = [a_user, all_obj];
assertSameEmails(recipients, expected);
});