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.

banners: Improve desktop notifications banner display logic.

Sayam Samald7e9efe21b6d
diff --git a/web/src/desktop_notifications.ts b/web/src/desktop_notifications.ts
index 3c24cdbebcc..09e44c6d9ca 100644
--- a/web/src/desktop_notifications.ts
+++ b/web/src/desktop_notifications.ts
@@ -105,8 +105,11 @@ export function granted_desktop_notifications_permission(): boolean {
return NotificationAPI?.permission === "granted";
}
-export function request_desktop_notifications_permission(): void {
+export async function request_desktop_notifications_permission(): Promise<NotificationPermission> {
if (NotificationAPI) {
- void NotificationAPI.requestPermission();
+ return await NotificationAPI.requestPermission();
}
+ // Act like notifications are blocked if they do not have access to
+ // the notification API.
+ return "denied";
}
diff --git a/web/src/navbar_alerts.ts b/web/src/navbar_alerts.ts
index b1d67fd241e..ca284fd7e17 100644
--- a/web/src/navbar_alerts.ts
+++ b/web/src/navbar_alerts.ts
@@ -254,10 +254,15 @@ export function initialize(): void {
$("#navbar_alerts_wrapper").on(
"click",
".request-desktop-notifications",
- function (this: HTMLElement) {
- const $banner = $(this).closest(".banner");
- banners.close($banner);
- desktop_notifications.request_desktop_notifications_permission();
+ function (this: HTMLElement): void {
+ void (async () => {
+ const $banner = $(this).closest(".banner");
+ const permission =
+ await desktop_notifications.request_desktop_notifications_permission();
+ if (permission === "granted" || permission === "denied") {
+ banners.close($banner);
+ }
+ })();
},
);