From 427502b2be7c5bc4996a3e34455d1a89c757fbc8 Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Mon, 15 Jul 2024 16:25:55 -0400 Subject: [PATCH] filter unused features to avoid breaking change --- .../urbanairship/reactnative/AirshipModule.kt | 8 +++--- .../com/urbanairship/reactnative/Utils.kt | 25 +++++++++++++++++++ ios/AirshipReactNative.swift | 5 +++- src/types.ts | 6 +++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt index 1432ed94..b3d8e8f1 100644 --- a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt +++ b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt @@ -479,7 +479,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) : override fun privacyManagerSetEnabledFeatures(features: ReadableArray?, promise: Promise) { promise.resolveResult { proxy.privacyManager.setEnabledFeatures( - Utils.convertArray(requireNotNull(features)) + Utils.convertFeaturesArray(requireNotNull(features)) ) } } @@ -495,7 +495,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) : override fun privacyManagerEnableFeature(features: ReadableArray?, promise: Promise) { promise.resolveResult { proxy.privacyManager.enableFeatures( - Utils.convertArray(requireNotNull(features)) + Utils.convertFeaturesArray(requireNotNull(features)) ) } } @@ -504,7 +504,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) : override fun privacyManagerDisableFeature(features: ReadableArray?, promise: Promise) { promise.resolveResult { proxy.privacyManager.disableFeatures( - Utils.convertArray(requireNotNull(features)) + Utils.convertFeaturesArray(requireNotNull(features)) ) } } @@ -513,7 +513,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) : override fun privacyManagerIsFeatureEnabled(features: ReadableArray?, promise: Promise) { promise.resolveResult { proxy.privacyManager.isFeatureEnabled( - Utils.convertArray(requireNotNull(features)) + Utils.convertFeaturesArray(requireNotNull(features)) ) } } diff --git a/android/src/main/java/com/urbanairship/reactnative/Utils.kt b/android/src/main/java/com/urbanairship/reactnative/Utils.kt index d4ea6da2..1e3bdcf2 100644 --- a/android/src/main/java/com/urbanairship/reactnative/Utils.kt +++ b/android/src/main/java/com/urbanairship/reactnative/Utils.kt @@ -44,6 +44,31 @@ object Utils { } } + /** + * Converts features array into a JsonValue. + * This is filtering Chat and Location features until we remove them. + * To be removed in the version 20.0.0. + */ + fun convertFeaturesArray(array: ReadableArray?): JsonValue { + return if (array == null) { + JsonValue.NULL + } else { + val jsonValues: MutableList = ArrayList() + var i = 0 + while (i < array.size()) { + val value = convertDynamic(array.getDynamic(i)) + // Filter the unused features. + if (value == "chat" || value == "location") { + i++ + continue + } + jsonValues.add(value) + i++ + } + JsonValue.wrapOpt(jsonValues) + } + } + /** * Converts a dynamic object into a [JsonValue]. * diff --git a/ios/AirshipReactNative.swift b/ios/AirshipReactNative.swift index d4830a06..6f979cdd 100644 --- a/ios/AirshipReactNative.swift +++ b/ios/AirshipReactNative.swift @@ -552,7 +552,10 @@ public extension AirshipReactNative { @objc func privacyManagerDisableFeature(features: [String]) throws { - try AirshipProxy.shared.privacyManager.disable(featureNames: features) + let filteredFeatures = features.filter { feature in + return feature != "chat" && feature != "location" + } + try AirshipProxy.shared.privacyManager.disable(featureNames: filteredFeatures) } @objc diff --git a/src/types.ts b/src/types.ts index 9df762d0..3499034f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -540,10 +540,12 @@ export enum Feature { InAppAutomation = 'in_app_automation', MessageCenter = 'message_center', Push = 'push', - FeatureFlags = 'feature_flags', Analytics = 'analytics', TagsAndAttributes = 'tags_and_attributes', - Contacts = 'contacts' + Contacts = 'contacts', + FeatureFlags = 'feature_flags', + Location = 'location', // No longer used. To be removed in version 20.0.0. + Chat = 'chat', // No longer used. To be removed in version 20.0.0. } /**