From 5ffca5e388132f09f6da34802afbde0df512ef11 Mon Sep 17 00:00:00 2001 From: Shikhar Vaish Date: Fri, 31 Aug 2018 02:15:59 +0530 Subject: [PATCH] settings: Warn if server is unable to deliver mobile push notifications. The "notification settings" page previously advertised support for mobile push notifications via checkboxes, even if the server hadn't yet been registered for push notifications. This was a frequent source of onboarding pain for new Zulip organizations. We fix this by providing a clear warning and disabling the relevant inputs on the settings pages. Modified significantly by tabbott to correct some tricky logic errors as well as some copy-paste bugs. Fixes #10331. --- frontend_tests/node_tests/templates.js | 1 + static/js/templates.js | 21 +++++++++++++++++++ .../settings/notification-settings.handlebars | 7 +++++-- .../settings/settings_checkbox.handlebars | 10 +++++++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/frontend_tests/node_tests/templates.js b/frontend_tests/node_tests/templates.js index 134c219454..1e99f02763 100644 --- a/frontend_tests/node_tests/templates.js +++ b/frontend_tests/node_tests/templates.js @@ -1075,6 +1075,7 @@ run_test('settings_tab', () => { enable_offline_push_notifications: true, enable_online_push_notifications: true, enable_digest_emails: true, realm_name_in_notifications: true, + realm_push_notifications_enabled: true, }; var page_params = $.extend(page_param_checkbox_options, { full_name: "Alyssa P. Hacker", password_auth_enabled: true, diff --git a/static/js/templates.js b/static/js/templates.js index 850040b44e..1633039e09 100644 --- a/static/js/templates.js +++ b/static/js/templates.js @@ -62,6 +62,27 @@ Handlebars.registerHelper('if_and', function () { return options.fn(this); }); +Handlebars.registerHelper('unless_a_not_b', function () { + // Execute the conditional code if at least one condition is false. + // Example usage: + // {{#unless_a_not_b cond1 cond2}} + //

a is false or b is true

+ // {{/unless_a_not_b}} + var options = arguments[arguments.length - 1]; + if (arguments[0] && !arguments[1]) { + return options.inverse(this); + } + return options.fn(this); +}); + +Handlebars.registerHelper('if_not_a_or_b_and_not_c', function () { + var options = arguments[arguments.length - 1]; + if (arguments[0] === false || arguments[1] === true && arguments[2] === false) { + return options.fn(this); + } + return options.inverse(this); +}); + Handlebars.registerHelper('if_or', function () { // Execute the conditional code if any of the conditions are true. // Example usage: diff --git a/static/templates/settings/notification-settings.handlebars b/static/templates/settings/notification-settings.handlebars index 6cf7659e72..61d9a1a38f 100644 --- a/static/templates/settings/notification-settings.handlebars +++ b/static/templates/settings/notification-settings.handlebars @@ -24,6 +24,7 @@ "setting_name" "enable_stream_push_notifications" "is_checked" page_params.enable_stream_push_notifications "label" settings_label.enable_stream_push_notifications + "push_notifications_tooltip" true "end_content" '
'}} {{partial "settings_checkbox" @@ -67,14 +68,16 @@ {{partial "settings_checkbox" "setting_name" "enable_offline_push_notifications" "is_checked" page_params.enable_offline_push_notifications - "label" settings_label.enable_offline_push_notifications}} + "label" settings_label.enable_offline_push_notifications + "push_notifications_tooltip" true}} {{partial "settings_checkbox" "setting_name" "enable_online_push_notifications" "is_checked" page_params.enable_online_push_notifications "is_parent_setting_enabled" page_params.enable_offline_push_notifications "is_nested" true - "label" settings_label.enable_online_push_notifications}} + "label" settings_label.enable_online_push_notifications + "push_notifications_tooltip" true}}
diff --git a/static/templates/settings/settings_checkbox.handlebars b/static/templates/settings/settings_checkbox.handlebars index f2f0445de0..d7da14fb40 100644 --- a/static/templates/settings/settings_checkbox.handlebars +++ b/static/templates/settings/settings_checkbox.handlebars @@ -1,15 +1,21 @@ -
+
+ {{#if push_notifications_tooltip}} + + {{/if}} {{{end_content}}}