mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
Handle subscription events in the web client
This has the nice side effect of not requiring us to trigger the events manually in the success callbacks of our subscribe/unsubscribe ajax calls. (imported from commit e8d9970b708e9832d22be4803570071bacb46792)
This commit is contained in:
@@ -537,12 +537,8 @@ function ajaxSubscribe(stream) {
|
|||||||
true_stream_name = res.already_subscribed[page_params.email][0];
|
true_stream_name = res.already_subscribed[page_params.email][0];
|
||||||
ui.report_success("Already subscribed to " + true_stream_name,
|
ui.report_success("Already subscribed to " + true_stream_name,
|
||||||
$("#subscriptions-status"));
|
$("#subscriptions-status"));
|
||||||
} else {
|
|
||||||
// Display the canonical stream capitalization.
|
|
||||||
true_stream_name = res.subscribed[page_params.email][0];
|
|
||||||
}
|
}
|
||||||
$(document).trigger($.Event('subscription_add.zephyr',
|
// The rest of the work is done via the subscribe event we will get
|
||||||
{subscription: {name: true_stream_name}}));
|
|
||||||
},
|
},
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
ui.report_error("Error adding subscription", xhr, $("#subscriptions-status"));
|
ui.report_error("Error adding subscription", xhr, $("#subscriptions-status"));
|
||||||
@@ -560,13 +556,7 @@ function ajaxUnsubscribe(stream) {
|
|||||||
success: function (resp, statusText, xhr, form) {
|
success: function (resp, statusText, xhr, form) {
|
||||||
var name, res = $.parseJSON(xhr.responseText);
|
var name, res = $.parseJSON(xhr.responseText);
|
||||||
$("#subscriptions-status").hide();
|
$("#subscriptions-status").hide();
|
||||||
if (res.removed.length === 0) {
|
// The rest of the work is done via the unsubscribe event we will get
|
||||||
name = res.not_subscribed[0];
|
|
||||||
} else {
|
|
||||||
name = res.removed[0];
|
|
||||||
}
|
|
||||||
$(document).trigger($.Event('subscription_remove.zephyr',
|
|
||||||
{subscription: {name: name}}));
|
|
||||||
},
|
},
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
ui.report_error("Error removing subscription", xhr, $("#subscriptions-status"));
|
ui.report_error("Error removing subscription", xhr, $("#subscriptions-status"));
|
||||||
@@ -589,9 +579,7 @@ function ajaxSubscribeForCreation(stream, principals, invite_only) {
|
|||||||
$("#create_stream_name").val("");
|
$("#create_stream_name").val("");
|
||||||
$("#subscriptions-status").hide();
|
$("#subscriptions-status").hide();
|
||||||
$('#stream-creation').modal("hide");
|
$('#stream-creation').modal("hide");
|
||||||
$(document).trigger($.Event('subscription_add.zephyr',
|
// The rest of the work is done via the subscribe event we will get
|
||||||
{subscription: {name: stream,
|
|
||||||
invite_only: invite_only}}));
|
|
||||||
},
|
},
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
ui.report_error("Error creating stream", xhr, $("#subscriptions-status"));
|
ui.report_error("Error creating stream", xhr, $("#subscriptions-status"));
|
||||||
|
|||||||
@@ -675,6 +675,15 @@ function get_updates(options) {
|
|||||||
}
|
}
|
||||||
typeahead_helper.autocomplete_needs_update(true);
|
typeahead_helper.autocomplete_needs_update(true);
|
||||||
break;
|
break;
|
||||||
|
case 'subscription':
|
||||||
|
if (event.op === 'add') {
|
||||||
|
$(document).trigger($.Event('subscription_add.zephyr',
|
||||||
|
{subscription: event.subscription}));
|
||||||
|
} else if (event.op === 'remove') {
|
||||||
|
$(document).trigger($.Event('subscription_remove.zephyr',
|
||||||
|
{subscription: event.subscription}));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user