Skip to content

Commit

Permalink
Added missing implementations for iOS target (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub authored Aug 13, 2024
1 parent 6919320 commit 22a7566
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -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<T>`) or three (`PatchValue<T>?`) states:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GetUUIDMetadataImpl(
onSuccess = callback.onSuccessHandler {
PNUUIDMetadataResult(
status = 200,
data = it?.let { createPNUUIDMetadata(from = it) }
data = createPNUUIDMetadata(it)
)
},
onFailure = callback.onFailureHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SetUUIDMetadataImpl(
onSuccess = callback.onSuccessHandler {
PNUUIDMetadataResult(
status = 200,
data = it?.let { createPNUUIDMetadata(from = it) }
data = createPNUUIDMetadata(it)
)
},
onFailure = callback.onFailureHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
)
}

Expand All @@ -79,34 +82,36 @@ internal fun createObjectSortProperties(from: Collection<PNSortKey<PNKey>>): 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())
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 ->
Expand All @@ -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 ->
Expand All @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 22a7566

Please sign in to comment.