fix(notifications): handle FCM background/terminated notification tap navigation#5127
fix(notifications): handle FCM background/terminated notification tap navigation#5127
Conversation
… navigation - Add FirebaseMessaging.onMessageOpenedApp listener to navigate when user taps a notification while app is in the background - Add FirebaseMessaging.getInitialMessage() call to handle notification taps that launch the app from terminated state - Expose NotificationUtil.handleNavigateTo() as a public static method to support programmatic deep-link navigation from FCM handlers Fixes: tapping Omi response notifications opens app to last screen instead of navigating to the relevant conversation Closes #5126
There was a problem hiding this comment.
Code Review
This pull request correctly addresses an issue with notification tap navigation from background and terminated states by adding the necessary FCM handlers. The changes are logical and follow the PR's objective. I've added one suggestion to refactor the new handlers to reduce code duplication and improve type safety, aligning with the preference for helper functions to centralize complex logic, which will enhance the code's maintainability and robustness.
…plicate logic Addresses Gemini review: consolidates duplicated background/terminated notification tap handling into a single local helper and uses `is String` type check instead of `.toString()` for safer payload handling. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
beastoin
left a comment
There was a problem hiding this comment.
Review by @ryo
Clean fix. Small change (+20/-0), correctly handles both FCM notification tap paths:
- Background →
onMessageOpenedApp.listen()— fires when app is backgrounded and user taps notification - Terminated →
getInitialMessage()— fires when app was killed and reopened via notification
The public handleNavigateTo() method properly delegates to the existing _handleAppLinkOrDeepLink() navigation system. No side effects on existing notification flows.
Recommendation: Safe to merge.
Withdrawing review — re-reviewing after internal discussion.
Problem
Fixes #5126
When a user taps an Omi response push notification:
Root Cause
The Flutter app was missing two FCM handlers in
notification_service_fcm.dart:FirebaseMessaging.onMessageOpenedApp— fires when user taps a notification while app is in the backgroundFirebaseMessaging.instance.getInitialMessage()— fires when app is launched from a killed state via notification tapThe backend already sends
navigate_to(e.g./chat/omi) in the FCM data payload — the app just never read it on tap.Changes
notification_service_fcm.dart: AddedonMessageOpenedApplistener andgetInitialMessage()call inlistenForMessages()notifications.dart: ExposedNotificationUtil.handleNavigateTo(String route)as a public static method (wraps existing_handleAppLinkOrDeepLink)Testing