@@ -47,6 +47,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
4747 var bundleCommerceEvents = false
4848 var isMpidIdentityType = false
4949 var identityType: IdentityType ? = null
50+ var subscriptionGroupIds: MutableMap <String , String >? = mutableMapOf ()
5051 private val dataFlushHandler = Handler ()
5152 private var dataFlushRunnable: Runnable ? = null
5253 private var forwardScreenViews = false
@@ -85,6 +86,9 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
8586 }
8687 }
8788 forwardScreenViews = settings[FORWARD_SCREEN_VIEWS ].toBoolean()
89+ subscriptionGroupIds = settings[SUBSCRIPTION_GROUP_MAPPING ]?.let {
90+ getSubscriptionGroupIds(it)
91+ }
8892 if (key != null ) {
8993 val config = BrazeConfig .Builder ().setApiKey(key)
9094 .setSdkFlavor(SdkFlavor .MPARTICLE )
@@ -318,10 +322,27 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
318322 else value.setGender(Gender .MALE )
319323 }
320324 else -> {
321- if (key.startsWith(" $" )) {
322- key = key.substring(1 )
325+ if (subscriptionGroupIds?.containsKey(key) == true ) {
326+ if (attributeValue == " true" ) {
327+ value.addToSubscriptionGroup(
328+ subscriptionGroupIds?.get(key).toString()
329+ )
330+ } else if (attributeValue == " false" ) {
331+ value.removeFromSubscriptionGroup(
332+ subscriptionGroupIds?.get(key).toString()
333+ )
334+ } else {
335+ Logger .warning(
336+ " unable to set Subscription Group ID for user attribute: "
337+ + key + " due to invalid value data type. expected value data type should be Boolean"
338+ )
339+ }
340+ } else {
341+ if (key.startsWith(" $" )) {
342+ key = key.substring(1 )
343+ }
344+ userAttributeSetter?.parseValue(key, attributeValue)
323345 }
324- userAttributeSetter?.parseValue(key, attributeValue)
325346 }
326347 }
327348 queueDataFlush()
@@ -966,6 +987,24 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
966987 return promotionArray
967988 }
968989
990+ private fun getSubscriptionGroupIds (subscriptionGroupMap : String ): MutableMap <String , String > {
991+ val subscriptionGroupsArray = JSONArray (subscriptionGroupMap)
992+ val subscriptionGroupIds = mutableMapOf<String , String >()
993+
994+ if (subscriptionGroupMap.isEmpty()) {
995+ return subscriptionGroupIds
996+ }
997+
998+ for (i in 0 until subscriptionGroupsArray.length()) {
999+ val subscriptionGroup = subscriptionGroupsArray.getJSONObject(i)
1000+ val key = subscriptionGroup.getString(" map" )
1001+ val value = subscriptionGroup.getString(" value" )
1002+ subscriptionGroupIds[key] = value
1003+ }
1004+
1005+ return subscriptionGroupIds
1006+ }
1007+
9691008 fun getImpressionListParameters (impressionList : List <Impression >): JSONArray {
9701009 val impressionArray = JSONArray ()
9711010 for ((i, impression) in impressionList.withIndex()) {
@@ -1083,6 +1122,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
10831122 const val USER_IDENTIFICATION_TYPE = " userIdentificationType"
10841123 const val ENABLE_TYPE_DETECTION = " enableTypeDetection"
10851124 const val BUNDLE_COMMERCE_EVENTS = " bundleCommerceEventData"
1125+ const val SUBSCRIPTION_GROUP_MAPPING = " subscriptionGroupMapping"
10861126 const val HOST = " host"
10871127 const val PUSH_ENABLED = " push_enabled"
10881128 const val NAME = " Appboy"
0 commit comments