Skip to content

Commit

Permalink
Opening access to arrow Core. Adding ChannelTypePreferenceItem conven…
Browse files Browse the repository at this point in the history
…ience class
  • Loading branch information
matgar26 committed Mar 5, 2024
1 parent 03c73fa commit 72455b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation ("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2")

// Arrow
implementation("io.arrow-kt:arrow-core:1.2.0")
api("io.arrow-kt:arrow-core:1.2.0")
implementation("io.arrow-kt:arrow-fx-coroutines:1.2.0")
implementation("io.arrow-kt:arrow-integrations-jackson-module:0.14.1")
}
31 changes: 23 additions & 8 deletions sdk/src/main/java/app/knock/client/KnockPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.knock.client
import arrow.core.Either
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.Nulls
import com.fasterxml.jackson.core.JsonGenerator
Expand All @@ -15,14 +16,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize


//enum class ChannelTypeKey {
// @JsonProperty("email") EMAIL,
// @JsonProperty("in_app_feed") IN_APP_FEED,
// @JsonProperty("sms") SMS,
// @JsonProperty("push") PUSH,
// @JsonProperty("chat") CHAT,
//}

@JsonIgnoreProperties(ignoreUnknown = true)
data class Condition(
val variable: String,
Expand Down Expand Up @@ -88,7 +81,29 @@ data class ChannelTypePreferences(
@JsonSerialize(using = BooleanOrConditionsArraySerializer::class)
@JsonIgnoreProperties(ignoreUnknown = true)
var chat: Either<Boolean, ConditionsArray>? = null,
) {
fun asArrayOfPreferenceItems(): List<ChannelTypePreferenceItem> {
return listOfNotNull(
email?.let { ChannelTypePreferenceItem(ChannelTypeKey.EMAIL, it) },
inAppFeed?.let { ChannelTypePreferenceItem(ChannelTypeKey.IN_APP_FEED, it) },
sms?.let { ChannelTypePreferenceItem(ChannelTypeKey.SMS, it) },
push?.let { ChannelTypePreferenceItem(ChannelTypeKey.PUSH, it) },
chat?.let { ChannelTypePreferenceItem(ChannelTypeKey.CHAT, it) }
)
}
}

data class ChannelTypePreferenceItem(
val id: ChannelTypeKey,
var value: Either<Boolean, ConditionsArray>
)
enum class ChannelTypeKey {
@JsonProperty("email") EMAIL,
@JsonProperty("in_app_feed") IN_APP_FEED,
@JsonProperty("sms") SMS,
@JsonProperty("push") PUSH,
@JsonProperty("chat") CHAT,
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class WorkflowPreference(
Expand Down

0 comments on commit 72455b8

Please sign in to comment.