diff --git a/pubnub-core/pubnub-core-api/src/commonMain/kotlin/com/pubnub/api/utils/PatchValue.kt b/pubnub-core/pubnub-core-api/src/commonMain/kotlin/com/pubnub/api/utils/PatchValue.kt index c60d7b801..38c7acc88 100644 --- a/pubnub-core/pubnub-core-api/src/commonMain/kotlin/com/pubnub/api/utils/PatchValue.kt +++ b/pubnub-core/pubnub-core-api/src/commonMain/kotlin/com/pubnub/api/utils/PatchValue.kt @@ -1,4 +1,5 @@ package com.pubnub.api.utils +import kotlin.jvm.JvmStatic /** * An optional that accepts nullable values. Thus, it can represent two (`PatchValue`) or three (`PatchValue?`) states: diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/PubNubImpl.kt b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/PubNubImpl.kt index aa16c8406..074b29045 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/PubNubImpl.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/PubNubImpl.kt @@ -201,7 +201,7 @@ class PubNubImpl(private val pubNubObjC: PubNubObjC) : PubNub { } // TODO: usePost parameter is not present in Swift SDK - override fun fire(channel: String, message: Any, meta: Any?, usePost: Boolean, ttl: Int?): Publish { + override fun fire(channel: String, message: Any, meta: Any?, usePost: Boolean): Publish { return PublishImpl( pubnub = pubNubObjC, channel = channel, diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/GetChannelMetadata.ios.kt b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/GetChannelMetadata.ios.kt index cd80a1b52..9a07c32d4 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/GetChannelMetadata.ios.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/GetChannelMetadata.ios.kt @@ -29,7 +29,7 @@ class GetChannelMetadataImpl( onSuccess = callback.onSuccessHandler { PNChannelMetadataResult( status = 200, - data = it?.let { rawValue -> createPNChannelMetadata(from = rawValue) } + data = createPNChannelMetadata(it) ) }, onFailure = callback.onFailureHandler() diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/SetChannelMetadata.ios.kt b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/SetChannelMetadata.ios.kt index 6177d3515..a041e47fd 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/SetChannelMetadata.ios.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/channel/SetChannelMetadata.ios.kt @@ -41,7 +41,7 @@ class SetChannelMetadataImpl( onSuccess = callback.onSuccessHandler { PNChannelMetadataResult( status = 200, - data = it?.let { rawValue -> createPNChannelMetadata(from = rawValue) } + data = createPNChannelMetadata(it) ) }, onFailure = callback.onFailureHandler() diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/GetUUIDMetadata.ios.kt b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/GetUUIDMetadata.ios.kt index b32946178..b1f358303 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/GetUUIDMetadata.ios.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/GetUUIDMetadata.ios.kt @@ -29,7 +29,7 @@ class GetUUIDMetadataImpl( onSuccess = callback.onSuccessHandler { PNUUIDMetadataResult( status = 200, - data = it?.let { createPNUUIDMetadata(from = it) } + data = createPNUUIDMetadata(it) ) }, onFailure = callback.onFailureHandler() diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/SetUUIDMetadata.ios.kt b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/SetUUIDMetadata.ios.kt index d61123679..e64a18747 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/SetUUIDMetadata.ios.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/api/endpoints/objects/uuid/SetUUIDMetadata.ios.kt @@ -45,7 +45,7 @@ class SetUUIDMetadataImpl( onSuccess = callback.onSuccessHandler { PNUUIDMetadataResult( status = 200, - data = it?.let { createPNUUIDMetadata(from = it) } + data = createPNUUIDMetadata(it) ) }, onFailure = callback.onFailureHandler() diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/converters.kt b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/converters.kt index a4b069d55..d19491906 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/converters.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/converters.kt @@ -12,6 +12,7 @@ import com.pubnub.api.models.consumer.objects.channel.PNChannelMetadata import com.pubnub.api.models.consumer.objects.member.PNMember import com.pubnub.api.models.consumer.objects.membership.PNChannelMembership import com.pubnub.api.models.consumer.objects.uuid.PNUUIDMetadata +import com.pubnub.api.utils.PatchValue import kotlinx.cinterop.ExperimentalForeignApi import platform.Foundation.NSData import platform.Foundation.NSString @@ -39,33 +40,35 @@ internal fun createPubNubHashedPage(from: PNPage?): PubNubHashedPageObjC { ) } +// TODO: PatchValue should consider cases where there is no response for a given field @OptIn(ExperimentalForeignApi::class) -internal fun createPNUUIDMetadata(from: PubNubUUIDMetadataObjC): PNUUIDMetadata { +internal fun createPNUUIDMetadata(from: PubNubUUIDMetadataObjC?): PNUUIDMetadata { return PNUUIDMetadata( - id = from.id(), - name = from.name(), - externalId = from.externalId(), - profileUrl = from.profileUrl(), - email = from.email(), - custom = from.custom()?.safeCast(), - updated = from.updated(), - eTag = from.eTag(), - type = from.type(), - status = from.status() + id = from!!.id(), + name = PatchValue.of(from.name()), + externalId = PatchValue.of(from.externalId()), + profileUrl = PatchValue.of(from.profileUrl()), + email = PatchValue.of(from.email()), + custom = PatchValue.of(from.custom()?.safeCast()), + updated = PatchValue.of(from.updated().orEmpty()), + eTag = PatchValue.of(from.eTag().orEmpty()), + type = PatchValue.of(from.type()), + status = PatchValue.of(from.status()) ) } +// TODO: PatchValue should consider cases where there is no response for a given field @OptIn(ExperimentalForeignApi::class) -internal fun createPNChannelMetadata(from: PubNubChannelMetadataObjC): PNChannelMetadata { +internal fun createPNChannelMetadata(from: PubNubChannelMetadataObjC?): PNChannelMetadata { return PNChannelMetadata( - id = from.id(), - name = from.name(), - description = from.descr(), - custom = from.custom()?.safeCast(), - updated = from.updated(), - eTag = from.eTag(), - type = from.type(), - status = from.status() + id = from!!.id(), + name = PatchValue.of(from.name()), + description = PatchValue.of(from.descr()), + custom = PatchValue.of(from.custom()?.safeCast()), + updated = PatchValue.of(from.updated().orEmpty()), + eTag = PatchValue.of(from.eTag().orEmpty()), + type = PatchValue.of(from.type()), + status = PatchValue.of(from.status()) ) } @@ -79,34 +82,36 @@ internal fun createObjectSortProperties(from: Collection>): Lis } } +// TODO: PatchValue should consider cases where there is no response for a given field @OptIn(ExperimentalForeignApi::class) internal fun createPNChannelMembership(from: PubNubMembershipMetadataObjC): PNChannelMembership { return PNChannelMembership( channel = PNChannelMetadata( id = from.channelMetadataId(), - name = from.channel()?.name(), - description = from.channel()?.descr(), - custom = from.channel()?.custom()?.safeCast(), - updated = from.channel()?.updated(), - eTag = from.channel()?.eTag(), - type = from.channel()?.type(), - status = from.channel()?.status() + name = PatchValue.of(from.channel()?.name()), + description = PatchValue.of(from.channel()?.descr()), + custom = PatchValue.of(from.channel()?.custom()?.safeCast()), + updated = PatchValue.of(from.channel()?.updated().orEmpty()), + eTag = PatchValue.of(from.channel()?.eTag().orEmpty()), + type = PatchValue.of(from.channel()?.type()), + status = PatchValue.of(from.channel()?.status()) ), - custom = from.custom()?.safeCast(), + custom = PatchValue.of(from.custom()?.safeCast()), updated = from.updated().orEmpty(), eTag = from.eTag().orEmpty(), - status = from.status() + status = PatchValue.of(from.status()) ) } +// TODO: PatchValue should consider cases where there is no response for a given field @OptIn(ExperimentalForeignApi::class) -internal fun createPNMember(from: PubNubMembershipMetadataObjC): PNMember { +internal fun createPNMember(from: PubNubMembershipMetadataObjC?): PNMember { return PNMember( - uuid = from.uuid()?.let { createPNUUIDMetadata(from = it) }, - custom = from.custom()?.safeCast(), + uuid = createPNUUIDMetadata(from = from!!.uuid()), + custom = PatchValue.of(from.custom()?.safeCast()), updated = from.updated().orEmpty(), eTag = from.eTag().orEmpty(), - status = from.status() + status = PatchValue.of(from.status()) ) } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/factories.ios.kt b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/factories.ios.kt index 5a41efe23..10b5ae134 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/factories.ios.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/iosMain/kotlin/com/pubnub/kmp/factories.ios.kt @@ -47,6 +47,7 @@ import com.pubnub.api.models.consumer.pubsub.objects.PNSetChannelMetadataEventMe import com.pubnub.api.models.consumer.pubsub.objects.PNSetMembershipEvent import com.pubnub.api.models.consumer.pubsub.objects.PNSetMembershipEventMessage import com.pubnub.api.models.consumer.pubsub.objects.PNSetUUIDMetadataEventMessage +import com.pubnub.api.utils.PatchValue import com.pubnub.api.v2.PNConfiguration import com.pubnub.api.v2.callbacks.EventListener import com.pubnub.api.v2.callbacks.EventListenerImpl @@ -192,6 +193,7 @@ private fun createObjectEvent(from: PubNubAppContextEventObjC?): PNObjectEventRe } } +// TODO: PatchValue should consider cases where there is no response for a given field @OptIn(ExperimentalForeignApi::class) private fun mapAppContextEvent(from: PubNubAppContextEventObjC?): PNObjectEventMessage? { when (from) { @@ -203,15 +205,15 @@ private fun mapAppContextEvent(from: PubNubAppContextEventObjC?): PNObjectEventM type = from.type(), data = PNUUIDMetadata( id = from.metadata().id(), - name = from.metadata().name(), - externalId = from.metadata().externalId(), - profileUrl = from.metadata().profileUrl(), - email = from.metadata().email(), - custom = from.metadata().custom()?.safeCast(), - updated = from.metadata().updated(), - eTag = from.metadata().eTag(), - type = from.metadata().type(), - status = from.metadata().status() + name = PatchValue.of(from.metadata().name()), + externalId = PatchValue.of(from.metadata().externalId()), + profileUrl = PatchValue.of(from.metadata().profileUrl()), + email = PatchValue.of(from.metadata().email()), + custom = PatchValue.of(from.metadata().custom()?.safeCast()), + updated = PatchValue.of(from.metadata().updated().orEmpty()), + eTag = PatchValue.of(from.metadata().eTag().orEmpty()), + type = PatchValue.of(from.metadata().type()), + status = PatchValue.of(from.metadata().status()) ) ) is PubNubRemoveUUIDMetadataResultObjC -> @@ -230,13 +232,13 @@ private fun mapAppContextEvent(from: PubNubAppContextEventObjC?): PNObjectEventM type = from.type(), data = PNChannelMetadata( id = from.metadata().id(), - name = from.metadata().name(), - description = from.metadata().descr(), - custom = from.metadata().custom()?.safeCast(), - updated = from.metadata().updated(), - eTag = from.metadata().eTag(), - type = from.metadata().type(), - status = from.metadata().status() + name = PatchValue.of(from.metadata().name()), + description = PatchValue.of(from.metadata().descr()), + custom = PatchValue.of(from.metadata().custom()?.safeCast()), + updated = PatchValue.of(from.metadata().updated().orEmpty()), + eTag = PatchValue.of(from.metadata().eTag().orEmpty()), + type = PatchValue.of(from.metadata().type()), + status = PatchValue.of(from.metadata().status()) ) ) is PubNubRemoveChannelMetadataResultObjC -> @@ -256,10 +258,10 @@ private fun mapAppContextEvent(from: PubNubAppContextEventObjC?): PNObjectEventM data = PNSetMembershipEvent( channel = from.metadata().channelMetadataId(), uuid = from.metadata().uuidMetadataId(), - custom = from.metadata().custom()?.safeCast(), + custom = PatchValue.of(from.metadata().custom()?.safeCast()), eTag = from.metadata().eTag().orEmpty(), updated = from.metadata().updated().orEmpty(), - status = from.metadata().status().orEmpty() + status = PatchValue.of(from.metadata().status().orEmpty()) ) ) is PubNubRemoveMembershipResultObjC -> diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt b/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt index 12e29a987..f6e54ec7b 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt @@ -98,8 +98,7 @@ actual interface PubNub { channel: String, message: Any, meta: Any?, - usePost: Boolean, - ttl: Int? + usePost: Boolean ): Publish actual fun signal(channel: String, message: Any): Signal diff --git a/pubnub-kotlin/pubnub-kotlin-test/src/commonMain/kotlin/com.pubnub.test/FakePubNub.kt b/pubnub-kotlin/pubnub-kotlin-test/src/commonMain/kotlin/com.pubnub.test/FakePubNub.kt index 035902256..7f7831328 100644 --- a/pubnub-kotlin/pubnub-kotlin-test/src/commonMain/kotlin/com.pubnub.test/FakePubNub.kt +++ b/pubnub-kotlin/pubnub-kotlin-test/src/commonMain/kotlin/com.pubnub.test/FakePubNub.kt @@ -105,7 +105,7 @@ abstract class FakePubNub( TODO("Not yet implemented") } - override fun fire(channel: String, message: Any, meta: Any?, usePost: Boolean, ttl: Int?): Publish { + override fun fire(channel: String, message: Any, meta: Any?, usePost: Boolean): Publish { TODO("Not yet implemented") } diff --git a/swift b/swift index d8c940837..f1dd87e0a 160000 --- a/swift +++ b/swift @@ -1 +1 @@ -Subproject commit d8c940837704e4718e729f969b568efa4348690d +Subproject commit f1dd87e0af69b2a7b7195b41f9f0077152101fa0