Skip to content

Add P2P chat background notifications (Phase 2)#529

Draft
AndreaDiazCorreia wants to merge 8 commits intomainfrom
feat/p2p-chat-background-notifications
Draft

Add P2P chat background notifications (Phase 2)#529
AndreaDiazCorreia wants to merge 8 commits intomainfrom
feat/p2p-chat-background-notifications

Conversation

@AndreaDiazCorreia
Copy link
Member

Summary

  • Extract tradeKey event handling into _handleTradeKeyEvent() for clarity
  • Add sharedKey matching in _decryptAndProcessEvent() so P2P chat messages arriving in background are detected
  • Add _handleP2PChatEvent() that decrypts via p2pUnwrap(sharedKey) and triggers a generic "New message" notification
  • Reuses existing localization keys and notification pipeline from Phase 1 (admin DM notifications)

How it works

Previously, _decryptAndProcessEvent() only matched events by tradeKey.public, so P2P chat messages (which arrive at sharedKey.public) were silently dropped. Now, when no tradeKey match is found, sessions are checked by sharedKey.public. Matched events are decrypted with p2pUnwrap and produce the same generic chat notification used for admin DMs.

Test plan

  • Open an active trade with P2P chat between two users
  • Send the app to background (do NOT kill it)
  • From the counterparty, send a P2P chat message
  • Verify a local notification appears with "New message" title and generic body
  • Tap the notification and verify it navigates to the trade detail screen
  • Verify Mostro protocol notifications (order updates, cancellations, timeouts) still work as before
  • Verify admin/dispute chat background notifications still work as before
  • Run flutter analyze — zero issues expected

Add detection for admin/dispute DM messages in background service by checking
for {"dm": {...}} format before standard MostroMessage parsing. Return synthetic
MostroMessage with sendDm action to trigger notification flow.

Part of chat notifications implementation (Phase 1: Admin DM background notifications).
…load

Extract duplicate DM format detection logic (`item is Map && item.containsKey('dm')`)
into shared `NostrUtils.isDmPayload()` method. Replace inline checks in
DisputeChatNotifier, BackgroundNotificationService, and MostroService with calls
to the new utility.

Update tests to exercise NostrUtils.isDmPayload directly instead of testing
detection logic in isolation. Add edge case coverage for non-Map types.
…xtractor

Add explicit case handlers for Action.sendDm and Action.cooperativeCancelAccepted
in NotificationDataExtractor to ensure they generate non-temporary notifications.
Both actions require no payload extraction (empty values map).

Expand test coverage to validate three layers of the admin/dispute DM notification
pipeline: NostrUtils.isDmPayload detection, MostroMessage construction with sendDm
action, and NotificationDataExtractor
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d78cfb63-de29-4a28-8406-2370eddc78ae

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/p2p-chat-background-notifications
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

You can get early access to new features in CodeRabbit.

Enable the early_access setting to enable early access features such as new models, tools, and more.

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.

1 participant