Selaa lähdekoodia

Hide the bell's Enable button when the app runs without push keys

The Spry.Push adoption made the VAPID key operator-supplied (spry
keys); an unkeyed app previously still showed Enable and failed on
click with 'not available on this server'. The shared bell engine now
derives its state from the page's push_vapid_key: when empty, Enable
stays hidden and the helper text says the operator must run spry keys.
Turn-off and the test probe are unaffected (an existing subscription
can still be removed; the probe reports the true reason).
saddle-ClankerSaddle 17 tuntia sitten
vanhempi
sitoutus
7e148d3c1e
1 muutettua tiedostoa jossa 12 lisäystä ja 2 poistoa
  1. 12 2
      src/pages/app.js

+ 12 - 2
src/pages/app.js

@@ -702,16 +702,26 @@
                             if (!card) return;
                             var here = mine !== null && list.indexOf(mine) !== -1;
                             var others = otherBrowserCount();
+                            // Without a VAPID key (the app booted unkeyed and
+                            // `spry keys` has not run) there is nothing to
+                            // subscribe WITH: hide Enable and say why. An
+                            // existing subscription can still be turned off,
+                            // and the test probe reports the real reason.
+                            var keyed = !!state().push_vapid_key;
                             var onBtn = card.querySelector('[data-bell-on]');
                             var offBtn = card.querySelector('[data-bell-off]');
                             var help = card.querySelector('[data-bell-help]');
                             var testBtn = card.querySelector('[data-push-test]');
                             hereNow = here;
-                            if (onBtn) onBtn.hidden = here;
+                            if (onBtn) onBtn.hidden = here || !keyed;
                             if (offBtn) offBtn.hidden = !here;
                             if (testBtn) testBtn.hidden = !here;
                             if (help) {
-                                if (here) {
+                                if (!keyed) {
+                                    help.textContent = '\u2014 notifications are not configured'
+                                        + ' on this server yet (no push keys \u2014 the operator'
+                                        + ' needs to run spry keys)';
+                                } else if (here) {
                                     help.textContent = others > 0
                                         ? '\u2014 this browser receives question, RFC, review and waiting-on-drafts alerts; '
                                           + others + ' other browser(s) are also subscribed; "Notify me" per task adds its start, failure and completion'