Move check_stream_existence() to compose.js.

The function check_stream_existence() temporarliy got moved
to stream_create.js, and our call from compose.js was still trying
to find it in subs.js.  Now we move the function to compose.js,
since we no longer use it stream_create.js.

This function is pretty dubious, and we may want to only check
for duplicate stream names locally.
This commit is contained in:
Steve Howell 2017-04-28 14:47:35 -07:00 committed by Tim Abbott
parent d999827465
commit 5965dc092a
2 changed files with 31 additions and 32 deletions

View File

@ -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"));

View File

@ -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();