fix(webpush): rework web push notification status verification logic

Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me>
This commit is contained in:
0xsysr3ll
2025-12-09 00:04:28 +01:00
parent 39e6115467
commit 609082c7b3

View File

@@ -170,10 +170,30 @@ const UserWebPushSettings = () => {
useEffect(() => { useEffect(() => {
const verifyWebPush = async () => { const verifyWebPush = async () => {
const enabled = await verifyPushSubscription(user?.id, currentSettings); 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( localStorage.setItem(
'pushNotificationsEnabled', 'pushNotificationsEnabled',
enabled ? 'true' : 'false' isEnabled ? 'true' : 'false'
); );
}; };