js: check_stream_existence to subs.js.

We want to remove this, but in the meantime, this is a more coherent
place for htis to live than compose.js.
This commit is contained in:
Tim Abbott
2017-03-17 15:15:57 -07:00
parent af5852a55b
commit 8efe4d530d
2 changed files with 32 additions and 32 deletions

View File

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