Skip to content

feat(notifications): open the chat when a chat notification is tapped - #681

Merged
grunch merged 1 commit into
mainfrom
feat/chat-notification-opens-chat
Aug 26, 2026
Merged

feat(notifications): open the chat when a chat notification is tapped#681
grunch merged 1 commit into
mainfrom
feat/chat-notification-opens-chat

Conversation

@grunch

@grunch grunch commented Aug 25, 2026

Copy link
Copy Markdown
Member

Problem

Tapping a chat notification did not open the chat. Both chat kinds landed on the trade detail screen:

  • P2P chat (Action.chatMessage) built a plain-orderId payload, which resolveNotificationRoute maps to /trade_detail/:orderId.
  • Solver/dispute chat (Action.sendDm) already had a JSON payload, but the in-app notification list ignored it and pushed /trade_detail/:orderId too.

Change

Chat notifications now carry a structured payload and route to the conversation itself:

Action Payload Route
chatMessage {"type":"peer_chat","orderId":…} /chat_room/:orderId
sendDm {"type":"admin_dm","orderId":…,"disputeId":…} /dispute_details/:disputeId (→ DisputeChatScreen)
everything else plain orderId (unchanged) /trade_detail/:orderId

Payload construction was extracted into buildNotificationPayload() so the payload and the route resolution are covered by the same tests.

The in-app notification list (NotificationItem) follows the same dispatch: chatMessage opens the P2P chat room, sendDm resolves the dispute id from the session and opens the solver chat, falling back to the trade detail when the session has no dispute id yet.

Backward compatible: the legacy plain-orderId payload still resolves to the trade detail, so notifications posted before this change keep working. Both screens already render graceful error states when the session or peer is missing.

Test plan

  • flutter analyze — no new issues (the 2 remaining are pre-existing containsSemantics deprecations in automation_contract_test.dart)
  • flutter test — 1109 passing
  • New unit tests for buildNotificationPayload + resolveNotificationRoute (peer_chat, admin_dm with/without dispute, legacy payload)
  • New widget tests asserting NotificationItem navigates to /chat_room, /dispute_details, and the no-dispute fallback (verified RED before the fix)
  • Manual: receive a P2P message with the app backgrounded, tap the notification → chat room opens
  • Manual: receive a solver message on a disputed order, tap the notification → dispute chat opens
  • Manual: same two flows from a cold start (app terminated)

Summary by CodeRabbit

  • New Features

    • Notification taps now open the relevant chat room for peer messages.
    • Admin direct-message notifications open dispute details when available, or trade details as a fallback.
    • Notification payloads now support more precise routing while preserving existing behavior for standard notifications.
  • Bug Fixes

    • Improved notification navigation when dispute information is missing.

Tapping a chat notification landed on the trade detail screen instead of
the conversation the notification was about.

Push notifications now carry a structured payload for chat actions:
- Action.chatMessage -> {"type":"peer_chat"} -> /chat_room/:orderId
- Action.sendDm -> {"type":"admin_dm"} -> /dispute_details/:disputeId

Non-chat actions keep the legacy plain orderId payload, so previously
scheduled notifications still resolve to the trade detail screen.

The in-app notification list follows the same dispatch: peer chat
messages open the P2P chat room and solver DMs open the dispute chat,
falling back to the trade detail when the session has no dispute id yet.
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fa25f16b-362f-41ab-9fe0-121e956d18f6

📥 Commits

Reviewing files that changed from the base of the PR and between 75f54ef and 4c96d22.

📒 Files selected for processing (4)
  • lib/features/notifications/services/background_notification_service.dart
  • lib/features/notifications/widgets/notification_item.dart
  • test/features/notifications/services/background_notification_dm_detection_test.dart
  • test/features/notifications/widgets/notification_item_tap_test.dart

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The notification service now creates structured payloads for peer chats and admin DMs. Notification taps route chats to chat rooms, DMs to dispute details when available, and otherwise to trade details. Standard notifications retain plain order IDs.

Changes

Notification routing

Layer / File(s) Summary
Payload construction and background routing
lib/features/notifications/services/background_notification_service.dart, test/features/notifications/services/background_notification_dm_detection_test.dart
Structured peer_chat and admin_dm payloads now carry notification identifiers. Standard notifications retain plain order IDs. Routing tests cover chat, dispute, fallback, and legacy paths.
Notification tap routing
lib/features/notifications/widgets/notification_item.dart, test/features/notifications/widgets/notification_item_tap_test.dart
Peer chat taps open chat rooms. Solver DM taps open dispute details when the session has a dispute ID and otherwise open trade details. Widget tests cover these destinations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 4c96d

This change routes chat notifications to the appropriate chat screens while preserving legacy trade-detail routing; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant NotificationItem
  participant SessionProvider
  participant Router
  NotificationItem->>SessionProvider: Read dispute ID for solver DM
  SessionProvider-->>NotificationItem: Return dispute ID or no ID
  NotificationItem->>Router: Open chat room, dispute details, or trade details
Loading

Suggested reviewers: andreadiazcorreia, catrya

Poem

A rabbit taps a message bright
And hops to chat by lantern light
A dispute path appears in view
Or trade details come hopping through
Plain orders keep their steady trail

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: tapping a chat notification opens the related chat instead of the trade details screen. It is concise and directly related to the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/chat-notification-opens-chat

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Catrya Catrya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tACK

@grunch
grunch merged commit 11365d5 into main Aug 26, 2026
2 checks passed
@grunch
grunch deleted the feat/chat-notification-opens-chat branch August 26, 2026 18:12
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.

2 participants