mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 16:14:02 +00:00
Give users the option to propagate global stream changes.
This helps the common case of not liking our default of having audible and desktop notifications enabled, and not making users adjust the settings on every existing stream to fix it. (imported from commit be75edb2c1385d1bd9a289416e2dffd8007f5e0a)
This commit is contained in:
@@ -58,6 +58,22 @@ function set_stream_property(stream_name, property, value) {
|
||||
});
|
||||
}
|
||||
|
||||
function set_notification_setting_for_all_streams(notification_type, new_setting) {
|
||||
_.each(stream_data.subscribed_subs(), function (sub) {
|
||||
if (sub[notification_type] !== new_setting) {
|
||||
set_stream_property(sub.name, notification_type, new_setting);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.set_all_stream_desktop_notifications_to = function (new_setting) {
|
||||
set_notification_setting_for_all_streams("desktop_notifications", new_setting);
|
||||
};
|
||||
|
||||
exports.set_all_stream_audible_notifications_to = function (new_setting) {
|
||||
set_notification_setting_for_all_streams("audible_notifications", new_setting);
|
||||
};
|
||||
|
||||
function stream_home_view_clicked(e) {
|
||||
var sub_row = $(e.target).closest('.subscription_row');
|
||||
var stream = sub_row.find('.subscription_name').text();
|
||||
|
@@ -1155,6 +1155,54 @@ $(function () {
|
||||
update_notification_settings_error);
|
||||
});
|
||||
|
||||
function update_global_stream_setting(notification_type, new_setting) {
|
||||
var data = {};
|
||||
data[notification_type] = new_setting;
|
||||
channel.post({
|
||||
url: "/json/notify_settings/change",
|
||||
data: data,
|
||||
success: update_notification_settings_success,
|
||||
error: update_notification_settings_error
|
||||
});
|
||||
}
|
||||
|
||||
function update_desktop_notification_setting(new_setting) {
|
||||
update_global_stream_setting("enable_stream_desktop_notifications", new_setting);
|
||||
subs.set_all_stream_desktop_notifications_to(new_setting);
|
||||
}
|
||||
|
||||
function update_audible_notification_setting(new_setting) {
|
||||
update_global_stream_setting("enable_stream_sounds", new_setting);
|
||||
subs.set_all_stream_audible_notifications_to(new_setting);
|
||||
}
|
||||
|
||||
function maybe_bulk_update_stream_notification_setting(notification_checkbox,
|
||||
propagate_setting_function) {
|
||||
var html = templates.render("propagate_notification_change");
|
||||
var control_group = notification_checkbox.closest(".control-group");
|
||||
var checkbox_status = notification_checkbox.is(":checked");
|
||||
control_group.find(".propagate_stream_notifications_change").html(html);
|
||||
control_group.find(".yes_propagate_notifications").on("click", function (e) {
|
||||
propagate_setting_function(checkbox_status);
|
||||
control_group.find(".propagate_stream_notifications_change").empty();
|
||||
});
|
||||
control_group.find(".no_propagate_notifications").on("click", function (e) {
|
||||
control_group.find(".propagate_stream_notifications_change").empty();
|
||||
});
|
||||
}
|
||||
|
||||
$("#enable_stream_desktop_notifications").on("click", function (e) {
|
||||
var notification_checkbox = $("#enable_stream_desktop_notifications");
|
||||
maybe_bulk_update_stream_notification_setting(notification_checkbox,
|
||||
update_desktop_notification_setting);
|
||||
});
|
||||
|
||||
$("#enable_stream_sounds").on("click", function (e) {
|
||||
var notification_checkbox = $("#enable_stream_sounds");
|
||||
maybe_bulk_update_stream_notification_setting(notification_checkbox,
|
||||
update_audible_notification_setting);
|
||||
});
|
||||
|
||||
if (feature_flags.show_autoscroll_forever_option) {
|
||||
$("form.ui-settings").expectOne().ajaxForm({
|
||||
dataType: 'json',
|
||||
|
12
static/templates/propagate_notification_change.handlebars
Normal file
12
static/templates/propagate_notification_change.handlebars
Normal file
@@ -0,0 +1,12 @@
|
||||
<div>
|
||||
<p>Apply this change to all stream subscriptions?</p>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="controls propagate-notifications-controls">
|
||||
<button type="button"
|
||||
class="yes_propagate_notifications btn btn-primary btn-small">Yes</button>
|
||||
<button type="button"
|
||||
class="no_propagate_notifications btn btn-small">No</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@@ -108,6 +108,7 @@
|
||||
<label for="enable_stream_desktop_notifications" class="control-label">
|
||||
Desktop notifications
|
||||
</label>
|
||||
<div class="propagate_stream_notifications_change"></div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
@@ -120,6 +121,7 @@
|
||||
<label for="enable_stream_sounds" class="control-label">
|
||||
Audible notifications
|
||||
</label>
|
||||
<div class="propagate_stream_notifications_change"></div>
|
||||
</div>
|
||||
|
||||
<p class="notification-settings-note">Change notification settings for
|
||||
|
@@ -663,6 +663,15 @@ function render(template_name, args) {
|
||||
assert.equal(a.text().trim(), 'Narrow to private messages with Hamlet');
|
||||
}());
|
||||
|
||||
(function notification_docs() {
|
||||
var html = render('propagate_notification_change');
|
||||
global.write_test_output("propagate_notification_change.handlebars", html);
|
||||
|
||||
var button_area = $(html).find(".propagate-notifications-controls");
|
||||
assert.equal(button_area.find(".yes_propagate_notifications").text().trim(), 'Yes');
|
||||
assert.equal(button_area.find(".no_propagate_notifications").text().trim(), 'No');
|
||||
}());
|
||||
|
||||
// By the end of this test, we should have compiled all our templates. Ideally,
|
||||
// we will also have exercised them to some degree, but that's a little trickier
|
||||
// to enforce.
|
||||
|
Reference in New Issue
Block a user