mirror of https://github.com/zulip/zulip.git
compose: Improved warning for wildcard mentions.
Edited the warning to clearly state that most members/most stream members will be notified on using wildcard mentions, along with the specific mention (e.g. @ALL, @everyone and @stream). Did a separate check for all wildcard mentions in util.js and stored the corresponding mention in wildcard_mention inside compose.js. Fixes: #13636
This commit is contained in:
parent
23a5cf41dc
commit
1fa46b1963
|
@ -7,8 +7,8 @@
|
|||
// and assert truths:
|
||||
|
||||
zrequire('util');
|
||||
assert(!util.is_all_or_everyone_mentioned('boring text'));
|
||||
assert(util.is_all_or_everyone_mentioned('mention @**everyone**'));
|
||||
assert(!util.find_wildcard_mentions('boring text'));
|
||||
assert(util.find_wildcard_mentions('mention @**everyone**'));
|
||||
|
||||
// Let's test with people.js next. We'll show this technique:
|
||||
// * get a false value
|
||||
|
|
|
@ -519,13 +519,29 @@ run_test('compose_invite_users', () => {
|
|||
run_test('compose_all_everyone', () => {
|
||||
const args = {
|
||||
count: '101',
|
||||
name: 'all',
|
||||
mention: 'all',
|
||||
};
|
||||
const html = render('compose_all_everyone', args);
|
||||
let html = render('compose_all_everyone', args);
|
||||
const button = $(html).find("button").first();
|
||||
|
||||
// test for @all mention warning.
|
||||
assert.equal(button.text(), "translated: Yes, send");
|
||||
const error_msg = $(html).find('span.compose-all-everyone-msg').text().trim();
|
||||
assert.equal(error_msg, "translated: Are you sure you want to mention all 101 people in this stream?");
|
||||
let error_msg = $(html).find('span.compose-all-everyone-msg').text().trim();
|
||||
assert.equal(error_msg, "translated: Are you sure you want to mention all 101 people in this stream? This will send email and mobile push notifications to most of those 101 users. If you don't want to do that, please edit your message to remove the @all mention.");
|
||||
|
||||
// test for @everyone warning.
|
||||
args.mention = 'everyone';
|
||||
html = render('compose_all_everyone', args);
|
||||
assert.equal(button.text(), "translated: Yes, send");
|
||||
error_msg = $(html).find('span.compose-all-everyone-msg').text().trim();
|
||||
assert.equal(error_msg, "translated: Are you sure you want to mention all 101 people in this stream? This will send email and mobile push notifications to most of those 101 users. If you don't want to do that, please edit your message to remove the @everyone mention.");
|
||||
|
||||
// test for @stream warning.
|
||||
args.mention = 'stream';
|
||||
html = render('compose_all_everyone', args);
|
||||
assert.equal(button.text(), "translated: Yes, send");
|
||||
error_msg = $(html).find('span.compose-all-everyone-msg').text().trim();
|
||||
assert.equal(error_msg, "translated: Are you sure you want to mention all 101 people in this stream? This will send email and mobile push notifications to most of those 101 users. If you don't want to do that, please edit your message to remove the @stream mention.");
|
||||
});
|
||||
|
||||
run_test('compose_announce', () => {
|
||||
|
|
|
@ -222,27 +222,27 @@ run_test('all_and_everyone_mentions_regexp', () => {
|
|||
|
||||
let i;
|
||||
for (i = 0; i < messages_with_all_mentions.length; i += 1) {
|
||||
assert(util.is_all_or_everyone_mentioned(messages_with_all_mentions[i]));
|
||||
assert(util.find_wildcard_mentions(messages_with_all_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_with_everyone_mentions.length; i += 1) {
|
||||
assert(util.is_all_or_everyone_mentioned(messages_with_everyone_mentions[i]));
|
||||
assert(util.find_wildcard_mentions(messages_with_everyone_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_with_stream_mentions.length; i += 1) {
|
||||
assert(util.is_all_or_everyone_mentioned(messages_with_stream_mentions[i]));
|
||||
assert(util.find_wildcard_mentions(messages_with_stream_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_without_all_mentions.length; i += 1) {
|
||||
assert(!util.is_all_or_everyone_mentioned(messages_without_everyone_mentions[i]));
|
||||
assert(!util.find_wildcard_mentions(messages_without_everyone_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_without_everyone_mentions.length; i += 1) {
|
||||
assert(!util.is_all_or_everyone_mentioned(messages_without_everyone_mentions[i]));
|
||||
assert(!util.find_wildcard_mentions(messages_without_everyone_mentions[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < messages_without_stream_mentions.length; i += 1) {
|
||||
assert(!util.is_all_or_everyone_mentioned(messages_without_stream_mentions[i]));
|
||||
assert(!util.find_wildcard_mentions(messages_without_stream_mentions[i]));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ const render_compose_private_stream_alert = require("../templates/compose_privat
|
|||
|
||||
let user_acknowledged_all_everyone;
|
||||
let user_acknowledged_announce;
|
||||
let wildcard_mention;
|
||||
|
||||
exports.all_everyone_warn_threshold = 15;
|
||||
exports.announce_warn_threshold = 60;
|
||||
|
@ -32,7 +33,8 @@ function make_uploads_relative(content) {
|
|||
function show_all_everyone_warnings() {
|
||||
const stream_count = stream_data.get_subscriber_count(compose_state.stream_name()) || 0;
|
||||
|
||||
const all_everyone_template = render_compose_all_everyone({count: stream_count});
|
||||
const all_everyone_template = render_compose_all_everyone({count: stream_count,
|
||||
mention: wildcard_mention});
|
||||
const error_area_all_everyone = $("#compose-all-everyone");
|
||||
|
||||
// only show one error for any number of @all or @everyone mentions
|
||||
|
@ -429,10 +431,10 @@ function check_unsubscribed_stream_for_send(stream_name, autosubscribe) {
|
|||
|
||||
function validate_stream_message_mentions(stream_name) {
|
||||
const stream_count = stream_data.get_subscriber_count(stream_name) || 0;
|
||||
wildcard_mention = util.find_wildcard_mentions(compose_state.message_content());
|
||||
|
||||
// check if @all or @everyone is in the message
|
||||
if (util.is_all_or_everyone_mentioned(compose_state.message_content()) &&
|
||||
stream_count > exports.all_everyone_warn_threshold) {
|
||||
// check if wildcard_mention has any mention and henceforth execute the warning message.
|
||||
if (wildcard_mention !== null && stream_count > exports.all_everyone_warn_threshold) {
|
||||
if (user_acknowledged_all_everyone === undefined ||
|
||||
user_acknowledged_all_everyone === false) {
|
||||
// user has not seen a warning message yet if undefined
|
||||
|
@ -541,8 +543,7 @@ function validate_stream_message() {
|
|||
|
||||
// If both `@all` is mentioned and it's in `#announce`, just validate
|
||||
// for `@all`. Users shouldn't have to hit "yes" more than once.
|
||||
if (util.is_all_or_everyone_mentioned(compose_state.message_content()) &&
|
||||
stream_name === "announce") {
|
||||
if (wildcard_mention !== null && stream_name === "announce") {
|
||||
if (!exports.validate_stream_message_address_info(stream_name) ||
|
||||
!validate_stream_message_mentions(stream_name)) {
|
||||
return false;
|
||||
|
|
|
@ -209,9 +209,12 @@ exports.CachedValue.prototype = {
|
|||
},
|
||||
};
|
||||
|
||||
exports.is_all_or_everyone_mentioned = function (message_content) {
|
||||
const all_everyone_re = /(^|\s)(@\*{2}(all|everyone|stream)\*{2})($|\s)/;
|
||||
return all_everyone_re.test(message_content);
|
||||
exports.find_wildcard_mentions = function (message_content) {
|
||||
const mention = message_content.match(/(^|\s)(@\*{2}(all|everyone|stream)\*{2})($|\s)/);
|
||||
if (mention === null) {
|
||||
return null;
|
||||
}
|
||||
return mention[3];
|
||||
};
|
||||
|
||||
exports.move_array_elements_to_front = function util_move_array_elements_to_front(array, selected) {
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
<div class="compose-all-everyone">
|
||||
<span class="compose-all-everyone-msg">
|
||||
{{#tr this}}Are you sure you want to mention all <strong>__count__</strong> people in this stream?{{/tr}}
|
||||
{{#tr this}}
|
||||
Are you sure you want to mention all <strong>__count__</strong> people in this stream?
|
||||
<br />
|
||||
This will send email and mobile push notifications to most of those <strong>__count__</strong> users.
|
||||
<br />
|
||||
If you don't want to do that, please edit your message to remove the <strong>@__mention__</strong> mention.
|
||||
{{/tr}}
|
||||
</span>
|
||||
<span class="compose-all-everyone-controls">
|
||||
<button type="button" class="btn btn-warning compose-all-everyone-confirm">{{t "Yes, send" }}</button>
|
||||
|
|
Loading…
Reference in New Issue