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 = [
|
2019-06-12 10:33:45 +02:00
|
|
|
"enable_stream_desktop_notifications",
|
|
|
|
"enable_stream_audible_notifications",
|
2019-06-13 10:27:55 +02:00
|
|
|
"enable_stream_push_notifications",
|
2019-06-12 10:33:45 +02:00
|
|
|
"enable_stream_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_sounds",
|
2019-06-13 10:27:55 +02:00
|
|
|
"enable_offline_push_notifications",
|
|
|
|
"enable_offline_email_notifications",
|
2018-03-08 00:09:22 +01:00
|
|
|
];
|
|
|
|
|
2019-06-13 10:27:55 +02:00
|
|
|
var desktop_notification_settings = [
|
2019-04-20 00:42:32 +02:00
|
|
|
"pm_content_in_desktop_notifications",
|
2019-06-13 10:27:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
var mobile_notification_settings = [
|
2019-04-18 03:58:25 +02:00
|
|
|
"enable_online_push_notifications",
|
2019-06-13 10:27:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
var email_notification_settings = [
|
2018-03-08 00:09:22 +01:00
|
|
|
"enable_digest_emails",
|
2018-08-24 07:28:51 +02:00
|
|
|
"enable_login_emails",
|
2017-11-29 13:42:39 +01:00
|
|
|
"message_content_in_email_notifications",
|
2019-06-13 10:27:55 +02:00
|
|
|
"realm_name_in_notifications",
|
2017-06-04 19:43:10 +02:00
|
|
|
];
|
|
|
|
|
2019-06-13 10:27:55 +02:00
|
|
|
var other_notification_settings = desktop_notification_settings.concat(
|
|
|
|
mobile_notification_settings,
|
|
|
|
email_notification_settings,
|
|
|
|
["notification_sound"]
|
|
|
|
);
|
|
|
|
|
2019-06-12 10:33:45 +02:00
|
|
|
var notification_settings_status = [
|
|
|
|
{status_label: "pm-mention-notify-settings-status", settings: pm_mention_notification_settings},
|
|
|
|
{status_label: "other-notify-settings-status", settings: other_notification_settings},
|
|
|
|
{status_label: "stream-notify-settings-status", settings: stream_notification_settings},
|
|
|
|
];
|
|
|
|
|
|
|
|
exports.all_notification_settings_labels = other_notification_settings.concat(
|
2018-03-08 00:09:22 +01:00
|
|
|
pm_mention_notification_settings,
|
2019-06-12 10:33:45 +02:00
|
|
|
stream_notification_settings
|
2018-03-24 13:41:56 +01:00
|
|
|
);
|
2018-03-08 00:09:22 +01:00
|
|
|
|
2019-06-13 10:27:55 +02:00
|
|
|
exports.all_notifications = {
|
|
|
|
settings: {
|
|
|
|
stream_notification_settings: stream_notification_settings,
|
|
|
|
pm_mention_notification_settings: pm_mention_notification_settings,
|
|
|
|
desktop_notification_settings: desktop_notification_settings,
|
|
|
|
mobile_notification_settings: mobile_notification_settings,
|
|
|
|
email_notification_settings: email_notification_settings,
|
|
|
|
},
|
|
|
|
push_notification_tooltip: {
|
|
|
|
enable_stream_push_notifications: true,
|
|
|
|
enable_offline_push_notifications: true,
|
|
|
|
enable_online_push_notifications: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2019-05-10 08:45:46 +02:00
|
|
|
exports.set_enable_digest_emails_visibility = function () {
|
|
|
|
if (page_params.realm_digest_emails_enabled) {
|
|
|
|
$('#enable_digest_emails_label').parent().show();
|
|
|
|
} else {
|
|
|
|
$('#enable_digest_emails_label').parent().hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-07 23:08:42 +01:00
|
|
|
exports.set_up = function () {
|
2019-06-12 10:33:45 +02:00
|
|
|
_.each(notification_settings_status, function (setting) {
|
|
|
|
_.each(setting.settings, function (sub_setting) {
|
|
|
|
$("#" + sub_setting).change(function () {
|
|
|
|
var value;
|
|
|
|
|
|
|
|
if (sub_setting === "notification_sound") {
|
|
|
|
// `notification_sound` is not a boolean.
|
|
|
|
value = $(this).val();
|
|
|
|
} else {
|
|
|
|
value = $(this).prop('checked');
|
|
|
|
}
|
|
|
|
change_notification_setting(sub_setting, value,
|
|
|
|
"#" + setting.status_label);
|
|
|
|
});
|
2017-06-04 19:43:10 +02:00
|
|
|
});
|
2017-04-06 16:01:07 +02:00
|
|
|
});
|
2017-07-21 01:04:12 +02:00
|
|
|
|
2018-01-11 21:36:11 +01:00
|
|
|
$("#play_notification_sound").click(function () {
|
|
|
|
$("#notifications-area").find("audio")[0].play();
|
|
|
|
});
|
|
|
|
|
|
|
|
var notification_sound_dropdown = $("#notification_sound");
|
|
|
|
notification_sound_dropdown.val(page_params.notification_sound);
|
|
|
|
|
2019-06-11 08:47:49 +02:00
|
|
|
$("#enable_sounds, #enable_stream_audible_notifications").change(function () {
|
|
|
|
if ($("#enable_stream_audible_notifications").prop("checked") || $("#enable_sounds").prop("checked")) {
|
2018-01-11 21:36:11 +01:00
|
|
|
notification_sound_dropdown.prop("disabled", false);
|
|
|
|
notification_sound_dropdown.parent().removeClass("control-label-disabled");
|
|
|
|
} else {
|
|
|
|
notification_sound_dropdown.prop("disabled", true);
|
|
|
|
notification_sound_dropdown.parent().addClass("control-label-disabled");
|
|
|
|
}
|
|
|
|
});
|
2019-05-10 08:45:46 +02:00
|
|
|
exports.set_enable_digest_emails_visibility();
|
2017-04-06 16:01:07 +02:00
|
|
|
};
|
|
|
|
|
2018-05-30 18:06:59 +02:00
|
|
|
exports.update_page = function () {
|
2019-06-12 10:33:45 +02:00
|
|
|
_.each(exports.all_notification_settings_labels, function (setting) {
|
2019-04-30 05:56:23 +02:00
|
|
|
if (setting === 'enable_offline_push_notifications'
|
|
|
|
&& !page_params.realm_push_notifications_enabled) {
|
|
|
|
// If push notifications are disabled at the realm level,
|
|
|
|
// we should just leave the checkbox always off.
|
|
|
|
return;
|
|
|
|
}
|
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;
|