2017-04-06 16:01:07 +02:00
|
|
|
var settings_notifications = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2018-03-08 00:09:22 +01:00
|
|
|
var stream_notification_settings = [
|
|
|
|
{setting: "enable_stream_desktop_notifications", notifications:"desktop_notifications"},
|
|
|
|
{setting: "enable_stream_push_notifications", notifications:"push_notifications"},
|
|
|
|
{setting: "enable_stream_sounds", notifications:"audible_notifications"},
|
2017-11-21 05:58:26 +01:00
|
|
|
{setting: "enable_stream_email_notifications", notifications:"email_notifications"},
|
2018-03-08 00:09:22 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
var pm_mention_notification_settings = [
|
2017-06-04 19:43:10 +02:00
|
|
|
"enable_desktop_notifications",
|
|
|
|
"enable_offline_email_notifications",
|
|
|
|
"enable_offline_push_notifications",
|
|
|
|
"enable_online_push_notifications",
|
|
|
|
"enable_sounds",
|
|
|
|
"pm_content_in_desktop_notifications",
|
2018-03-08 00:09:22 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
var other_notification_settings = [
|
|
|
|
"enable_digest_emails",
|
2018-08-24 07:28:51 +02:00
|
|
|
"enable_login_emails",
|
2018-01-06 23:30:43 +01:00
|
|
|
"realm_name_in_notifications",
|
2017-11-29 13:42:39 +01:00
|
|
|
"message_content_in_email_notifications",
|
2017-06-04 19:43:10 +02:00
|
|
|
];
|
|
|
|
|
2018-03-08 07:50:16 +01:00
|
|
|
exports.notification_settings = other_notification_settings.concat(
|
2018-03-08 00:09:22 +01:00
|
|
|
pm_mention_notification_settings,
|
2018-03-24 13:41:56 +01:00
|
|
|
_.pluck(stream_notification_settings, 'setting')
|
|
|
|
);
|
2018-03-08 00:09:22 +01:00
|
|
|
|
2017-06-05 23:36:32 +02:00
|
|
|
function maybe_bulk_update_stream_notification_setting(notification_checkbox,
|
|
|
|
propagate_setting_function) {
|
|
|
|
var html = templates.render("propagate_notification_change");
|
|
|
|
// TODO: This seems broken!!!
|
|
|
|
var group = notification_checkbox.closest(".input-group");
|
|
|
|
var checkbox_status = notification_checkbox.prop('checked');
|
|
|
|
group.find(".propagate_stream_notifications_change").html(html);
|
|
|
|
group.find(".yes_propagate_notifications").on("click", function () {
|
|
|
|
propagate_setting_function(checkbox_status);
|
|
|
|
group.find(".propagate_stream_notifications_change").empty();
|
|
|
|
});
|
|
|
|
group.find(".no_propagate_notifications").on("click", function () {
|
|
|
|
group.find(".propagate_stream_notifications_change").empty();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-07 23:08:42 +01:00
|
|
|
function change_notification_setting(setting, setting_data, status_element) {
|
|
|
|
var data = {};
|
|
|
|
data[setting] = JSON.stringify(setting_data);
|
2018-03-11 10:47:36 +01:00
|
|
|
settings_ui.do_settings_change(channel.patch, '/json/settings/notifications', data, status_element);
|
2018-03-07 23:08:42 +01:00
|
|
|
}
|
2017-04-06 16:01:07 +02:00
|
|
|
|
2018-03-07 23:08:42 +01:00
|
|
|
exports.set_up = function () {
|
2018-08-01 12:51:35 +02:00
|
|
|
if (!page_params.realm_digest_emails_enabled) {
|
2018-01-06 23:30:43 +01:00
|
|
|
$("#digest_container").hide();
|
2017-04-06 22:55:41 +02:00
|
|
|
}
|
|
|
|
|
2018-03-07 23:08:42 +01:00
|
|
|
_.each(pm_mention_notification_settings, function (setting) {
|
|
|
|
$("#" + setting).change(function () {
|
|
|
|
change_notification_setting(setting, $(this).prop('checked'),
|
|
|
|
"#pm-mention-notify-settings-status");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(other_notification_settings, function (setting) {
|
|
|
|
$("#" + setting).change(function () {
|
|
|
|
change_notification_setting(setting, $(this).prop('checked'),
|
|
|
|
"#other-notify-settings-status");
|
|
|
|
});
|
|
|
|
});
|
2017-06-04 19:43:10 +02:00
|
|
|
|
2018-03-07 23:08:42 +01:00
|
|
|
_.each(stream_notification_settings, function (stream_setting) {
|
|
|
|
var setting = stream_setting.setting;
|
|
|
|
$("#" + setting).change(function () {
|
|
|
|
var setting_data = $(this).prop('checked');
|
|
|
|
change_notification_setting(setting, setting_data, "#stream-notify-settings-status");
|
2018-03-08 00:15:24 +01:00
|
|
|
maybe_bulk_update_stream_notification_setting($('#' + setting), function () {
|
|
|
|
stream_edit.set_notification_setting_for_all_streams(
|
|
|
|
stream_setting.notifications, setting_data);
|
|
|
|
});
|
2017-06-04 19:43:10 +02:00
|
|
|
});
|
2017-04-06 16:01:07 +02:00
|
|
|
});
|
2017-07-21 01:04:12 +02:00
|
|
|
|
|
|
|
$("#enable_desktop_notifications").change(function () {
|
2018-03-03 05:44:58 +01:00
|
|
|
settings_ui.disable_sub_setting_onchange(this.checked, "pm_content_in_desktop_notifications", true);
|
2017-07-21 01:04:12 +02:00
|
|
|
});
|
2017-09-17 05:16:09 +02:00
|
|
|
|
|
|
|
$("#enable_offline_push_notifications").change(function () {
|
2018-03-03 05:44:58 +01:00
|
|
|
settings_ui.disable_sub_setting_onchange(this.checked, "enable_online_push_notifications", true);
|
2017-09-17 05:16:09 +02:00
|
|
|
});
|
2017-04-06 16:01:07 +02:00
|
|
|
};
|
|
|
|
|
2018-05-30 18:06:59 +02:00
|
|
|
exports.update_page = function () {
|
2018-03-08 07:50:16 +01:00
|
|
|
_.each(exports.notification_settings, function (setting) {
|
2017-06-04 19:43:10 +02:00
|
|
|
$("#" + setting).prop('checked', page_params[setting]);
|
|
|
|
});
|
2017-04-06 16:01:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings_notifications;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.settings_notifications = settings_notifications;
|