Skip to content

refactor: Introduce EventsManager to track events for different features#2096

Merged
facumenzella merged 19 commits into
mainfrom
feat/event-manager
Feb 5, 2025
Merged

refactor: Introduce EventsManager to track events for different features#2096
facumenzella merged 19 commits into
mainfrom
feat/event-manager

Conversation

@facumenzella

@facumenzella facumenzella commented Jan 30, 2025

Copy link
Copy Markdown
Member

Motivation

Introduce events for Customer Center

Description

I am working on introducing events for customer center, and I needed an event manager an realized PaywallEventManager could be generalized to be reused. This introduces EventsManager, with backwards compatibility for previous events

@facumenzella facumenzella requested review from a team and vegaro January 30, 2025 14:18
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesFactory.kt Outdated
@codecov

codecov Bot commented Jan 30, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 69.54023% with 53 lines in your changes missing coverage. Please review.

Project coverage is 80.81%. Comparing base (a205ff1) to head (d295af6).
Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
...revenuecat/purchases/common/events/BackendEvent.kt 33.33% 25 Missing and 1 partial ⚠️
...evenuecat/purchases/common/events/EventsManager.kt 82.50% 11 Missing and 3 partials ⚠️
...ecat/purchases/common/events/BackendStoredEvent.kt 72.72% 4 Missing and 2 partials ⚠️
...otlin/com/revenuecat/purchases/PurchasesFactory.kt 55.55% 4 Missing ⚠️
.../com/revenuecat/purchases/PurchasesOrchestrator.kt 66.66% 0 Missing and 1 partial ⚠️
...evenuecat/purchases/common/events/EventsRequest.kt 92.85% 0 Missing and 1 partial ⚠️
...com/revenuecat/purchases/utils/EventsFileHelper.kt 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2096      +/-   ##
==========================================
- Coverage   81.11%   80.81%   -0.30%     
==========================================
  Files         271      272       +1     
  Lines        8953     9049      +96     
  Branches     1269     1280      +11     
==========================================
+ Hits         7262     7313      +51     
- Misses       1162     1201      +39     
- Partials      529      535       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventsManager.kt Outdated
@facumenzella facumenzella changed the title refactor: Introduce abstract EventManager and PaywallEventManager impl refactor: Introduce EventsManager to track events Jan 31, 2025
@facumenzella facumenzella changed the title refactor: Introduce EventsManager to track events [WIP] refactor: Introduce EventsManager to track events Jan 31, 2025
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesFactory.kt Outdated
@facumenzella facumenzella changed the title [WIP] refactor: Introduce EventsManager to track events refactor: Introduce EventsManager to track events Jan 31, 2025
@facumenzella facumenzella changed the title refactor: Introduce EventsManager to track events refactor: Introduce EventsManager to track events for different features Jan 31, 2025
@facumenzella

Copy link
Copy Markdown
Member Author

@RevenueCat/coresdk one thing I am thinking is that maybe its worth is keeping PaywallsEventManager instead of the legacy FileHelper because it's already tested.

Either that, or just keep the tests from PaywallsManager instead EventsManagerTests

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventsManager.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventRequest.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/FeatureEvent.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventsManager.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventsManager.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventsManager.kt Outdated
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/BackendEvent.kt Outdated
@facumenzella facumenzella requested a review from vegaro February 4, 2025 15:02
@facumenzella facumenzella requested a review from vegaro February 4, 2025 17:22
Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventRequest.kt Outdated
subclass(BackendEvent.Paywalls::class, BackendEvent.Paywalls.serializer())
}
}
classDiscriminator = "discriminator"

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.

I thought in the request there's no discriminator?

@facumenzella facumenzella Feb 5, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I ended up adding it because tests were failing. If I understood correctly, you must use a classDiscriminator when using polymorphic. However, this is just use for tests and it should not break anything, since it's just an extra field right?

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/EventsManager.kt Outdated
Comment thread purchases/src/testDefaults/kotlin/com/revenuecat/purchases/PurchasesTest.kt Outdated
@facumenzella facumenzella requested a review from vegaro February 5, 2025 09:46

@vegaro vegaro 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.

I think this should be good to merge. Just some small comments

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/common/events/BackendEvent.kt Outdated
flushInProgress = true

if (!legacyFlushDone) {
flushLegacyEvents()

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.

actually since it's enqueued... there's a race condition if flushEvents executes again before flushLegacyEvents finishes? A way to solve it is removing the enqueuing in flushLegacyEvents. Or actually... shouldn't it go before flushLegacyEvents and not after?

*
* @property event The associated `PaywallEvent`.
*/
data class Paywall(val event: PaywallEvent) : FeatureEvent()

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.

not a merge stopper but this could be directly the PaywallEvent? So you could make the PaywallEvent a FeatureEvent

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can apply this in another PR, since this has already grown a lot 😓

@facumenzella facumenzella enabled auto-merge (squash) February 5, 2025 12:18
@facumenzella facumenzella merged commit 25c90b0 into main Feb 5, 2025
@facumenzella facumenzella deleted the feat/event-manager branch February 5, 2025 12:46
This was referenced Feb 12, 2025
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.

2 participants