From 7151597888ee4fffbb402dc5f5a04493a7112c2a Mon Sep 17 00:00:00 2001 From: Kris Hu Date: Mon, 14 Jul 2025 12:17:44 +0800 Subject: [PATCH] fix(notification): allow in-app notification in background when push notification isn't enabled --- src/app/pages/client/ClientNonUIFeatures.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app/pages/client/ClientNonUIFeatures.tsx b/src/app/pages/client/ClientNonUIFeatures.tsx index fa9a26ad..f9261df6 100644 --- a/src/app/pages/client/ClientNonUIFeatures.tsx +++ b/src/app/pages/client/ClientNonUIFeatures.tsx @@ -94,6 +94,7 @@ function InviteNotifications() { const navigate = useNavigate(); const [showNotifications] = useSetting(settingsAtom, 'useInAppNotifications'); + const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications'); const [notificationSound] = useSetting(settingsAtom, 'isNotificationSounds'); const notify = useCallback( @@ -119,7 +120,7 @@ function InviteNotifications() { }, []); useEffect(() => { - if (document.visibilityState != "visible") return; + if (usePushNotifications && document.visibilityState != "visible") return; if (invites.length > perviousInviteLen && mx.getSyncState() === 'SYNCING') { if (showNotifications && notificationPermission('granted')) { notify(invites.length - perviousInviteLen); @@ -129,7 +130,16 @@ function InviteNotifications() { playSound(); } } - }, [mx, invites, perviousInviteLen, showNotifications, notificationSound, notify, playSound]); + }, [ + mx, + invites, + perviousInviteLen, + showNotifications, + usePushNotifications, + notificationSound, + notify, + playSound + ]); return ( // eslint-disable-next-line jsx-a11y/media-has-caption @@ -146,6 +156,7 @@ function MessageNotifications() { const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); const [showNotifications] = useSetting(settingsAtom, 'useInAppNotifications'); + const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications'); const [notificationSound] = useSetting(settingsAtom, 'isNotificationSounds'); const navigate = useNavigate(); @@ -197,7 +208,7 @@ function MessageNotifications() { data ) => { if (mx.getSyncState() !== 'SYNCING') return; - if (document.visibilityState != "visible") return; + if (usePushNotifications && document.visibilityState != "visible") return; if (document.hasFocus() && (selectedRoomId === room?.roomId || notificationSelected)) return; if ( @@ -252,6 +263,7 @@ function MessageNotifications() { notificationSound, notificationSelected, showNotifications, + usePushNotifications, playSound, notify, selectedRoomId,