mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +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];
|
||||
ui.report_success("Already subscribed to " + true_stream_name,
|
||||
$("#subscriptions-status"));
|
||||
} else {
|
||||
// Display the canonical stream capitalization.
|
||||
true_stream_name = res.subscribed[page_params.email][0];
|
||||
}
|
||||
$(document).trigger($.Event('subscription_add.zephyr',
|
||||
{subscription: {name: true_stream_name}}));
|
||||
// The rest of the work is done via the subscribe event we will get
|
||||
},
|
||||
error: function (xhr) {
|
||||
ui.report_error("Error adding subscription", xhr, $("#subscriptions-status"));
|
||||
@@ -560,13 +556,7 @@ function ajaxUnsubscribe(stream) {
|
||||
success: function (resp, statusText, xhr, form) {
|
||||
var name, res = $.parseJSON(xhr.responseText);
|
||||
$("#subscriptions-status").hide();
|
||||
if (res.removed.length === 0) {
|
||||
name = res.not_subscribed[0];
|
||||
} else {
|
||||
name = res.removed[0];
|
||||
}
|
||||
$(document).trigger($.Event('subscription_remove.zephyr',
|
||||
{subscription: {name: name}}));
|
||||
// The rest of the work is done via the unsubscribe event we will get
|
||||
},
|
||||
error: function (xhr) {
|
||||
ui.report_error("Error removing subscription", xhr, $("#subscriptions-status"));
|
||||
@@ -589,9 +579,7 @@ function ajaxSubscribeForCreation(stream, principals, invite_only) {
|
||||
$("#create_stream_name").val("");
|
||||
$("#subscriptions-status").hide();
|
||||
$('#stream-creation').modal("hide");
|
||||
$(document).trigger($.Event('subscription_add.zephyr',
|
||||
{subscription: {name: stream,
|
||||
invite_only: invite_only}}));
|
||||
// The rest of the work is done via the subscribe event we will get
|
||||
},
|
||||
error: function (xhr) {
|
||||
ui.report_error("Error creating stream", xhr, $("#subscriptions-status"));
|
||||
|
||||
@@ -675,6 +675,15 @@ function get_updates(options) {
|
||||
}
|
||||
typeahead_helper.autocomplete_needs_update(true);
|
||||
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