Skip to content

Support multiple UpdatedCustomerInfoListeners#3247

Draft
facumenzella wants to merge 6 commits intomainfrom
facundo/cc-628-multi-listener
Draft

Support multiple UpdatedCustomerInfoListeners#3247
facumenzella wants to merge 6 commits intomainfrom
facundo/cc-628-multi-listener

Conversation

@facumenzella
Copy link
Copy Markdown
Member

@facumenzella facumenzella commented Mar 16, 2026

Summary

  • Add addUpdatedCustomerInfoListener/removeUpdatedCustomerInfoListener(listener) methods to support multiple concurrent listeners in CustomerInfoUpdateHandler, PurchasesOrchestrator, and both Purchases flavors
  • Deprecate the single-listener updatedCustomerInfoListener property and no-arg removeUpdatedCustomerInfoListener()
  • Expose the new API through PurchasesType/PurchasesImpl/MockPurchasesType so the UI module can register its own listener
  • New listeners receive cached customer info immediately on registration, matching legacy behavior

This is infrastructure-only — Customer Center ViewModel integration is a follow-up.

Fixes in sendToSingleListener / addUpdatedCustomerInfoListener

  • sendToSingleListener no longer mutates lastSentCustomerInfo: the shared dedup gate must only be advanced by notifyListeners. Previously, registering a new listener while the cache held an older value than what was last broadcast would roll the gate backwards, causing double-delivery to all existing listeners on the next notifyListeners call.
  • listeners.add() moved to after the initial cached-info dispatch: prevents a concurrent notifyListeners from interleaving a newer value before the new listener's initial delivery, which would leave it in a stale state.

Test plan

  • CustomerInfoUpdateHandlerTest — 8 new test cases covering:
    • Multiple listeners all notified on change
    • Removing a specific listener stops its notifications
    • Legacy property and added listeners coexist
    • Setting legacy to null doesn't affect added listeners
    • New listener gets cached info immediately even after prior broadcasts
    • removeAllListeners clears everything
    • Added listener skips cached info in CEC mode
    • Regression: adding a new listener does not cause double delivery to existing listeners
  • Existing tests pass with @Suppress("DEPRECATION") on legacy usages
  • API surface files updated via api-dump.sh
  • detekt passes

🤖 Generated with Claude Code

Add add/remove methods for registering multiple UpdatedCustomerInfoListener
instances, deprecate the single-listener property setter, and expose the new
API through PurchasesType so the UI module can use it.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
facumenzella and others added 5 commits March 17, 2026 08:37
Resolve conflict in MockPurchasesType.kt — keep new listener methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add missing mockk stubs for addUpdatedCustomerInfoListener,
removeUpdatedCustomerInfoListener, and removeAllListeners. Update test
that verified the old close() behavior (setting listener to null) to
verify removeAllListeners() instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Merge duplicate `if (lastSent != customerInfo)` checks in notifyListeners
- Guard sendToSingleListener against overwriting lastSentCustomerInfo with stale data
- Only track diagnostics in sendToSingleListener when info differs from last sent

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…istener support

- Remove lastSentCustomerInfo mutation from sendToSingleListener to prevent
  rolling back the global dedup gate to a stale value, which could cause
  double-delivery to all existing listeners on the next notifyListeners call
- Move listeners.add() to after the initial cached-info dispatch so a concurrent
  notifyListeners cannot interleave a newer value before the new listener's
  initial delivery, preventing out-of-order delivery on the main thread

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…sting ones

Covers the fix to sendToSingleListener that prevented it from rolling back
lastSentCustomerInfo to a stale value, which would cause re-delivery to all
existing listeners on the next notifyListeners call.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant