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.

people: Fix `get_mention_syntax` when `full_name` matches wildcard.

akshatdalton78b59fa75605
diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js
index 4c23473bcff..697eae3a564 100644
--- a/frontend_tests/node_tests/people.js
+++ b/frontend_tests/node_tests/people.js
@@ -233,6 +233,18 @@ const plain_noah = {
full_name: "Nooaah Emerson",
};
+const all1 = {
+ email: "[email protected]",
+ user_id: 1202,
+ full_name: "all",
+};
+
+const all2 = {
+ email: "[email protected]",
+ user_id: 1203,
+ full_name: "all",
+};
+
// This is for error checking--never actually
// tell people.js about this user.
const unknown_user = {
@@ -1014,6 +1026,16 @@ test_people("get_mention_syntax", () => {
assert.equal(people.get_mention_syntax("Stephen King", 601), "@**Stephen King|601**");
assert.equal(people.get_mention_syntax("Stephen King", 602), "@**Stephen King|602**");
assert.equal(people.get_mention_syntax("Maria Athens", 603), "@**Maria Athens**");
+
+ // Following tests handle a special case when `full_name` matches with a wildcard.
+ //
+ // At this point, there is no duplicate full name, `all`, so we should still get
+ // mention syntax with `user_id` appended to it.
+ people.add_active_user(all1);
+ assert.equal(people.get_mention_syntax("all", 1202), "@**all|1202**");
+
+ people.add_active_user(all2);
+ assert.equal(people.get_mention_syntax("all", 1203), "@**all|1203**");
});
test_people("initialize", () => {
diff --git a/static/js/people.js b/static/js/people.js
index 5ced8eb1f8b..9a11339fda3 100644
--- a/static/js/people.js
+++ b/static/js/people.js
@@ -1108,13 +1108,20 @@ export function get_mention_syntax(full_name, user_id, silent) {
if (!user_id) {
blueslip.warn("get_mention_syntax called without user_id.");
}
- if (is_duplicate_full_name(full_name) && user_id) {
+ if (
+ (is_duplicate_full_name(full_name) || full_name_matches_wildcard_mention(full_name)) &&
+ user_id
+ ) {
mention += "|" + user_id;
}
mention += "**";
return mention;
}
+function full_name_matches_wildcard_mention(full_name) {
+ return ["all", "everyone", "stream"].includes(full_name);
+}
+
export function _add_user(person) {
/*
This is common code to add any user, even