From c15d1ff343d71ebba103f98aedea8d809bec3b8c Mon Sep 17 00:00:00 2001 From: Sampriti Panda Date: Thu, 5 Jan 2017 16:35:51 +0530 Subject: [PATCH] compose: Split validate_stream_message into separate functions. --- static/js/compose.js | 47 ++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/static/js/compose.js b/static/js/compose.js index e8b9659947..5a29092485 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -771,21 +771,7 @@ function check_stream_for_send(stream_name, autosubscribe) { return result; } -function validate_stream_message() { - var stream_name = exports.stream_name(); - if (stream_name === "") { - compose_error(i18n.t("Please specify a stream"), $("#stream")); - return false; - } - - if (page_params.mandatory_topics) { - var topic = exports.subject(); - if (topic === "") { - compose_error(i18n.t("Please specify a topic"), $("#subject")); - return false; - } - } - +function validate_stream_message_mentions(stream_name) { var current_stream = stream_data.get_sub(stream_name); var stream_count = current_stream.subscribers.num_items(); @@ -808,6 +794,10 @@ function validate_stream_message() { // at this point, the user has either acknowledged the warning or removed @all / @everyone user_acknowledged_all_everyone = undefined; + return true; +} + +function validate_stream_message_address_info(stream_name) { var response; if (!stream_data.is_subscribed(stream_name)) { @@ -818,12 +808,12 @@ function validate_stream_message() { "

Manage your subscriptions on your Streams page.

"; compose_error(response, $('#stream')); return false; - case "error": - return false; case "subscribed": // You're actually subscribed to the stream, but this // browser window doesn't know it. return true; + case "error": + return false; case "not-subscribed": response = "

You're not subscribed to the stream " + Handlebars.Utils.escapeExpression(stream_name) + ".

" + @@ -835,6 +825,29 @@ function validate_stream_message() { return true; } + +function validate_stream_message() { + var stream_name = exports.stream_name(); + if (stream_name === "") { + compose_error(i18n.t("Please specify a stream"), $("#stream")); + return false; + } + + if (page_params.mandatory_topics) { + var topic = exports.subject(); + if (topic === "") { + compose_error(i18n.t("Please specify a topic"), $("#subject")); + return false; + } + } + + if (!validate_stream_message_mentions(stream_name) || + !validate_stream_message_address_info(stream_name)) { + return false; + } + + return true; +} // The function checks whether the recipients are users of the realm or cross realm users (bots // for now) function validate_private_message() {