Skip to content

fix(notifications): handle FCM background/terminated notification tap navigation - #5127

Closed
mdmohsin7 wants to merge 2 commits into
mainfrom
fix/notification-tap-navigation
Closed

mdmohsin7 wants to merge 2 commits into
mainfrom
fix/notification-tap-navigation

Conversation

@mdmohsin7

Copy link
Copy Markdown
Member

Problem

Fixes #5126

When a user taps an Omi response push notification:

  • From background state: app opens to the last screen instead of the conversation
  • From terminated state: same issue — app opens but doesn't navigate

Root Cause

The Flutter app was missing two FCM handlers in notification_service_fcm.dart:

  1. FirebaseMessaging.onMessageOpenedApp — fires when user taps a notification while app is in the background
  2. FirebaseMessaging.instance.getInitialMessage() — fires when app is launched from a killed state via notification tap

The 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: Added onMessageOpenedApp listener and getInitialMessage() call in listenForMessages()
  • notifications.dart: Exposed NotificationUtil.handleNavigateTo(String route) as a public static method (wraps existing _handleAppLinkOrDeepLink)

Testing

  1. Send yourself a chat message via the Omi app
  2. Put app in background → tap the notification → should navigate to the conversation
  3. Kill the app → tap the notification → app should open directly to the 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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 <[email protected]>
beastoin
beastoin previously approved these changes Mar 10, 2026

@beastoin beastoin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@beastoin
beastoin dismissed their stale review March 10, 2026 01:50

Withdrawing review — re-reviewing after internal discussion.

@beastoin

Copy link
Copy Markdown
Collaborator

Hey @mdmohsin7 👋 Friendly reminder — this PR has been quiet for a bit. If you don't need further assistance from the CTO, feel free to go ahead and merge it. Let's close the loop and not let it go stale. Thanks!

@beastoin

Copy link
Copy Markdown
Collaborator

Don't let your PR go stale. Unfortunately, I won't review further PRs from the internal team proactively, so please reopen and mention others who have review permissions. It's important to keep PRs from going stale.

@beastoin beastoin closed this Apr 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @mdmohsin7 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our roadmap and vision

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community! 💜

kodjima33 pushed a commit that referenced this pull request Aug 6, 2026
…5126) (#11144)

* fix(app): navigate from FCM background/terminated notification taps (#5126)

Register onMessageOpenedApp and getInitialMessage so push taps honor
navigate_to instead of leaving the user on the last screen. Resurrects
closed #5127 with a shared String-safe navigate_to parser.

Co-authored-by: Cursor <[email protected]>

* fix(app): wait for navigator before FCM cold-start navigate (#5126)

getInitialMessage can resolve before runApp attaches globalNavigatorKey,
so pushReplacement previously no-op'd on terminated taps. Poll until the
navigator is ready (same race class as app_links #4763).

Co-authored-by: Cursor <[email protected]>

* fix(app): const FCM navigate_to test maps for analyzer ratchet (#5126)

Non-const map literals tripped prefer_const_literals (baseline 0). Drop
the redundant foundation import that also added an unnecessary_import.

Co-authored-by: Cursor <[email protected]>

* chore(ci): retrigger checks after hermetic scope timeout (#5126)

Detect Hermetic Backend Scope hit the 2m job timeout (cancelled); Merge Gate
fail-closed on SCOPE_RESULT=cancelled. App-only PR — no backend scope change.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Cursor <[email protected]>
@undivisible
undivisible deleted the fix/notification-tap-navigation branch August 20, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Tapping Omi response notifications doesn't navigate to the correct conversation

2 participants