diff --git a/.pubnub.yml b/.pubnub.yml index 13bf7b27..f112d192 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,9 +1,14 @@ --- name: swift scm: github.com/pubnub/swift -version: "5.0.1" +version: "5.1.0" schema: 1 changelog: + - date: 2022-02-02 + version: 5.1.0 + changes: + - type: feature + text: "Add affected channels and groups under `affected` resources list." - date: 2022-01-19 version: 5.0.1 changes: @@ -439,7 +444,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: PubNub - location: https://github.com/pubnub/swift/archive/refs/tags/5.0.1.zip + location: https://github.com/pubnub/swift/archive/refs/tags/5.1.0.zip supported-platforms: supported-operating-systems: macOS: diff --git a/Examples/Sources/MasterDetailTableViewController.swift b/Examples/Sources/MasterDetailTableViewController.swift index c024ec3a..f66b1cbe 100644 --- a/Examples/Sources/MasterDetailTableViewController.swift +++ b/Examples/Sources/MasterDetailTableViewController.swift @@ -308,6 +308,16 @@ class MasterDetailTableViewController: UITableViewController { print("A file was uplaoded \(file)") case let .subscribeError(error): print("The following error was generated during subscription \(error.localizedDescription)") + error.affected.forEach { + switch $0 { + case let .channels(affectedChannels): + print("Affected channels: \(affectedChannels)") + case let .channelGroups(affectedChannelGroups): + print("Affected channel groups: \(affectedChannelGroups)") + default: + break + } + } print("If `disconnectedUnexpectedly` also occurred then subscription has stopped, and needs to be restarted") } } diff --git a/PubNub.xcodeproj/project.pbxproj b/PubNub.xcodeproj/project.pbxproj index 710b79c3..fc4fe077 100644 --- a/PubNub.xcodeproj/project.pbxproj +++ b/PubNub.xcodeproj/project.pbxproj @@ -2506,7 +2506,7 @@ "$(inherited)", "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", ); - MARKETING_VERSION = 5.0.1; + MARKETING_VERSION = 5.1.0; OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; @@ -2539,7 +2539,7 @@ "$(inherited)", "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", ); - MARKETING_VERSION = 5.0.1; + MARKETING_VERSION = 5.1.0; OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; diff --git a/PubNubSwift.podspec b/PubNubSwift.podspec index 0e2086a8..65083dd7 100644 --- a/PubNubSwift.podspec +++ b/PubNubSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'PubNubSwift' - s.version = '5.0.1' + s.version = '5.1.0' s.homepage = 'https://github.com/pubnub/swift' s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk' s.authors = { 'PubNub, Inc.' => 'support@pubnub.com' } diff --git a/Sources/PubNub/Errors/PubNubError.swift b/Sources/PubNub/Errors/PubNubError.swift index ded2ee79..ffae5abd 100644 --- a/Sources/PubNub/Errors/PubNubError.swift +++ b/Sources/PubNub/Errors/PubNubError.swift @@ -66,6 +66,8 @@ public struct PubNubError: Error { case response(HTTPURLResponse) case json(AnyJSON) case subscribe(SubscribeCursor) + case channels([String]) + case channelGroups([String]) } /// The PubNubError specific Domain that groups together the different Reasons @@ -255,7 +257,9 @@ public struct PubNubError: Error { router: HTTPRouter?, request: URLRequest?, response: HTTPURLResponse?, - additional details: [ErrorDetail]? = nil + additional details: [ErrorDetail]? = nil, + affectedChannels channels: [String]? = nil, + affectedChannelGroups channelGroups: [String]? = nil ) { var reasonOrResponse = reason @@ -268,6 +272,12 @@ public struct PubNubError: Error { reasonOrResponse = reasonOrResponse ?? Reason(rawValue: response.statusCode) affectedValues.append(.response(response)) } + if let channels = channels { + affectedValues.append(.channels(channels)) + } + if let channelGroups = channelGroups { + affectedValues.append(.channelGroups(channelGroups)) + } self.init(reasonOrResponse ?? .unrecognizedStatusCode, router: router, diff --git a/Sources/PubNub/Helpers/Constants.swift b/Sources/PubNub/Helpers/Constants.swift index 30842f44..799f8a66 100644 --- a/Sources/PubNub/Helpers/Constants.swift +++ b/Sources/PubNub/Helpers/Constants.swift @@ -62,7 +62,7 @@ public struct Constant { }() static let pubnubSwiftSDKVersion: String = { - "5.0.1" + "5.1.0" }() static let appBundleId: String = { diff --git a/Sources/PubNub/Networking/Response/GenericServicePayloadResponse.swift b/Sources/PubNub/Networking/Response/GenericServicePayloadResponse.swift index c7635ffe..ebf0bbae 100644 --- a/Sources/PubNub/Networking/Response/GenericServicePayloadResponse.swift +++ b/Sources/PubNub/Networking/Response/GenericServicePayloadResponse.swift @@ -225,6 +225,8 @@ struct GenericServicePayloadResponse: Codable, Hashable { let status: Int let error: Bool let channels: [String: [String]] + let affectedChannels: [String]? + let affectedChannelGroups: [String]? init( message: EndpointResponseMessage? = nil, @@ -232,7 +234,9 @@ struct GenericServicePayloadResponse: Codable, Hashable { service: String? = nil, status: Int? = nil, error: Bool = false, - channels: [String: [String]] = [:] + channels: [String: [String]] = [:], + affectedChannels: [String]? = nil, + affectedChannelGroups: [String]? = nil ) { if !error, HTTPURLResponse.successfulStatusCodes.contains(status ?? 0) { self.message = .acknowledge @@ -245,6 +249,8 @@ struct GenericServicePayloadResponse: Codable, Hashable { self.status = status ?? -1 self.error = error self.channels = channels + self.affectedChannels = affectedChannels + self.affectedChannelGroups = affectedChannelGroups } enum CodingKeys: String, CodingKey { @@ -254,6 +260,7 @@ struct GenericServicePayloadResponse: Codable, Hashable { case status case error case channels + case payload } init(from decoder: Decoder) throws { @@ -289,13 +296,18 @@ struct GenericServicePayloadResponse: Codable, Hashable { let status = try container.decodeIfPresent(Int.self, forKey: .status) let channels = try container.decodeIfPresent([String: [String]].self, forKey: .channels) ?? [:] + let payload = try container.decodeIfPresent([String: [String]].self, forKey: .payload) ?? [:] + let affectedChannels: [String]? = payload["channels"] + let affectedChannelGroups: [String]? = payload["channel-groups"] self.init(message: message ?? error, details: details, service: service, status: status, error: isError, - channels: channels) + channels: channels, + affectedChannels: affectedChannels, + affectedChannelGroups: affectedChannelGroups) } func encode(to encoder: Encoder) throws { diff --git a/Sources/PubNub/Networking/Response/ResponseOperator.swift b/Sources/PubNub/Networking/Response/ResponseOperator.swift index d278420e..7059874e 100644 --- a/Sources/PubNub/Networking/Response/ResponseOperator.swift +++ b/Sources/PubNub/Networking/Response/ResponseOperator.swift @@ -95,7 +95,9 @@ extension ResponseDecoder { return PubNubError(reason: generalErrorPayload?.pubnubReason, router: router, request: request, response: response, - additional: generalErrorPayload?.details) + additional: generalErrorPayload?.details, + affectedChannels: generalErrorPayload?.affectedChannels, + affectedChannelGroups: generalErrorPayload?.affectedChannelGroups) } } diff --git a/Sources/PubNub/Subscription/SubscriptionSession.swift b/Sources/PubNub/Subscription/SubscriptionSession.swift index a30f1157..f7d50eeb 100644 --- a/Sources/PubNub/Subscription/SubscriptionSession.swift +++ b/Sources/PubNub/Subscription/SubscriptionSession.swift @@ -33,7 +33,7 @@ public class SubscriptionSession { public let uuid = UUID() let longPollingSession: SessionReplaceable - internal(set) var configuration: SubscriptionConfiguration + var configuration: SubscriptionConfiguration let sessionStream: SessionListener /// PSV2 feature to subscribe with a custom filter expression.