diff --git a/static/js/compose.js b/static/js/compose.js index 11e2c81172..e2c8d9fad7 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -463,10 +463,40 @@ exports.get_invalid_recipient_emails = function () { return invalid_recipients; }; +// *Synchronously* check if a stream exists. +// This is deprecated and we hope to remove it. +exports.check_stream_existence = function (stream_name, autosubscribe) { + var result = "error"; + var request = {stream: stream_name}; + if (autosubscribe) { + request.autosubscribe = true; + } + channel.post({ + url: "/json/subscriptions/exists", + data: request, + async: false, + success: function (data) { + if (data.subscribed) { + result = "subscribed"; + } else { + result = "not-subscribed"; + } + }, + error: function (xhr) { + if (xhr.status === 404) { + result = "does-not-exist"; + } else { + result = "error"; + } + }, + }); + return result; +}; + // Checks if a stream exists. If not, displays an error and returns // false. function check_stream_for_send(stream_name, autosubscribe) { - var result = subs.check_stream_existence(stream_name, autosubscribe); + var result = exports.check_stream_existence(stream_name, autosubscribe); if (result === "error") { compose_error(i18n.t("Error checking subscription"), $("#stream")); diff --git a/static/js/stream_create.js b/static/js/stream_create.js index e7a4091f2d..4da64eb719 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -159,37 +159,6 @@ exports.new_stream_clicked = function (stream) { window.location.hash = "#streams/new"; }; -// *Synchronously* check if a stream exists. -// This is deprecated and we hope to remove it. -exports.check_stream_existence = function (stream_name, autosubscribe) { - var result = "error"; - var request = {stream: stream_name}; - if (autosubscribe) { - request.autosubscribe = true; - } - channel.post({ - url: "/json/subscriptions/exists", - data: request, - async: false, - success: function (data) { - if (data.subscribed) { - result = "subscribed"; - } else { - result = "not-subscribed"; - } - }, - error: function (xhr) { - if (xhr.status === 404) { - result = "does-not-exist"; - } else { - result = "error"; - } - }, - }); - return result; -}; - - exports.show_new_stream_modal = function () { $("#stream-creation").removeClass("hide"); $(".right .settings").hide();