diff --git a/static/js/compose.js b/static/js/compose.js index 139c3b9296..ebda185030 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -736,40 +736,10 @@ exports.update_email = function (user_id, new_email) { exports.recipient(reply_to); }; -// *Synchronously* check if a stream exists. -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 = exports.check_stream_existence(stream_name, autosubscribe); + var result = subs.check_stream_existence(stream_name, autosubscribe); if (result === "error") { compose_error(i18n.t("Error checking subscription"), $("#stream")); diff --git a/static/js/subs.js b/static/js/subs.js index da3531f047..b6722e5576 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -1239,7 +1239,7 @@ $(function () { $(".subscriptions").on("focusout", "#create_stream_name", function () { var stream = $.trim($("#create_stream_name").val()); if (stream.length !== 0) { - var stream_status = compose.check_stream_existence(stream); + var stream_status = exports.check_stream_existence(stream); if (stream_status !== "does-not-exist") { $("#stream_name_error").text(i18n.t("A stream with this name already exists")); @@ -1542,6 +1542,36 @@ exports.show_and_focus_on_narrow = function () { ui.change_tab_to("#streams"); }; +// *Synchronously* check if a stream exists. +// This is deprecated nad 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; +}; + return exports; }());