From 609082c7b37e284f84b1f223ee352497deda1b70 Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <0xsysr3ll@pm.me> Date: Tue, 9 Dec 2025 00:04:28 +0100 Subject: [PATCH] fix(webpush): rework web push notification status verification logic Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> --- .../UserNotificationsWebPush/index.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx index 8ebc53c5d..fde07b2c2 100644 --- a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx +++ b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx @@ -170,10 +170,30 @@ const UserWebPushSettings = () => { useEffect(() => { const verifyWebPush = async () => { const enabled = await verifyPushSubscription(user?.id, currentSettings); - setWebPushEnabled(enabled); + let isEnabled = enabled; + + if (!enabled && 'serviceWorker' in navigator) { + const { subscription } = await getPushSubscription(); + if (subscription) { + isEnabled = true; + } + } + + if (!isEnabled && dataDevices && dataDevices.length > 0) { + const currentUserAgent = navigator.userAgent; + const hasMatchingDevice = dataDevices.some( + (device) => device.userAgent === currentUserAgent + ); + + if (hasMatchingDevice || dataDevices.length === 1) { + isEnabled = true; + } + } + + setWebPushEnabled(isEnabled); localStorage.setItem( 'pushNotificationsEnabled', - enabled ? 'true' : 'false' + isEnabled ? 'true' : 'false' ); };