Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle all possible values for the include field in the KMP layer (internal usage) #197

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions PubNub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@
3D4ED42F2B519FC500FE58C7 /* SubscriptionSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4ED42E2B519FC500FE58C7 /* SubscriptionSessionTests.swift */; };
3D5BE9AE2BCEA5B50091ACA7 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3D34160A2BB5832E008558A0 /* PrivacyInfo.xcprivacy */; };
3D6265D72ABCA79100FDD5E6 /* CryptorUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D6265D62ABCA79100FDD5E6 /* CryptorUtils.swift */; };
3D7062C42D26AA20000729E1 /* KMPAppContextIncludeFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D7062C32D26AA20000729E1 /* KMPAppContextIncludeFields.swift */; };
3D7411A32C171F2B002267B8 /* Int+NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D7411A22C171F2B002267B8 /* Int+NSNumber.swift */; };
3D758DBF2AAA1C49005D2B36 /* CryptoModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D758DBE2AAA1C49005D2B36 /* CryptoModule.swift */; };
3D758DC82AB06A12005D2B36 /* CryptoInputStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D758DC62AB06A12005D2B36 /* CryptoInputStream.swift */; };
Expand Down Expand Up @@ -1046,6 +1047,7 @@
3D452B242C05DF6D008987D4 /* KMPHereNowResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPHereNowResult.swift; sourceTree = "<group>"; };
3D4ED42E2B519FC500FE58C7 /* SubscriptionSessionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionSessionTests.swift; sourceTree = "<group>"; };
3D6265D62ABCA79100FDD5E6 /* CryptorUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptorUtils.swift; sourceTree = "<group>"; };
3D7062C32D26AA20000729E1 /* KMPAppContextIncludeFields.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPAppContextIncludeFields.swift; sourceTree = "<group>"; };
3D7411A22C171F2B002267B8 /* Int+NSNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+NSNumber.swift"; sourceTree = "<group>"; };
3D758DBE2AAA1C49005D2B36 /* CryptoModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptoModule.swift; sourceTree = "<group>"; };
3D758DC62AB06A12005D2B36 /* CryptoInputStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CryptoInputStream.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2079,6 +2081,7 @@
3DBFF2BE2C22F21200142985 /* KMPEntity.swift */,
3DBFF2C22C2300F500142985 /* KMPSubscription.swift */,
3D3C38822C47D62700E782E7 /* KMPError.swift */,
3D7062C32D26AA20000729E1 /* KMPAppContextIncludeFields.swift */,
);
path = Wrappers;
sourceTree = "<group>";
Expand Down Expand Up @@ -3720,6 +3723,7 @@
35EE358C22E26A4D00E3F081 /* HTTPURLResponse+PubNub.swift in Sources */,
3D389FEE2B35AF4A006928E7 /* SubscribeTransition.swift in Sources */,
3DB925822B7AA75F001B7E90 /* Subscribable.swift in Sources */,
3D7062C42D26AA20000729E1 /* KMPAppContextIncludeFields.swift in Sources */,
3DB9257E2B7AA75F001B7E90 /* PubNubEntityEvent.swift in Sources */,
3D389FE32B35AF4A006928E7 /* EffectHandler.swift in Sources */,
350EFBE022C9573F00FA33AA /* NSLocking+PubNub.swift in Sources */,
Expand Down
172 changes: 95 additions & 77 deletions Sources/PubNub/KMP/KMPPubNub+AppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@ extension KMPPubNub {
}
}
}

private func mapToPubNubIncludeFields(from includeFields: KMPAppContextIncludeFields) -> PubNub.IncludeFields {
PubNub.IncludeFields(
custom: includeFields.includeCustom,
type: includeFields.includeType,
status: includeFields.includeStatus,
totalCount: includeFields.includeTotalCount
)
}

private func mapToChannelIncludeFields(from includeFields: KMPChannelIncludeFields) -> PubNub.ChannelIncludeFields {
PubNub.ChannelIncludeFields(
custom: includeFields.includeCustom,
type: includeFields.includeType,
status: includeFields.includeStatus,
totalCount: includeFields.includeTotalCount
)
}

private func mapToPubNubUserIncludeFields(from includeFields: KMPUserIncludeFields) -> PubNub.UserIncludeFields {
PubNub.UserIncludeFields(
custom: includeFields.includeCustom,
type: includeFields.includeType,
status: includeFields.includeStatus,
totalCount: includeFields.includeTotalCount
)
}
}

@objc
Expand All @@ -90,13 +117,12 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [KMPObjectSortProperty],
includeCount: Bool,
includeCustom: Bool,
include includeFields: KMPChannelIncludeFields,
onSuccess: @escaping (([KMPChannelMetadata], NSNumber?, KMPHashedPage) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.allChannelMetadata(
include: PubNub.IncludeFields(custom: includeCustom, totalCount: includeCount),
include: mapToPubNubIncludeFields(from: includeFields),
filter: filter,
sort: objectSortProperties(from: sort),
limit: limit?.intValue,
Expand All @@ -117,11 +143,11 @@ public extension KMPPubNub {

func getChannelMetadata(
metadataId: String,
includeCustom: Bool,
include includeFields: KMPChannelIncludeFields,
onSuccess: @escaping ((KMPChannelMetadata) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.fetchChannelMetadata(metadataId, include: PubNub.ChannelIncludeFields(custom: includeCustom)) {
pubnub.fetchChannelMetadata(metadataId, include: mapToChannelIncludeFields(from: includeFields)) {
switch $0 {
case .success(let metadata):
onSuccess(KMPChannelMetadata(metadata: metadata))
Expand All @@ -136,9 +162,9 @@ public extension KMPPubNub {
name: String?,
description: String?,
custom: KMPAnyJSON?,
includeCustom: Bool,
type: String?,
status: String?,
include includeFields: KMPChannelIncludeFields,
onSuccess: @escaping ((KMPChannelMetadata) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
Expand All @@ -150,7 +176,7 @@ public extension KMPPubNub {
channelDescription: description,
custom: convertDictionaryToScalars(custom?.asMap())
)
pubnub.setChannelMetadata(channelMetadata, include: PubNub.ChannelIncludeFields(custom: includeCustom)) {
pubnub.setChannelMetadata(channelMetadata, include: mapToChannelIncludeFields(from: includeFields)) {
switch $0 {
case .success(let metadata):
onSuccess(KMPChannelMetadata(metadata: metadata))
Expand Down Expand Up @@ -180,13 +206,12 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [KMPObjectSortProperty],
includeCount: Bool,
includeCustom: Bool,
include includeFields: KMPUserIncludeFields,
onSuccess: @escaping (([KMPUserMetadata], NSNumber?, KMPHashedPage) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.allUserMetadata(
include: PubNub.UserIncludeFields(custom: includeCustom, totalCount: includeCount),
include: mapToPubNubUserIncludeFields(from: includeFields),
filter: filter,
sort: objectSortProperties(from: sort),
limit: limit?.intValue,
Expand All @@ -207,11 +232,11 @@ public extension KMPPubNub {

func getUserMetadata(
metadataId: String?,
includeCustom: Bool,
include includeFields: KMPUserIncludeFields,
onSuccess: @escaping ((KMPUserMetadata) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.fetchUserMetadata(metadataId, include: PubNub.UserIncludeFields(custom: includeCustom)) {
pubnub.fetchUserMetadata(metadataId, include: mapToPubNubUserIncludeFields(from: includeFields)) {
switch $0 {
case .success(let metadata):
onSuccess(KMPUserMetadata(metadata: metadata))
Expand All @@ -228,9 +253,9 @@ public extension KMPPubNub {
profileUrl: String?,
email: String?,
custom: KMPAnyJSON?,
includeCustom: Bool,
type: String?,
status: String?,
include includeFields: KMPUserIncludeFields,
onSuccess: @escaping ((KMPUserMetadata) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
Expand All @@ -244,10 +269,7 @@ public extension KMPPubNub {
email: email,
custom: convertDictionaryToScalars(custom?.asMap())
)
pubnub.setUserMetadata(
userMetadata,
include: PubNub.UserIncludeFields(custom: includeCustom)
) {
pubnub.setUserMetadata(userMetadata, include: mapToPubNubUserIncludeFields(from: includeFields)) {
switch $0 {
case .success(let metadata):
onSuccess(KMPUserMetadata(metadata: metadata))
Expand Down Expand Up @@ -278,22 +300,21 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [String],
includeCount: Bool,
includeCustom: Bool,
includeChannelFields: Bool,
includeChannelCustomFields: Bool,
includeChannelType: Bool,
include includeFields: KMPMembershipIncludeFields,
onSuccess: @escaping (([KMPMembershipMetadata], NSNumber?, KMPHashedPage?) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.fetchMemberships(
userId: userId,
include: .init(
customFields: includeCustom,
channelFields: includeChannelFields,
channelCustomFields: includeChannelCustomFields,
channelTypeField: includeChannelType,
totalCount: includeCount
customFields: includeFields.includeCustom,
channelFields: includeFields.includeChannel,
statusField: includeFields.includeStatus,
typeField: includeFields.includeType,
channelCustomFields: includeFields.includeChannelCustom,
channelTypeField: includeFields.includeChannelType,
channelStatusField: includeFields.includeChannelStatus,
totalCount: includeFields.includeTotalCount
),
filter: filter,
sort: mapToMembershipSortFields(from: sort),
Expand All @@ -320,11 +341,7 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [String],
includeCount: Bool,
includeCustom: Bool,
includeChannelFields: Bool,
includeChannelCustomFields: Bool,
includeChannelType: Bool,
include includeFields: KMPMembershipIncludeFields,
onSuccess: @escaping (([KMPMembershipMetadata], NSNumber?, KMPHashedPage?) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
Expand All @@ -335,15 +352,19 @@ public extension KMPPubNub {
userMetadataId: userId ?? pubnub.configuration.userId,
channelMetadataId: $0.id,
status: $0.status,
type: $0.type,
custom: convertDictionaryToScalars($0.custom)
)
},
include: .init(
customFields: includeCustom,
channelFields: includeChannelFields,
channelCustomFields: includeChannelCustomFields,
channelTypeField: includeChannelType,
totalCount: includeCount
customFields: includeFields.includeCustom,
channelFields: includeFields.includeChannel,
statusField: includeFields.includeStatus,
typeField: includeFields.includeType,
channelCustomFields: includeFields.includeChannelCustom,
channelTypeField: includeFields.includeChannelType,
channelStatusField: includeFields.includeChannelStatus,
totalCount: includeFields.includeTotalCount
),
filter: filter,
sort: mapToMembershipSortFields(from: sort),
Expand All @@ -370,11 +391,7 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [String],
includeCount: Bool,
includeCustom: Bool,
includeChannelFields: Bool,
includeChannelCustomFields: Bool,
includeChannelType: Bool,
include includeFields: KMPMembershipIncludeFields,
onSuccess: @escaping (([KMPMembershipMetadata], NSNumber?, KMPHashedPage?) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
Expand All @@ -387,11 +404,14 @@ public extension KMPPubNub {
)
},
include: .init(
customFields: includeCustom,
channelFields: includeChannelFields,
channelCustomFields: includeChannelCustomFields,
channelTypeField: includeChannelType,
totalCount: includeCount
customFields: includeFields.includeCustom,
channelFields: includeFields.includeChannel,
statusField: includeFields.includeStatus,
typeField: includeFields.includeType,
channelCustomFields: includeFields.includeChannelCustom,
channelTypeField: includeFields.includeChannelType,
channelStatusField: includeFields.includeChannelStatus,
totalCount: includeFields.includeTotalCount
),
filter: filter,
sort: mapToMembershipSortFields(from: sort),
Expand All @@ -417,22 +437,21 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [String],
includeCount: Bool,
includeCustom: Bool,
includeUserFields: Bool,
includeUserCustomFields: Bool,
includeUserType: Bool,
include includeFields: KMPMemberIncludeFields,
onSuccess: @escaping (([KMPMembershipMetadata], NSNumber?, KMPHashedPage?) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.fetchMembers(
channel: channel,
include: .init(
customFields: includeCustom,
uuidFields: includeUserFields,
uuidCustomFields: includeUserCustomFields,
uuidTypeField: includeUserType,
totalCount: includeCount
customFields: includeFields.includeCustom,
uuidFields: includeFields.includeUser,
statusField: includeFields.includeStatus,
typeField: includeFields.includeType,
uuidCustomFields: includeFields.includeUserCustom,
uuidTypeField: includeFields.includeUserType,
uuidStatusField: includeFields.includeUserStatus,
totalCount: includeFields.includeTotalCount
),
filter: filter,
sort: mapToMembershipSortFields(from: sort),
Expand All @@ -459,11 +478,7 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [String],
includeCount: Bool,
includeCustom: Bool,
includeUser: Bool,
includeUserCustom: Bool,
includeUserType: Bool,
include includeFields: KMPMemberIncludeFields,
onSuccess: @escaping (([KMPMembershipMetadata], NSNumber?, KMPHashedPage?) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
Expand All @@ -474,15 +489,19 @@ public extension KMPPubNub {
userMetadataId: $0.id,
channelMetadataId: channel,
status: $0.status,
type: $0.type,
custom: convertDictionaryToScalars($0.custom)
)
},
include: .init(
customFields: includeCustom,
uuidFields: includeUser,
uuidCustomFields: includeUserCustom,
uuidTypeField: includeUserType,
totalCount: includeCount
customFields: includeFields.includeCustom,
uuidFields: includeFields.includeUser,
statusField: includeFields.includeStatus,
typeField: includeFields.includeType,
uuidCustomFields: includeFields.includeUserCustom,
uuidTypeField: includeFields.includeUserType,
uuidStatusField: includeFields.includeUserStatus,
totalCount: includeFields.includeTotalCount
),
filter: filter,
sort: mapToMembershipSortFields(from: sort),
Expand All @@ -509,11 +528,7 @@ public extension KMPPubNub {
page: KMPHashedPage?,
filter: String?,
sort: [String],
includeCount: Bool,
includeCustom: Bool,
includeUser: Bool,
includeUserCustom: Bool,
includeUserType: Bool,
include includeFields: KMPMemberIncludeFields,
onSuccess: @escaping (([KMPMembershipMetadata], NSNumber?, KMPHashedPage?) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
Expand All @@ -526,11 +541,14 @@ public extension KMPPubNub {
)
},
include: .init(
customFields: includeCustom,
uuidFields: includeUser,
uuidCustomFields: includeUserCustom,
uuidTypeField: includeUserType,
totalCount: includeCount
customFields: includeFields.includeCustom,
uuidFields: includeFields.includeUser,
statusField: includeFields.includeStatus,
typeField: includeFields.includeType,
uuidCustomFields: includeFields.includeUserCustom,
uuidTypeField: includeFields.includeUserType,
uuidStatusField: includeFields.includeUserStatus,
totalCount: includeFields.includeTotalCount
),
filter: filter,
sort: mapToMembershipSortFields(from: sort),
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/KMP/KMPPubNub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// While these symbols are public, they are intended strictly for internal usage.
//
// External developers should refrain from directly using these symbols in their code, as their implementation details
// may change in future versions of the framework, potentially leading to breaking changes..
// may change in future versions of the framework, potentially leading to breaking changes.

import Foundation

Expand Down
Loading
Loading