From 5c67919c47f7cfbdf2ac72a79b8d1deccf95dbb2 Mon Sep 17 00:00:00 2001 From: scott Date: Mon, 13 Apr 2026 13:48:07 -0700 Subject: [PATCH] Enable browser notifications by default and always show them Default prefs now start enabled with osa-announcements channel on. Removed visibility check (tab focus) and self-filter so all alerts trigger a browser notification regardless of who created them. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/hooks/use-browser-notifications.ts | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/frontend/src/hooks/use-browser-notifications.ts b/frontend/src/hooks/use-browser-notifications.ts index 577fc4b..15d98a8 100644 --- a/frontend/src/hooks/use-browser-notifications.ts +++ b/frontend/src/hooks/use-browser-notifications.ts @@ -1,6 +1,5 @@ import { useCallback, useRef, useSyncExternalStore } from "react"; import { useMqttRawSubscription } from "@/hooks/use-mqtt"; -import { useAuthContext } from "@/contexts/auth-context"; // ── localStorage sync ──────────────────────────────────────────── @@ -12,7 +11,7 @@ interface NotificationPrefs { channels: string[]; } -const DEFAULT_PREFS: NotificationPrefs = { enabled: false, channels: [] }; +const DEFAULT_PREFS: NotificationPrefs = { enabled: true, channels: ["osa-announcements"] }; // Cache the snapshot so useSyncExternalStore gets a stable reference let cachedRaw: string | null = null; @@ -108,7 +107,6 @@ export function useNotificationPreference() { export function useNotificationTrigger() { const { enabled, channels, permissionState } = useNotificationPreference(); - const { user } = useAuthContext(); const enabledRef = useRef(enabled); enabledRef.current = enabled; @@ -116,16 +114,11 @@ export function useNotificationTrigger() { channelsRef.current = channels; const permRef = useRef(permissionState); permRef.current = permissionState; - const userRef = useRef(user); - userRef.current = user; const handleMessage = useCallback( (topic: string, payload: Record) => { if (!enabledRef.current || permRef.current !== "granted") return; - // Don't notify when tab is focused - if (document.visibilityState === "visible") return; - // Extract channel from topic: mgmt/notifications/{channel} const parts = topic.split("/"); const channel = parts[parts.length - 1]; @@ -134,16 +127,6 @@ export function useNotificationTrigger() { // Check if user is subscribed to this channel if (!channelsRef.current.includes(channel)) return; - // Skip own announcements - if ( - channel === "osa-announcements" && - payload.created_by && - userRef.current && - payload.created_by === (userRef.current as { username?: string }).username - ) { - return; - } - const title = (payload.title as string) || "MGMT Notification"; const body = (payload.body as string) || ""; const id = (payload.id as string) || String(Date.now());