Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

navbar_alerts: Don't ask spectator for notifications access.

Aman Agrawal1295b47e3b90
diff --git a/frontend_tests/node_tests/navbar_alerts.js b/frontend_tests/node_tests/navbar_alerts.js
index 94653c7c7c4..f7d4c615076 100644
--- a/frontend_tests/node_tests/navbar_alerts.js
+++ b/frontend_tests/node_tests/navbar_alerts.js
@@ -8,6 +8,8 @@ const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params");
+page_params.is_spectator = false;
+
const ls_container = new Map();
const localStorage = set_global("localStorage", {
@@ -73,6 +75,13 @@ test("allow_notification_alert", () => {
notifications.permission_state = () => "granted";
notifications.granted_desktop_notifications_permission = () => "granted";
assert.equal(navbar_alerts.should_show_notifications(ls), false);
+
+ // Don't ask for permission to spectator.
+ util.is_mobile = () => false;
+ notifications.granted_desktop_notifications_permission = () => false;
+ notifications.permission_state = () => "granted";
+ page_params.is_spectator = true;
+ assert.equal(navbar_alerts.should_show_notifications(ls), false);
});
test("profile_incomplete_alert", () => {
diff --git a/static/js/navbar_alerts.js b/static/js/navbar_alerts.js
index 43832a51466..1b4d0e8271b 100644
--- a/static/js/navbar_alerts.js
+++ b/static/js/navbar_alerts.js
@@ -51,6 +51,9 @@ export function should_show_notifications(ls) {
}
return (
+ // Spectators cannot receive desktop notifications, so never
+ // request permissions to send them.
+ !page_params.is_spectator &&
// notifications *basically* don't work on any mobile platforms, so don't
// event show the banners. This prevents trying to access things that
// don't exist like `Notification.permission`.