Move checking all/everyone message to util.js module.

Create is_all_or_everyone_mentioned function in util.js.
This commit is contained in:
Tomasz Kolek 2016-08-09 22:38:45 +02:00 committed by Tim Abbott
parent d8f108a5cf
commit 5c82e53b9a
2 changed files with 7 additions and 3 deletions

View File

@ -8,7 +8,6 @@ var is_composing_message = false;
// get an error message too.
// undefined: no @all/@everyone in message; false: user typed @all/@everyone; true: user clicked YES
var user_acknowledged_all_everyone;
var all_everyone_re = /(@\*{2}(all|everyone)\*{2})|(@(all|everyone))/;
var message_snapshot;
var empty_subject_placeholder = "(no topic)";
@ -377,7 +376,7 @@ exports.restore_message = function () {
compose.start(snapshot_copy.type, snapshot_copy);
if (snapshot_copy.content !== undefined &&
all_everyone_re.test(snapshot_copy.content)) {
util.is_all_or_everyone_mentioned(snapshot_copy.content)) {
show_all_everyone_warnings();
}
};
@ -775,7 +774,7 @@ function validate_stream_message() {
}
// check if @all or @everyone is in the message
if (all_everyone_re.test(exports.message_content())) {
if (util.is_all_or_everyone_mentioned(exports.message_content())) {
if (user_acknowledged_all_everyone === undefined ||
user_acknowledged_all_everyone === false) {
// user has not seen a warning message yet if undefined

View File

@ -232,6 +232,11 @@ exports.execute_early = function (func) {
}
};
exports.is_all_or_everyone_mentioned = function (message_content) {
var all_everyone_re = /(@\*{2}(all|everyone)\*{2})|(@(all|everyone))/;
return all_everyone_re.test(message_content);
};
return exports;
}());
if (typeof module !== 'undefined') {