Skip to content

feat(notifications): persist order cancellations in history with context#602

Open
AndreaDiazCorreia wants to merge 3 commits into
mainfrom
feat/persist-cancellation-notifications
Open

feat(notifications): persist order cancellations in history with context#602
AndreaDiazCorreia wants to merge 3 commits into
mainfrom
feat/persist-cancellation-notifications

Conversation

@AndreaDiazCorreia
Copy link
Copy Markdown
Member

@AndreaDiazCorreia AndreaDiazCorreia commented May 22, 2026

Summary

Closes #535.

When an order is canceled due to counterparty inactivity in waiting-payment or waiting-buyer-invoice, the user previously only saw a transient SnackBar — the event never reached the notifications screen (bell icon), so they could not review what happened to the order afterwards.

This PR persists every Action.canceled event to the notification history with a context-aware message based on the order's previous status:

  • waiting-payment → "The seller did not continue the order. The order has been cancelled."
  • waiting-buyer-invoice → "The buyer did not continue the order. The order has been cancelled."
  • Other (manual cancel, pending expiry, etc.) → generic "The order has been canceled."

Changes

  • NotificationDataExtractor: new previousStatus parameter; Action.canceled no longer returns null (which previously skipped persistence) and instead emits NotificationData with previous_status in values.
  • NotificationMessageMapper.getMessageKeyWithContext: resolves the correct localization key for Action.canceled based on previous_status.
  • AbstractMostroNotifier.subscribe(): captures previousStatus = state.status before state.updateWith(msg) and forwards it through handleEvent → extractor.
  • AbstractMostroNotifier.handleEvent(): removed the now-redundant showCustomMessage('orderCanceled') call — the centralized notify() path already shows the SnackBar and persists to history.
  • OrderNotifier: forwards previousStatus in its handleEvent override and converts the pending-order-expiry showCustomMessage('orderCanceled') to a notify(Action.canceled, ...) call so it also appears in the history.
  • Localizations: added notification_order_canceled_by_seller_inactivity_message and notification_order_canceled_by_buyer_inactivity_message to en, es, it, de, fr.

Test plan

  • fvm flutter analyze → no issues (verified)
  • fvm flutter test → all tests pass (verified, 369/369)
  • Manual: take a sell order, let the seller (maker) not pay → after Action.canceled, open the notifications screen and verify the "seller did not continue" message appears
  • Manual: take a buy order, let the buyer (maker) not provide an invoice → verify the "buyer did not continue" message appears
  • Manual: create a pending order and let it expire → verify a generic cancellation entry appears in the notifications screen
  • Manual: verify a single SnackBar is shown (no duplicate) on cancellation
  • Manual: verify message is correctly localized in EN, ES, IT

Summary by CodeRabbit

  • New Features

    • Cancellation notifications are now persisted and include previous order status when available.
    • Notifications differentiate seller vs. buyer inactivity and no longer tag user-initiated cancels as inactivity.
    • Manual cancels are tracked so user-initiated cancellations are handled appropriately; automatic expirations now record a deterministic notification event.
  • Localization

    • Added localized messages for inactivity-based cancellations in English, German, Spanish, French, and Italian.

Review Change Stack

…essages

- Add previousStatus parameter to notification extraction and event handling chain to differentiate cancellation reasons
- Map Action.canceled to specific messages based on previous status (waiting-payment → seller inactivity, waiting-buyer-invoice → buyer inactivity)
- Remove early return for canceled orders in NotificationDataExtractor; persist all cancellations to notification history
- Replace custom showCustomMessage calls
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2f034203-ae28-43d2-92aa-086bb04893be

📥 Commits

Reviewing files that changed from the base of the PR and between 18e4e16 and 2a95305.

📒 Files selected for processing (2)
  • lib/features/order/notifiers/abstract_mostro_notifier.dart
  • lib/features/order/notifiers/order_notifier.dart

Walkthrough

Threads previous order status and a user-initiated-cancel flag through notifiers into NotificationDataExtractor, which now persists Action.canceled notifications (optionally adding previous_status). Message mapper and localization add keys for seller vs buyer inactivity; auto-expiration uses the centralized notify path with a stable eventId.

Changes

Order cancellation notification for inactivity detection

Layer / File(s) Summary
Status threading through notifier chain
lib/features/order/notifiers/abstract_mostro_notifier.dart, lib/features/order/notifiers/order_notifier.dart
AbstractMostroNotifier.subscribe() captures current state.status and a user-initiated cancel flag, threads previousStatus and wasUserInitiatedCancel through handleEvent() (abstract and concrete), and forwards them to the notification extractor; inline SnackBar cancel handling is removed.
Status-aware notification extraction and message mapping
lib/features/notifications/utils/notification_data_extractor.dart, lib/features/notifications/utils/notification_message_mapper.dart
NotificationDataExtractor.extractFromMostroMessage() signature extended with previousStatus and wasUserInitiatedCancel; Action.canceled now yields persistent NotificationData and conditionally writes previous_status. NotificationMessageMapper.getMessageKeyWithContext() maps values['previous_status'] to new seller/buyer inactivity message keys.
OrderNotifier integration and auto-expiration
lib/features/order/notifiers/order_notifier.dart
OrderNotifier.handleEvent() updated to accept and forward previousStatus and wasUserInitiatedCancel. cancelOrder() marks cancels as user-initiated and unmarks on RPC failure. Auto-expiration now calls notify(Action.canceled, values: {'previous_status': Status.pending.value}, eventId: 'auto_expire:$orderId') instead of showing a transient custom message.
Inactivity cancellation message localization
lib/l10n/intl_*.arb (de, en, es, fr, it)
Adds new localized message keys for notification_order_canceled_by_seller_inactivity_message and notification_order_canceled_by_buyer_inactivity_message.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • MostroP2P/mobile#304: Touches notifier/notification pipeline and dispute notification handling related to AbstractMostroNotifier changes.
  • MostroP2P/mobile#252: Overlaps on cancellation-notification handling and _checkTimeoutAndCleanup/auto-expiration behavior.
  • MostroP2P/mobile#327: Modifies Action.canceled flow in the notifier/notification pipeline and is directly related to cancellation handling.

Suggested reviewers

  • grunch
  • Catrya

Poem

🐰 I hopped through status threads tonight,
marked which cancels came from hands, not plight,
I tucked the old state in a tiny note,
so inboxes can tell who failed to float,
🥕 a rabbit's cheer for clearer notification light.

🚥 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 and specifically summarizes the main change: persisting order cancellations to history with contextual information.
Linked Issues check ✅ Passed All code changes directly address issue #535: cancellations now persist in notification history with context-aware messages indicating which party's inactivity caused the cancellation.
Out of Scope Changes check ✅ Passed All changes are scoped to the cancellation notification persistence objective; no unrelated modifications detected across the six modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/persist-cancellation-notifications

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/features/order/notifiers/order_notifier.dart`:
- Around line 187-193: The notify call in order_notifier.dart that persists
auto-expiration cancellations (using
ref.read(notificationActionsProvider.notifier) and notify with Action.canceled)
must include a stable eventId to avoid duplicate history entries; update the
notify invocation to pass a deterministic eventId (for example a string like
"auto_expire:<orderId>" or a hash based on orderId + expirationTimestamp) via
the eventId parameter so repeated emissions of the same cancellation won't
create duplicate notifications.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2f7c680-aecf-4829-b16e-91bc188b1315

📥 Commits

Reviewing files that changed from the base of the PR and between df7490c and 0b4f402.

📒 Files selected for processing (9)
  • lib/features/notifications/utils/notification_data_extractor.dart
  • lib/features/notifications/utils/notification_message_mapper.dart
  • lib/features/order/notifiers/abstract_mostro_notifier.dart
  • lib/features/order/notifiers/order_notifier.dart
  • lib/l10n/intl_de.arb
  • lib/l10n/intl_en.arb
  • lib/l10n/intl_es.arb
  • lib/l10n/intl_fr.arb
  • lib/l10n/intl_it.arb

Comment thread lib/features/order/notifiers/order_notifier.dart Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b4f402eb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/features/notifications/utils/notification_message_mapper.dart
Copy link
Copy Markdown

@ermeme ermeme Bot left a comment

Choose a reason for hiding this comment

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

Revisión Hermes

Veredicto: NO aprobaría este PR todavía.

Hay un problema funcional: el nuevo criterio usa solo previous_status para decidir si la cancelación fue por inactividad. Eso mezcla cancelaciones manuales con expiraciones reales y puede mostrar un mensaje falso en el historial.

Necesita un discriminador más preciso antes de entrar.

Comment thread lib/features/notifications/utils/notification_message_mapper.dart
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/features/order/notifiers/order_notifier.dart`:
- Around line 127-131: The code sets the user-initiated cancel flag via
AbstractMostroNotifier.markUserInitiatedCancel(orderId) before awaiting
mostroService.cancelOrder(orderId); if the async call throws the flag remains
set and later Action.canceled may be misclassified—wrap the await in a
try/catch, and in the catch call the corresponding rollback/unmark method (e.g.,
AbstractMostroNotifier.unmarkUserInitiatedCancel(orderId) or the actual method
that clears the flag) before rethrowing the error so the flag is only left set
on successful cancel.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0141b9cb-d938-47c6-ba1f-4589e8423f88

📥 Commits

Reviewing files that changed from the base of the PR and between 0b4f402 and 18e4e16.

📒 Files selected for processing (3)
  • lib/features/notifications/utils/notification_data_extractor.dart
  • lib/features/order/notifiers/abstract_mostro_notifier.dart
  • lib/features/order/notifiers/order_notifier.dart

Comment thread lib/features/order/notifiers/order_notifier.dart Outdated
Copy link
Copy Markdown

@ermeme ermeme Bot left a comment

Choose a reason for hiding this comment

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

Revisión Hermes

Veredicto: todavía no lo aprobaría.

El commit arregla el caso principal, pero dejó un hueco: el flag de markUserInitiatedCancel() se setea antes de await mostroService.cancelOrder(orderId) y nunca se limpia si esa llamada falla o no llega a emitir Action.canceled. Eso deja estado colgado y puede contaminar una cancelación posterior del mismo orderId.

La solución debería limpiar el flag en un try/finally o moverlo a una estructura con expiración/caducidad.

Comment thread lib/features/order/notifiers/order_notifier.dart
Copy link
Copy Markdown

@ermeme ermeme Bot left a comment

Choose a reason for hiding this comment

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

Hermes review

Approved.

The previous blocker is fixed: manual cancels are now tagged separately, the fallback is generic when the cancel was user-initiated, and the failure path now rolls back the marker so it does not leak into later events. The notification history behavior is now consistent for inactivity vs manual cancellation.

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.

Add notification screen when orders are cancelled due to counterparty inactivity

1 participant