mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 04:12:02 +00:00
Fix showing the subscribe-and-send dialogue when you're subscribed.
This doesn't fully fix the problems related to not syncing subscriptions to browser clients, but it does fix the instance that everyone experiences. (imported from commit be2bc31a7c4443c1678321f1a938496e2632c0d3)
This commit is contained in:
@@ -200,7 +200,7 @@ function compose_error(error_text, bad_input) {
|
|||||||
// *Synchronously* check if a stream exists.
|
// *Synchronously* check if a stream exists.
|
||||||
// If not, displays an error and returns false.
|
// If not, displays an error and returns false.
|
||||||
function check_stream_for_send(stream_name) {
|
function check_stream_for_send(stream_name) {
|
||||||
var okay = true;
|
var result = "error";
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/json/subscriptions/exists",
|
url: "/json/subscriptions/exists",
|
||||||
@@ -209,24 +209,28 @@ function check_stream_for_send(stream_name) {
|
|||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (!data.exists) {
|
if (!data.exists) {
|
||||||
// The stream doesn't exist
|
// The stream doesn't exist
|
||||||
okay = false;
|
result = "does-not-exist";
|
||||||
$('#send-status').removeClass(status_classes).show();
|
$('#send-status').removeClass(status_classes).show();
|
||||||
$('#stream-dne-name').text(stream_name);
|
$('#stream-dne-name').text(stream_name);
|
||||||
$('#stream-dne').show();
|
$('#stream-dne').show();
|
||||||
$("#compose-send-button").removeAttr('disabled');
|
$("#compose-send-button").removeAttr('disabled');
|
||||||
exports.hide();
|
exports.hide();
|
||||||
$('#create-it').focus();
|
$('#create-it').focus();
|
||||||
|
} else if (data.subscribed) {
|
||||||
|
result = "subscribed";
|
||||||
|
} else {
|
||||||
|
result = "not-subscribed";
|
||||||
}
|
}
|
||||||
$("#home-error").hide();
|
$("#home-error").hide();
|
||||||
},
|
},
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
okay = false;
|
result = "error";
|
||||||
report_error("Error checking subscription", xhr, $("#home-error"));
|
report_error("Error checking subscription", xhr, $("#home-error"));
|
||||||
$("#stream").focus();
|
$("#stream").focus();
|
||||||
$("#compose-send-button").removeAttr('disabled');
|
$("#compose-send-button").removeAttr('disabled');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return okay;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate_stream_message() {
|
function validate_stream_message() {
|
||||||
@@ -242,10 +246,15 @@ function validate_stream_message() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!subs.have(stream_name)) {
|
if (!subs.have(stream_name)) {
|
||||||
if (!check_stream_for_send(stream_name)) {
|
switch(check_stream_for_send(stream_name)) {
|
||||||
|
case "does-not-exist":
|
||||||
|
case "error":
|
||||||
return false;
|
return false;
|
||||||
}
|
case "subscribed":
|
||||||
// You're not subbed to the stream
|
// You're actually subscribed to the stream, but this
|
||||||
|
// browser window doesn't know it.
|
||||||
|
return true;
|
||||||
|
case "not-subscribed":
|
||||||
$('#send-status').removeClass(status_classes).show();
|
$('#send-status').removeClass(status_classes).show();
|
||||||
$('#stream-nosub-name').text(stream_name);
|
$('#stream-nosub-name').text(stream_name);
|
||||||
$('#stream-nosub').show();
|
$('#stream-nosub').show();
|
||||||
@@ -254,6 +263,7 @@ function validate_stream_message() {
|
|||||||
$('#sub-it').focus();
|
$('#sub-it').focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -776,8 +776,14 @@ def json_change_settings(request, user_profile, full_name=POST,
|
|||||||
def json_stream_exists(request, user_profile, stream=POST):
|
def json_stream_exists(request, user_profile, stream=POST):
|
||||||
if not valid_stream_name(stream):
|
if not valid_stream_name(stream):
|
||||||
return json_error("Invalid characters in stream name")
|
return json_error("Invalid characters in stream name")
|
||||||
exists = bool(get_stream(stream, user_profile.realm))
|
stream = get_stream(stream, user_profile.realm)
|
||||||
return json_success({"exists": exists})
|
result = {"exists": bool(stream)}
|
||||||
|
if stream is not None:
|
||||||
|
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
|
||||||
|
result["subscribed"] = Subscription.objects.filter(user_profile=user_profile,
|
||||||
|
recipient=recipient,
|
||||||
|
active=True).exists()
|
||||||
|
return json_success(result)
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@require_post
|
@require_post
|
||||||
|
|||||||
Reference in New Issue
Block a user