mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
typeahead: Suggest only the first matching wildcard mention.
We suggest only the first matching wildcard mention, irrespective of how many equivalent wildcard mentions match. This helps to avoid suggesting multiple wildcard mentions at the same time that do the same thing but have different names. Fixes #25613.
This commit is contained in:
committed by
Tim Abbott
parent
fe2d6c07fb
commit
fa063e4afc
@@ -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) {
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user