Skip to content

Commit

Permalink
filter unused features to avoid breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrico972 committed Jul 15, 2024
1 parent 4e29ae3 commit 427502b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
}
}
Expand All @@ -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))
)
}
}
Expand All @@ -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))
)
}
}
Expand All @@ -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))
)
}
}
Expand Down
25 changes: 25 additions & 0 deletions android/src/main/java/com/urbanairship/reactnative/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonValue> = 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].
*
Expand Down
5 changes: 4 additions & 1 deletion ios/AirshipReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

/**
Expand Down

0 comments on commit 427502b

Please sign in to comment.