compose: Set wildcard_mention for message before further validation.

We do not show the warning while sending messages to announce
stream if there is a wildcard mention in the message (i.e.
when wildcard_mention != null)

There are two cases where we should ideally show the warning
but we don't-

 - When there is no wildcard mention in the message and
   wildcard_mention is set to undefined (initial value of
   wildcard_mention).
   This is because "wildcard_mention != null" returns true for
   this case and thus the warning is not shown, assuming the
   message to have wildcard mention.

 - When previous message had a wildcard mention and now a message
   is being sent with no wildcard mention.
   This is because the condition "wildcard_mention != null" is
   checked with the previous value of wildcard_mention and not
   with the value according to current message content, and thus
   the warning is not shown, assuming the message to have wildcard
   mention.

This commit changes the code to set wildcard_mention from the
latest message content before performing other validations and
thus solves the problems described above.
This commit is contained in:
sahil839
2020-07-07 01:52:19 +05:30
committed by Tim Abbott
parent 912e372c4e
commit 04ef6ba63a

View File

@@ -463,7 +463,6 @@ function check_unsubscribed_stream_for_send(stream_name, autosubscribe) {
function validate_stream_message_mentions(stream_id) {
const stream_count = stream_data.get_subscriber_count(stream_id) || 0;
wildcard_mention = util.find_wildcard_mentions(compose_state.message_content());
// check if wildcard_mention has any mention and henceforth execute the warning message.
if (wildcard_mention !== null && stream_count > exports.all_everyone_warn_threshold) {
@@ -595,6 +594,11 @@ function validate_stream_message() {
return false;
}
/* Note: This is a global and thus accessible in the functions
below; it's important that we update this state here before
proceeding with further validation. */
wildcard_mention = util.find_wildcard_mentions(compose_state.message_content());
// 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 (wildcard_mention !== null && stream_name === "announce") {