From 0b1c307ddb9a7df07d8d95d63df59cfbb1c7691e Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 14 Sep 2023 16:08:30 +0200 Subject: [PATCH] add more comments and TODOs --- .../src/main/java/com/posthog/PostHog.kt | 27 +++++++++++++++++-- .../main/java/com/posthog/PostHogConfig.kt | 1 + .../posthog/internal/PostHogFeatureFlags.kt | 4 ++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/posthog-v3/posthog/src/main/java/com/posthog/PostHog.kt b/posthog-v3/posthog/src/main/java/com/posthog/PostHog.kt index f916aa8e..a7b8fccc 100644 --- a/posthog-v3/posthog/src/main/java/com/posthog/PostHog.kt +++ b/posthog-v3/posthog/src/main/java/com/posthog/PostHog.kt @@ -154,6 +154,12 @@ public class PostHog { capture("\$identify", properties = props) } + public fun group(type: String, key: String, properties: Map? = null) { + if (!isEnabled()) { + return + } + } + public fun reloadFeatureFlagsRequest() { if (!isEnabled()) { return @@ -163,7 +169,7 @@ public class PostHog { private fun loadFeatureFlagsRequest() { val map = mapOf() - featureFlags?.loadFeatureFlagsRequest(buildProperties(map)) + featureFlags?.loadFeatureFlags(buildProperties(map)) } public fun isFeatureEnabled(key: String, defaultValue: Boolean = false): Boolean { @@ -173,11 +179,17 @@ public class PostHog { return featureFlags?.isFeatureEnabled(key, defaultValue) ?: defaultValue } + // TODO: getFeatureFlagPayload + public fun getFeatureFlag(key: String, defaultValue: Any? = null): Any? { if (!isEnabled()) { return defaultValue } - return featureFlags?.getFeatureFlag(key, defaultValue) ?: defaultValue + val flag = featureFlags?.getFeatureFlag(key, defaultValue) ?: defaultValue + + // TODO: reportFeatureFlagCalled + + return flag } public fun flush() { @@ -187,6 +199,13 @@ public class PostHog { queue?.flush() } + public fun reset() { + if (!isEnabled()) { + return + } + // TODO: reset stuff, delete cache + } + // TODO: groups, groupIdentify, group, feature flags, buildProperties (static context, dynamic context, distinct_id) private fun isEnabled(): Boolean { @@ -234,6 +253,10 @@ public class PostHog { shared.flush() } + public fun reset() { + shared.reset() + } + // TODO: add other methods } } diff --git a/posthog-v3/posthog/src/main/java/com/posthog/PostHogConfig.kt b/posthog-v3/posthog/src/main/java/com/posthog/PostHogConfig.kt index ffae179a..50cd1593 100644 --- a/posthog-v3/posthog/src/main/java/com/posthog/PostHogConfig.kt +++ b/posthog-v3/posthog/src/main/java/com/posthog/PostHogConfig.kt @@ -12,6 +12,7 @@ public class PostHogConfig( public var maxBatchSize: Int = 10, // (30).toDuration(DurationUnit.SECONDS) requires Kotlin 1.6 public var flushIntervalSeconds: Int = 30, + public var dataMode: PostHogDataMode = PostHogDataMode.ANY, ) { internal var logger: PostHogLogger? = null diff --git a/posthog-v3/posthog/src/main/java/com/posthog/internal/PostHogFeatureFlags.kt b/posthog-v3/posthog/src/main/java/com/posthog/internal/PostHogFeatureFlags.kt index e3f57eab..5d5da5a8 100644 --- a/posthog-v3/posthog/src/main/java/com/posthog/internal/PostHogFeatureFlags.kt +++ b/posthog-v3/posthog/src/main/java/com/posthog/internal/PostHogFeatureFlags.kt @@ -16,7 +16,7 @@ internal class PostHogFeatureFlags(private val config: PostHogConfig, private va @Volatile private var isFeatureFlagsLoaded = false - fun loadFeatureFlagsRequest(properties: Map) { + fun loadFeatureFlags(properties: Map) { executor.execute { if (isLoadingFeatureFlags.getAndSet(true)) { config.logger?.log("Feature flags are being loaded already.") @@ -32,6 +32,7 @@ internal class PostHogFeatureFlags(private val config: PostHogConfig, private va isFeatureFlagsLoaded = true } catch (e: Throwable) { + isFeatureFlagsLoaded = false config.logger?.log("Loading feature flags failed: $e") } @@ -46,6 +47,7 @@ internal class PostHogFeatureFlags(private val config: PostHogConfig, private va val value: Any? synchronized(featureFlagsLock) { + // TODO: read featureFlags and featureFlagPayloads only? value = featureFlags?.get(key) }