mirror of https://github.com/zulip/zulip.git
util: Fix the 'find_wildcard_mentions' function.
The function considers @**all**, @**everyone**, @**stream**, and @**topic** as wildcard mentions. Earlier, the function didn't have a check to match @**topic** in the message_content.
This commit is contained in:
parent
1a867a43a7
commit
b274169ccc
|
@ -193,7 +193,7 @@ export class CachedValue<T> {
|
|||
}
|
||||
|
||||
export function find_wildcard_mentions(message_content: string): string | null {
|
||||
const mention = message_content.match(/(^|\s)(@\*{2}(all|everyone|stream)\*{2})($|\s)/);
|
||||
const mention = message_content.match(/(^|\s)(@\*{2}(all|everyone|stream|topic)\*{2})($|\s)/);
|
||||
if (mention === null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ run_test("random_int", () => {
|
|||
});
|
||||
});
|
||||
|
||||
run_test("all_and_everyone_mentions_regexp", () => {
|
||||
run_test("wildcard_mentions_regexp", () => {
|
||||
const messages_with_all_mentions = [
|
||||
"@**all**",
|
||||
"some text before @**all** some text after",
|
||||
|
@ -170,6 +170,13 @@ run_test("all_and_everyone_mentions_regexp", () => {
|
|||
"some text before only @**stream**",
|
||||
];
|
||||
|
||||
const messages_with_topic_mentions = [
|
||||
"@**topic**",
|
||||
"some text before @**topic** some text after",
|
||||
"@**topic** some text after only",
|
||||
"some text before only @**topic**",
|
||||
];
|
||||
|
||||
const messages_without_all_mentions = [
|
||||
"@all",
|
||||
"some text before @all some text after",
|
||||
|
@ -197,6 +204,15 @@ run_test("all_and_everyone_mentions_regexp", () => {
|
|||
"some_email@**stream**.com",
|
||||
];
|
||||
|
||||
const messages_without_topic_mentions = [
|
||||
"some text before @topic some text after",
|
||||
"@topic",
|
||||
"`@topic`",
|
||||
"some_email@topic.com",
|
||||
"`@**topic**`",
|
||||
"some_email@**topic**.com",
|
||||
];
|
||||
|
||||
let i;
|
||||
for (i = 0; i < messages_with_all_mentions.length; i += 1) {
|
||||
assert.ok(util.find_wildcard_mentions(messages_with_all_mentions[i]));
|
||||
|
@ -210,6 +226,10 @@ run_test("all_and_everyone_mentions_regexp", () => {
|
|||
assert.ok(util.find_wildcard_mentions(messages_with_stream_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_with_topic_mentions.length; i += 1) {
|
||||
assert.ok(util.find_wildcard_mentions(messages_with_topic_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_without_all_mentions.length; i += 1) {
|
||||
assert.ok(!util.find_wildcard_mentions(messages_without_everyone_mentions[i]));
|
||||
}
|
||||
|
@ -221,6 +241,10 @@ run_test("all_and_everyone_mentions_regexp", () => {
|
|||
for (i = 0; i < messages_without_stream_mentions.length; i += 1) {
|
||||
assert.ok(!util.find_wildcard_mentions(messages_without_stream_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_without_topic_mentions.length; i += 1) {
|
||||
assert.ok(!util.find_wildcard_mentions(messages_without_topic_mentions[i]));
|
||||
}
|
||||
});
|
||||
|
||||
run_test("move_array_elements_to_front", () => {
|
||||
|
|
Loading…
Reference in New Issue