Skip to content

Commit

Permalink
Fixes according to swift module changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Sep 10, 2024
1 parent 0f11994 commit 39f6a37
Show file tree
Hide file tree
Showing 55 changed files with 299 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PubNubKotlinMultiplatformPlugin : Plugin<Project> {
// }
// version = "7.1.0"
source = path(rootProject.file(swiftPath))
moduleName = "PubNub"
moduleName = "PubNubSDK"
extraOpts += listOf("-compiler-option", "-fmodules")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.pubnub.api

import cocoapods.PubNubSwift.AnyJSONObjC
import cocoapods.PubNubSwift.KMPAnyJSON
import kotlinx.cinterop.ExperimentalForeignApi

actual abstract class JsonElement(val value: Any?) {
Expand Down Expand Up @@ -43,15 +43,15 @@ class JsonElementImpl(value: Any?) : JsonElement(value)

actual fun JsonElement.asString(): String? {
return when (value) {
is AnyJSONObjC -> value.asString()
is KMPAnyJSON -> value.asString()
is String -> value
else -> null
}
}

actual fun JsonElement.asMap(): Map<String, JsonElement>? {
return when (value) {
is AnyJSONObjC -> (value.asMap() as? Map<String, Any>)?.mapValues {
is KMPAnyJSON -> (value.asMap() as? Map<String, Any>)?.mapValues {
JsonElementImpl(it.value)
}
is Map<*, *> -> (value as Map<String, *>)?.mapValues { JsonElementImpl(it.value) }
Expand All @@ -60,12 +60,12 @@ actual fun JsonElement.asMap(): Map<String, JsonElement>? {
}

actual fun JsonElement.isNull(): Boolean {
return value == null || (value as? AnyJSONObjC)?.isNull() == true
return value == null || (value as? KMPAnyJSON)?.isNull() == true
}

actual fun JsonElement.asList(): List<JsonElement>? {
return when (value) {
is AnyJSONObjC -> value.asList()?.map {
is KMPAnyJSON -> value.asList()?.map {
JsonElementImpl(it)
}
is List<*> -> value.map { JsonElementImpl(it) }
Expand All @@ -75,7 +75,7 @@ actual fun JsonElement.asList(): List<JsonElement>? {

actual fun JsonElement.asLong(): Long? {
return when (value) {
is AnyJSONObjC -> value.asInt()?.longValue
is KMPAnyJSON -> value.asInt()?.longValue
is Long -> value
is Int -> value.toLong()
is Boolean -> if (value) {
Expand All @@ -89,15 +89,15 @@ actual fun JsonElement.asLong(): Long? {

actual fun JsonElement.asBoolean(): Boolean? {
return when (value) {
is AnyJSONObjC -> value.asBool()?.boolValue
is KMPAnyJSON -> value.asBool()?.boolValue
is Boolean -> value
else -> null
}
}

actual fun JsonElement.asDouble(): Double? {
return when (value) {
is AnyJSONObjC -> value.asDouble()?.doubleValue
is KMPAnyJSON -> value.asDouble()?.doubleValue
is Number -> value.toDouble()
is Boolean -> if (value) {
1.0
Expand All @@ -110,7 +110,7 @@ actual fun JsonElement.asDouble(): Double? {

actual fun JsonElement.asNumber(): Number? {
return when (value) {
is AnyJSONObjC -> value.asNumber() as? Number
is KMPAnyJSON -> value.asNumber() as? Number
is Number -> value
is Boolean -> if (value) {
1
Expand All @@ -122,5 +122,5 @@ actual fun JsonElement.asNumber(): Number? {
}

actual fun createJsonElement(any: Any?): JsonElement {
return JsonElementImpl(AnyJSONObjC(any))
return JsonElementImpl(KMPAnyJSON(any))
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.pubnub.api

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.PubNubSubscriptionObjC
import cocoapods.PubNubSwift.PubNubSubscriptionSetObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.KMPSubscription
import cocoapods.PubNubSwift.KMPSubscriptionSet
import cocoapods.PubNubSwift.addEventListenerWithListener
import cocoapods.PubNubSwift.addStatusListenerWithListener
import cocoapods.PubNubSwift.channelGroupWith
Expand Down Expand Up @@ -143,9 +143,9 @@ import com.pubnub.kmp.Uploadable
import kotlinx.cinterop.ExperimentalForeignApi

@OptIn(ExperimentalForeignApi::class)
class PubNubImpl(private val pubNubObjC: PubNubObjC) : PubNub {
class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub {
constructor(configuration: PNConfiguration) : this(
PubNubObjC(
KMPPubNub(
user = configuration.userId.value,
subKey = configuration.subscribeKey,
pubKey = configuration.publishKey
Expand Down Expand Up @@ -833,7 +833,7 @@ class PubNubImpl(private val pubNubObjC: PubNubObjC) : PubNub {

override fun subscriptionSetOf(subscriptions: Set<Subscription>): SubscriptionSet {
return SubscriptionSetImpl(
PubNubSubscriptionSetObjC(subscriptions.filterIsInstance<SubscriptionImpl>().map { it.objCSubscription })
KMPSubscriptionSet(subscriptions.filterIsInstance<SubscriptionImpl>().map { it.objCSubscription })
)
}

Expand All @@ -842,14 +842,14 @@ class PubNubImpl(private val pubNubObjC: PubNubObjC) : PubNub {
channelGroups: Set<String>,
options: SubscriptionOptions
): SubscriptionSet {
val channelSubscriptions = channels.map { pubNubObjC.channelWith(it) }.map { entity -> PubNubSubscriptionObjC(entity) }
val channelSubscriptions = channels.map { pubNubObjC.channelWith(it) }.map { entity -> KMPSubscription(entity) }
val channelGroupSubscriptions = channelGroups.map { pubNubObjC.channelGroupWith(it) }.map {
entity ->
PubNubSubscriptionObjC(entity)
KMPSubscription(entity)
}

return SubscriptionSetImpl(
PubNubSubscriptionSetObjC(channelGroupSubscriptions + channelSubscriptions)
KMPSubscriptionSet(channelGroupSubscriptions + channelSubscriptions)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.deleteMessagesFrom
import com.pubnub.api.models.consumer.history.PNDeleteMessagesResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -18,7 +18,7 @@ actual interface DeleteMessages : PNFuture<PNDeleteMessagesResult>

@OptIn(ExperimentalForeignApi::class)
class DeleteMessagesImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channels: List<String>,
private val start: Long?,
private val end: Long?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.pubnub.api.endpoints

import cocoapods.PubNubSwift.PubNubBoundedPageObjC
import cocoapods.PubNubSwift.PubNubMessageActionObjC
import cocoapods.PubNubSwift.PubNubMessageObjC
import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPBoundedPage
import cocoapods.PubNubSwift.KMPMessage
import cocoapods.PubNubSwift.KMPMessageAction
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.fetchMessagesFrom
import com.pubnub.api.JsonElementImpl
import com.pubnub.api.models.consumer.PNBoundedPage
Expand All @@ -26,7 +26,7 @@ actual interface FetchMessages : PNFuture<PNFetchMessagesResult>

@OptIn(ExperimentalForeignApi::class)
open class FetchMessagesImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channels: List<String>,
private val page: PNBoundedPage,
private val includeUUID: Boolean,
Expand All @@ -41,7 +41,7 @@ open class FetchMessagesImpl(
includeMeta = includeMeta,
includeMessageActions = includeMessageActions,
includeMessageType = includeMessageType,
page = PubNubBoundedPageObjC(
page = KMPBoundedPage(
start = page.start?.let { NSNumber(long = it) },
end = page.end?.let { NSNumber(long = it) },
limit = page.limit?.let { NSNumber(int = it) }
Expand All @@ -61,7 +61,7 @@ open class FetchMessagesImpl(
}

private fun mapMessages(rawValue: Map<Any?, *>?): Map<String, List<PNFetchMessageItem>> {
return (rawValue?.safeCast<String, List<PubNubMessageObjC>>())?.mapValues { entry ->
return (rawValue?.safeCast<String, List<KMPMessage>>())?.mapValues { entry ->
entry.value.map {
PNFetchMessageItem(
uuid = it.publisher(),
Expand All @@ -77,7 +77,7 @@ open class FetchMessagesImpl(
}

private fun mapMessageActions(rawValue: List<*>): Map<String, Map<String, List<PNFetchMessageItem.Action>>>? {
return rawValue.filterIsInstance<PubNubMessageActionObjC>().groupBy { messageAction ->
return rawValue.filterIsInstance<KMPMessageAction>().groupBy { messageAction ->
messageAction.actionType()
}.mapValues { entry ->
entry.value.groupBy { groupedMessageAction ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.messageCountsFor
import com.pubnub.api.models.consumer.history.PNMessageCountResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -18,7 +18,7 @@ actual interface MessageCounts : PNFuture<PNMessageCountResult>

@OptIn(ExperimentalForeignApi::class)
class MessageCountsImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channels: List<String>,
private val channelsTimetoken: List<Long>
) : MessageCounts {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.timeOnSuccess
import com.pubnub.api.models.consumer.PNTimeResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface Time : PNFuture<PNTimeResult>

@OptIn(ExperimentalForeignApi::class)
class TimeImpl(
private val pubnub: PubNubObjC
private val pubnub: KMPPubNub
) : Time {
override fun async(callback: Consumer<Result<PNTimeResult>>) {
pubnub.timeOnSuccess(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.channel_groups

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.addChannelsTo
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsAddChannelResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface AddChannelChannelGroup : PNFuture<PNChannelGroupsAddChannelResu

@OptIn(ExperimentalForeignApi::class)
class AddChannelChannelGroupImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channels: List<String>,
private val channelGroup: String
) : AddChannelChannelGroup {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.channel_groups

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.listChannelsFor
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsAllChannelsResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface AllChannelsChannelGroup : PNFuture<PNChannelGroupsAllChannelsRe

@OptIn(ExperimentalForeignApi::class)
class AllChannelsChannelGroupImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channelGroup: String
) : AllChannelsChannelGroup {
override fun async(callback: Consumer<Result<PNChannelGroupsAllChannelsResult>>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.channel_groups

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.deleteWithChannelGroup
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsDeleteGroupResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface DeleteChannelGroup : PNFuture<PNChannelGroupsDeleteGroupResult>

@OptIn(ExperimentalForeignApi::class)
class DeleteChannelGroupImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channelGroup: String
) : DeleteChannelGroup {
override fun async(callback: Consumer<Result<PNChannelGroupsDeleteGroupResult>>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.channel_groups

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.listChannelGroupsOnSuccess
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsListAllResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface ListAllChannelGroup : PNFuture<PNChannelGroupsListAllResult>

@OptIn(ExperimentalForeignApi::class)
class ListAllChannelGroupImpl(
private val pubnub: PubNubObjC
private val pubnub: KMPPubNub
) : ListAllChannelGroup {
override fun async(callback: Consumer<Result<PNChannelGroupsListAllResult>>) {
pubnub.listChannelGroupsOnSuccess(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.channel_groups

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.removeWithChannels
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsRemoveChannelResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface RemoveChannelChannelGroup : PNFuture<PNChannelGroupsRemoveChann

@OptIn(ExperimentalForeignApi::class)
class RemoveChannelChannelGroupImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channels: List<String>,
private val channelGroup: String
) : RemoveChannelChannelGroup {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.files

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.deleteFileWithChannel
import com.pubnub.api.models.consumer.files.PNDeleteFileResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface DeleteFile : PNFuture<PNDeleteFileResult>

@OptIn(ExperimentalForeignApi::class)
class DeleteFileImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channel: String,
private val fileName: String,
private val fileId: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.files

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.downloadFileWithChannel
import com.pubnub.api.models.consumer.files.PNDownloadFileResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -19,7 +19,7 @@ actual interface DownloadFile : PNFuture<PNDownloadFileResult>

@OptIn(ExperimentalForeignApi::class)
class DownloadFileImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channel: String,
private val fileName: String,
private val fileId: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api.endpoints.files

import cocoapods.PubNubSwift.PubNubObjC
import cocoapods.PubNubSwift.KMPPubNub
import cocoapods.PubNubSwift.getFileUrlWithChannel
import com.pubnub.api.models.consumer.files.PNFileUrlResult
import com.pubnub.api.v2.callbacks.Consumer
Expand All @@ -17,7 +17,7 @@ actual interface GetFileUrl : PNFuture<PNFileUrlResult>

@OptIn(ExperimentalForeignApi::class)
class GetFileUrlImpl(
private val pubnub: PubNubObjC,
private val pubnub: KMPPubNub,
private val channel: String,
private val fileName: String,
private val fileId: String
Expand Down
Loading

0 comments on commit 39f6a37

Please sign in to comment.