/* Service worker FCM — généré dynamiquement */ importScripts('https://www.gstatic.com/firebasejs/10.14.1/firebase-app-compat.js'); importScripts('https://www.gstatic.com/firebasejs/10.14.1/firebase-messaging-compat.js'); firebase.initializeApp(@json([ 'apiKey' => $firebase['api_key'], 'authDomain' => $firebase['auth_domain'], 'projectId' => $firebase['project_id'], 'storageBucket' => $firebase['storage_bucket'], 'messagingSenderId' => $firebase['messaging_sender_id'], 'appId' => $firebase['app_id'], ])); const messaging = firebase.messaging(); const iconUrl = @json(url('/images/logo.png')); messaging.onBackgroundMessage((payload) => { const n = payload.notification || {}; const title = n.title || payload.data?.title || 'Babi Meet'; const body = n.body || payload.data?.body || ''; self.registration.showNotification(title, { body, icon: iconUrl, badge: iconUrl, data: payload.data || {}, }); }); self.addEventListener('notificationclick', (event) => { event.notification.close(); const data = event.notification.data || {}; const params = new URLSearchParams(); if (data.type === 'message' && data.conversation_id) { params.set('tab', 'messages'); params.set('conv', String(data.conversation_id)); } else if (data.type === 'match') { params.set('tab', 'matches'); } else if (data.type === 'like' || data.type === 'super_like') { params.set('tab', 'favorites'); } else { params.set('tab', 'notifications'); } const targetUrl = @json(url('/app')) + (params.toString() ? '?' + params.toString() : ''); event.waitUntil( clients.matchAll({ type: 'window', includeUncontrolled: true }).then((list) => { for (const client of list) { if ('focus' in client) { client.postMessage({ type: 'push-nav', data }); return client.focus(); } } return clients.openWindow(targetUrl); }) ); });