Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double notification on Android #2156

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core-mobile/app/services/fcm/FCMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BalanceChangeEvents,
NotificationsBalanceChangeSchema
} from 'services/fcm/types'
import { Platform } from 'react-native'

type UnsubscribeFunc = () => void

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,14 @@ class NotificationsService {
pressAction: {
id: PressActionId.OPEN_PORTFOLIO,
launchActivity: LAUNCH_ACTIVITY
}
},
channelId: channelId ?? ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a difference between passing an empty string and undefined for channelId?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in my experience notifee will report such payload as invalid

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's weird since channelId is an optional parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's optional for ios platform, on android it's required

},
data
}
if (sound) {
notification.ios = { sound: sound }
}
if (channelId && notification.android) {
notification.android.channelId = channelId
}
await notifee.displayNotification(notification).catch(Logger.error)
}
}
Expand Down
Loading