Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Dec 2, 2024
1 parent df2d7e4 commit c2bf7c5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ import RevenueCat
darkMode: darkMode,
isSandbox: isSandbox,
displayMode: displayMode)
let event = CustomerCenterEvent.impression(CustomerCenterEvent.CreationData(), eventData)
let event = CustomerCenterEvent.impression(CustomerCenterEventCreationData(), eventData)

purchasesProvider.track(customerCenterEvent: event)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private extension FeedbackSurveyViewModel {
surveyOptionTitleKey: option.title,
additionalContext: nil,
revisionID: 0)
let event = CustomerCenterSurveyOptionChosenEvent.surveyOptionChosen(CustomerCenterEvent.CreationData(),
let event = CustomerCenterSurveyOptionChosenEvent.surveyOptionChosen(CustomerCenterEventCreationData(),
surveyOptionData)
purchasesProvider.track(customerCenterEvent: event)
}
Expand Down
140 changes: 82 additions & 58 deletions Sources/CustomerCenter/Events/CustomerCenterEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,88 +25,102 @@ public protocol CustomerCenterEventType {

associatedtype EventData

var creationData: CustomerCenterEvent.CreationData { get }
var creationData: CustomerCenterEventCreationData { get }
var data: EventData { get }

}

extension CustomerCenterEvent: CustomerCenterEventType {
public typealias EventData = Data
extension CustomerCenterEventType {

var feature: Feature { .customerCenter }

}
extension CustomerCenterSurveyOptionChosenEvent: CustomerCenterEventType {
public typealias EventData = Data

public struct CustomerCenterEventCreationData {

public var id: UUID
public var date: Date

public init(
id: UUID = .init(),
date: Date = .init()
) {
self.id = id
self.date = date
}

}

public struct CustomerCenterBaseData {

public var localeIdentifier: String
public var darkMode: Bool
public var isSandbox: Bool
public var displayMode: CustomerCenterPresentationMode

public init(
locale: Locale,
darkMode: Bool,
isSandbox: Bool,
displayMode: CustomerCenterPresentationMode
) {
self.localeIdentifier = locale.identifier
self.darkMode = darkMode
self.isSandbox = isSandbox
self.displayMode = displayMode
}

}

/// An event to be sent by the `RevenueCatUI` SDK.
public enum CustomerCenterEvent: FeatureEvent {
public enum CustomerCenterEvent: FeatureEvent, CustomerCenterEventType {

// swiftlint:disable type_name

var feature: Feature {
return .customerCenter
}

var eventDiscriminator: String? { "impression" }

/// The Customer Center was displayed.
case impression(CreationData, Data)
case impression(CustomerCenterEventCreationData, Data)

}

/// An event to be sent by the `RevenueCatUI` SDK.
public enum CustomerCenterSurveyOptionChosenEvent: FeatureEvent {
public enum CustomerCenterSurveyOptionChosenEvent: FeatureEvent, CustomerCenterEventType {

// swiftlint:disable type_name

var feature: Feature {
return .customerCenter
}

var eventDiscriminator: String? { "survey_option_chosen" }

/// A feedback survey was completed with a particular option.
case surveyOptionChosen(CreationData, Data)
case surveyOptionChosen(CustomerCenterEventCreationData, Data)

}

extension CustomerCenterEvent {

/// The creation data of a ``CustomerCenterEvent``.
public struct CreationData {

// swiftlint:disable missing_docs
public var id: ID
public var date: Date

public init(
id: ID = .init(),
date: Date = .init()
) {
self.id = id
self.date = date
}

}

/// The content of a ``CustomerCenterEvent``.
public struct Data {

public let base: CustomerCenterBaseData

// swiftlint:disable missing_docs
public var localeIdentifier: String
public var darkMode: Bool
public var isSandbox: Bool
public var displayMode: CustomerCenterPresentationMode
public var localeIdentifier: String { base.localeIdentifier }
public var darkMode: Bool { base.darkMode }
public var isSandbox: Bool { base.isSandbox }
public var displayMode: CustomerCenterPresentationMode { base.displayMode }

public init(
locale: Locale,
darkMode: Bool,
isSandbox: Bool,
displayMode: CustomerCenterPresentationMode
) {
self.localeIdentifier = locale.identifier
self.darkMode = darkMode
self.isSandbox = isSandbox
self.displayMode = displayMode
self.base = CustomerCenterBaseData(
locale: locale,
darkMode: darkMode,
isSandbox: isSandbox,
displayMode: displayMode
)
}
// swiftlint:enable missing_docs

Expand All @@ -116,14 +130,13 @@ extension CustomerCenterEvent {

extension CustomerCenterSurveyOptionChosenEvent {

public typealias CreationData = CustomerCenterEvent.CreationData

public struct Data {

public var localeIdentifier: String
public var darkMode: Bool
public var isSandbox: Bool
public var displayMode: CustomerCenterPresentationMode
private let base: CustomerCenterBaseData
public var localeIdentifier: String { base.localeIdentifier }
public var darkMode: Bool { base.darkMode }
public var isSandbox: Bool { base.isSandbox }
public var displayMode: CustomerCenterPresentationMode { base.displayMode }
public var pathID: String
public var surveyOptionID: String
public var surveyOptionTitleKey: String
Expand All @@ -141,10 +154,12 @@ extension CustomerCenterSurveyOptionChosenEvent {
additionalContext: String? = nil,
revisionID: Int
) {
self.localeIdentifier = locale.identifier
self.darkMode = darkMode
self.isSandbox = isSandbox
self.displayMode = displayMode
self.base = CustomerCenterBaseData(
locale: locale,
darkMode: darkMode,
isSandbox: isSandbox,
displayMode: displayMode
)
self.pathID = pathID
self.surveyOptionID = surveyOptionID
self.surveyOptionTitleKey = surveyOptionTitleKey
Expand All @@ -158,8 +173,8 @@ extension CustomerCenterSurveyOptionChosenEvent {

extension CustomerCenterEvent {

/// - Returns: the underlying ``CustomerCenterEvent/CreationData-swift.struct`` for this event.
public var creationData: CreationData {
/// - Returns: the underlying ``CustomerCenterEventCreationData-swift.struct`` for this event.
public var creationData: CustomerCenterEventCreationData {
switch self {
case let .impression(creationData, _): return creationData
}
Expand All @@ -176,8 +191,8 @@ extension CustomerCenterEvent {

extension CustomerCenterSurveyOptionChosenEvent {

/// - Returns: the underlying ``CustomerCenterSurveyOptionChosenEvent/CreationData-swift.struct`` for this event.
public var creationData: CreationData {
/// - Returns: the underlying ``CustomerCenterEventCreationData-swift.struct`` for this event.
public var creationData: CustomerCenterEventCreationData {
switch self {
case let .surveyOptionChosen(creationData, _): return creationData
}
Expand All @@ -194,18 +209,27 @@ extension CustomerCenterSurveyOptionChosenEvent {

// MARK: -

extension CustomerCenterEvent.CreationData: Equatable, Codable, Sendable {}
extension CustomerCenterEventCreationData: Equatable, Codable, Sendable {}
extension CustomerCenterEvent.Data: Equatable, Codable, Sendable {}
extension CustomerCenterEvent: Equatable, Codable, Sendable {}

extension CustomerCenterSurveyOptionChosenEvent.Data: Equatable, Codable, Sendable {
extension CustomerCenterBaseData: Equatable, Codable, Sendable {

private enum CodingKeys: String, CodingKey {

case localeIdentifier = "localeIdentifier"
case darkMode = "darkMode"
case isSandbox = "isSandbox"
case displayMode = "displayMode"
}

}

extension CustomerCenterSurveyOptionChosenEvent.Data: Equatable, Codable, Sendable {

private enum CodingKeys: String, CodingKey {

case base
case pathID = "pathId"
case surveyOptionID = "surveyOptionId"
case surveyOptionTitleKey = "surveyOptionTitleKey"
Expand Down

0 comments on commit c2bf7c5

Please sign in to comment.