Skip to content

Commit

Permalink
chore: make storage manager public to the rn sdk (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Sep 24, 2024
1 parent 0e74908 commit 501cc8e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- no user facing changes

## 3.12.4 - 2024-09-19

- no user facing changes
Expand Down
2 changes: 2 additions & 0 deletions PostHog/PostHogConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import Foundation
// only internal
var disableReachabilityForTesting: Bool = false
var disableQueueTimerForTesting: Bool = false
// internal
public var storageManager: PostHogStorageManager?

@objc(apiKey:)
public init(
Expand Down
25 changes: 12 additions & 13 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ let maxRetryDelay = 30.0
private var replayQueue: PostHogQueue?
private var api: PostHogApi?
private var storage: PostHogStorage?
private var storageManager: PostHogStorageManager?
#if !os(watchOS)
private var reachability: Reachability?
#endif
Expand Down Expand Up @@ -99,7 +98,7 @@ let maxRetryDelay = 30.0
let theApi = PostHogApi(config)
api = theApi
featureFlags = PostHogFeatureFlags(config, theStorage, theApi)
storageManager = PostHogStorageManager(config)
config.storageManager = config.storageManager ?? PostHogStorageManager(config)
#if os(iOS)
replayIntegration = PostHogReplayIntegration(config)
#endif
Expand Down Expand Up @@ -159,15 +158,15 @@ let maxRetryDelay = 30.0
return ""
}

return storageManager?.getDistinctId() ?? ""
return config.storageManager?.getDistinctId() ?? ""
}

@objc public func getAnonymousId() -> String {
if !isEnabled() {
return ""
}

return storageManager?.getAnonymousId() ?? ""
return config.storageManager?.getAnonymousId() ?? ""
}

@objc public func getSessionId() -> String? {
Expand Down Expand Up @@ -244,8 +243,8 @@ let maxRetryDelay = 30.0
config.personProfiles == .never ||
(
config.personProfiles == .identifiedOnly &&
storageManager?.isIdentified() == false &&
storageManager?.isPersonProcessing() == false
config.storageManager?.isIdentified() == false &&
config.storageManager?.isPersonProcessing() == false
)
)
}
Expand All @@ -256,7 +255,7 @@ let maxRetryDelay = 30.0
hedgeLog("personProfiles is set to `never`. This call will be ignored.")
return false
}
storageManager?.setPersonProcessing(true)
config.storageManager?.setPersonProcessing(true)
return true
}

Expand Down Expand Up @@ -294,7 +293,7 @@ let maxRetryDelay = 30.0
props["$groups"] = mergedGroups
}

if let isIdentified = storageManager?.isIdentified() {
if let isIdentified = config.storageManager?.isIdentified() {
props["$is_identified"] = isIdentified
}

Expand Down Expand Up @@ -345,7 +344,7 @@ let maxRetryDelay = 30.0

// storage also removes all feature flags
storage?.reset()
storageManager?.reset()
config.storageManager?.reset()
flagCallReported.removeAll()
PostHogSessionManager.shared.endSession {
self.resetViews()
Expand Down Expand Up @@ -443,7 +442,7 @@ let maxRetryDelay = 30.0
return
}

guard let queue = queue, let storageManager = storageManager else {
guard let queue = queue, let storageManager = config.storageManager else {
return
}
let oldDistinctId = getDistinctId()
Expand Down Expand Up @@ -748,7 +747,7 @@ let maxRetryDelay = 30.0
return
}

guard let featureFlags = featureFlags, let storageManager = storageManager else {
guard let featureFlags = featureFlags, let storageManager = config.storageManager else {
return
}

Expand Down Expand Up @@ -885,8 +884,8 @@ let maxRetryDelay = 30.0
#endif
queue = nil
replayQueue = nil
storageManager?.reset()
storageManager = nil
config.storageManager?.reset()
config.storageManager = nil
config = PostHogConfig(apiKey: "")
api = nil
featureFlags = nil
Expand Down
3 changes: 2 additions & 1 deletion PostHog/PostHogStorageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import Foundation

class PostHogStorageManager {
// Internal class to manage the storage metadata of the PostHog SDK
public class PostHogStorageManager {
private let storage: PostHogStorage!

private let anonLock = NSLock()
Expand Down

0 comments on commit 501cc8e

Please sign in to comment.