compose: Add typeahead for user group silent mentions.

Prior to this, we restricted to show any user group suggestions
if silent mention syntax is used. But with the addition of
user group silent mentions, there are cases where one may want to
refer to some user groups without actually notifying them.
So, we add typeahead logic for such cases.

Test cases for silent syntax (@_*) and non-silent syntax (@*)
are added.
This commit is contained in:
akshatdalton 2021-05-17 12:29:54 +00:00 committed by Tim Abbott
parent f4891e7e4f
commit b636a9199b
2 changed files with 27 additions and 19 deletions

View File

@ -421,6 +421,20 @@ test("content_typeahead_selected", (override) => {
expected_value = "@**Othello, the Moor of Venice** ";
assert.equal(actual_value, expected_value);
fake_this.query = "@back";
fake_this.token = "back";
with_field(compose, "warn_if_mentioning_unsubscribed_user", unexpected_warn, () => {
actual_value = ct.content_typeahead_selected.call(fake_this, backend);
});
expected_value = "@*Backend* ";
assert.equal(actual_value, expected_value);
fake_this.query = "@*back";
fake_this.token = "back";
actual_value = ct.content_typeahead_selected.call(fake_this, backend);
expected_value = "@*Backend* ";
assert.equal(actual_value, expected_value);
// silent mention
fake_this.completing = "silent_mention";
function unexpected_warn() {
@ -454,18 +468,18 @@ test("content_typeahead_selected", (override) => {
expected_value = "@_**King Hamlet** ";
assert.equal(actual_value, expected_value);
fake_this.query = "@back";
fake_this.query = "@_back";
fake_this.token = "back";
with_field(compose, "warn_if_mentioning_unsubscribed_user", unexpected_warn, () => {
actual_value = ct.content_typeahead_selected.call(fake_this, backend);
});
expected_value = "@*Backend* ";
expected_value = "@_*Backend* ";
assert.equal(actual_value, expected_value);
fake_this.query = "@*back";
fake_this.query = "@_*back";
fake_this.token = "back";
actual_value = ct.content_typeahead_selected.call(fake_this, backend);
expected_value = "@*Backend* ";
expected_value = "@_*Backend* ";
assert.equal(actual_value, expected_value);
fake_this.query = "/m";
@ -1431,7 +1445,7 @@ test("filter_and_sort_mentions (silent)", () => {
const suggestions = ct.filter_and_sort_mentions(is_silent, "al");
assert.deepEqual(suggestions, [alice, hal]);
assert.deepEqual(suggestions, [alice, hal, call_center]);
});
test("typeahead_results", () => {
@ -1561,7 +1575,6 @@ test("muted users excluded from results", () => {
// mentions typeaheads, so we need only test once.
let results;
const opts = {
want_groups: false,
want_broadcast: true,
};
@ -1574,7 +1587,8 @@ test("muted users excluded from results", () => {
results = ct.get_person_suggestions("corde", opts);
assert.deepEqual(results, []);
// Make sure our muting logic doesn't break wildcard mentions.
// Make sure our muting logic doesn't break wildcard mentions
// or user group mentions.
results = ct.get_person_suggestions("all", opts);
assert.deepEqual(results, [mention_all]);
assert.deepEqual(results, [mention_all, call_center]);
});

View File

@ -423,7 +423,6 @@ export const slash_commands = [
export function filter_and_sort_mentions(is_silent, query, opts) {
opts = {
want_broadcast: !is_silent,
want_groups: !is_silent,
filter_pills: false,
...opts,
};
@ -433,7 +432,6 @@ export function filter_and_sort_mentions(is_silent, query, opts) {
export function get_pm_people(query) {
const opts = {
want_broadcast: false,
want_groups: true,
filter_pills: true,
};
return get_person_suggestions(query, opts);
@ -460,13 +458,7 @@ export function get_person_suggestions(query, opts) {
return persons.filter((item) => query_matches_person(query, item));
}
let groups;
if (opts.want_groups) {
groups = user_groups.get_realm_user_groups();
} else {
groups = [];
}
const groups = user_groups.get_realm_user_groups();
const filtered_groups = groups.filter((item) => query_matches_name_description(query, item));
@ -827,7 +819,9 @@ export function content_typeahead_selected(item, event) {
beginning = beginning.slice(0, -1);
}
if (user_groups.is_user_group(item)) {
beginning += "@*" + item.name + "* ";
let user_group_mention_text = is_silent ? "@_*" : "@*";
user_group_mention_text += item.name + "* ";
beginning += user_group_mention_text;
// We could theoretically warn folks if they are
// mentioning a user group that literally has zero
// members where we are posting to, but we don't have
@ -1005,7 +999,7 @@ function get_header_html() {
tip_text = $t({defaultMessage: "Press > for list of topics"});
break;
case "silent_mention":
tip_text = $t({defaultMessage: "User will not be notified"});
tip_text = $t({defaultMessage: "Silent mentions do not trigger notifications."});
break;
case "syntax":
if (page_params.realm_default_code_block_language !== null) {