From c2d52cd4fd2aa1eb6f59cecfef134b6cdd1d801c Mon Sep 17 00:00:00 2001 From: Neven Date: Fri, 13 Dec 2024 15:10:44 +0100 Subject: [PATCH] Fix double notification on Android --- packages/core-mobile/app/services/fcm/FCMService.ts | 5 +++++ .../app/services/notifications/NotificationsService.ts | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core-mobile/app/services/fcm/FCMService.ts b/packages/core-mobile/app/services/fcm/FCMService.ts index d83e9f165..217f97379 100644 --- a/packages/core-mobile/app/services/fcm/FCMService.ts +++ b/packages/core-mobile/app/services/fcm/FCMService.ts @@ -6,6 +6,7 @@ import { BalanceChangeEvents, NotificationsBalanceChangeSchema } from 'services/fcm/types' +import { Platform } from 'react-native' type UnsubscribeFunc = () => void @@ -59,6 +60,10 @@ class FCMService { listenForMessagesBackground = (): void => { messaging().setBackgroundMessageHandler(async remoteMessage => { Logger.info('A new FCM message arrived in background', remoteMessage) + if (Platform.OS === 'android') { + //skip for android, FCM sdk handles this already + return + } const result = NotificationsBalanceChangeSchema.safeParse(remoteMessage) if (!result.success) { Logger.error( diff --git a/packages/core-mobile/app/services/notifications/NotificationsService.ts b/packages/core-mobile/app/services/notifications/NotificationsService.ts index 37287d8af..40fd91f3d 100644 --- a/packages/core-mobile/app/services/notifications/NotificationsService.ts +++ b/packages/core-mobile/app/services/notifications/NotificationsService.ts @@ -321,16 +321,14 @@ class NotificationsService { pressAction: { id: PressActionId.OPEN_PORTFOLIO, launchActivity: LAUNCH_ACTIVITY - } + }, + channelId: channelId ?? '' }, data } if (sound) { notification.ios = { sound: sound } } - if (channelId && notification.android) { - notification.android.channelId = channelId - } await notifee.displayNotification(notification).catch(Logger.error) } }