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); 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 // Checks if a stream exists. If not, displays an error and returns
// false. // false.
function check_stream_for_send(stream_name, autosubscribe) { 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") { if (result === "error") {
compose_error(i18n.t("Error checking subscription"), $("#stream")); compose_error(i18n.t("Error checking subscription"), $("#stream"));

View File

@@ -1239,7 +1239,7 @@ $(function () {
$(".subscriptions").on("focusout", "#create_stream_name", function () { $(".subscriptions").on("focusout", "#create_stream_name", function () {
var stream = $.trim($("#create_stream_name").val()); var stream = $.trim($("#create_stream_name").val());
if (stream.length !== 0) { 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") { if (stream_status !== "does-not-exist") {
$("#stream_name_error").text(i18n.t("A stream with this name already exists")); $("#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"); 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; return exports;
}()); }());