From bad06d34f4867fc2850fb571af8829642111cd4b Mon Sep 17 00:00:00 2001 From: sBubshait Date: Thu, 7 Aug 2025 11:53:17 +0300 Subject: [PATCH] feat: iOS from receiving triple notificaitons to double only --- .../lib/services/notification_service.dart | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/frontend/lib/services/notification_service.dart b/frontend/lib/services/notification_service.dart index 455c5b1..aab4206 100644 --- a/frontend/lib/services/notification_service.dart +++ b/frontend/lib/services/notification_service.dart @@ -163,10 +163,11 @@ class NotificationService { } void _showNotification(RemoteNotification notification) { - // For web, we rely on the service worker to show notifications - // This is mainly for logging and debugging - print('Notification Title: ${notification.title}'); - print('Notification Body: ${notification.body}'); + // For web PWA, we rely on the service worker to show notifications + // This method is only for logging since service worker handles the UI + print('Foreground notification received - Title: ${notification.title}'); + print('Foreground notification received - Body: ${notification.body}'); + // Note: Do not show browser notification here as service worker handles it } void _handleNotificationTap(RemoteMessage message) { @@ -307,12 +308,15 @@ class NotificationService { final payload = { 'message': { 'token': token, - 'notification': {'title': title, 'body': body}, - 'data': data ?? {}, + // Use data-only for PWA to prevent duplicate notifications + 'data': { + 'title': title, + 'body': body, + ...(data ?? {}), + }, 'webpush': { - 'notification': { - 'icon': 'icons/ios/192.png', - 'badge': 'icons/ios/192.png', + 'headers': { + 'Urgency': 'normal', }, }, }, @@ -366,12 +370,15 @@ class NotificationService { final payload = { 'message': { 'topic': topic, - 'notification': {'title': title, 'body': body}, - 'data': data ?? {}, + // Use data-only for PWA to prevent duplicate notifications + 'data': { + 'title': title, + 'body': body, + ...(data ?? {}), + }, 'webpush': { - 'notification': { - 'icon': 'icons/ios/192.png', - 'badge': 'icons/ios/192.png', + 'headers': { + 'Urgency': 'normal', }, }, },