Skip to content

Commit 999b657

Browse files
authored
Make 'name' field optional (#90)
fix: make 'name' field optional Make `name` field optional for channel and UUID metadata.
1 parent f05433e commit 999b657

File tree

12 files changed

+52
-31
lines changed

12 files changed

+52
-31
lines changed

.pubnub.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
---
22
name: swift
33
scm: github.com/pubnub/swift
4-
version: "4.1.1"
4+
version: "4.1.2"
55
schema: 1
66
changelog:
7+
- date: 2021-11-08
8+
version: 4.1.2
9+
changes:
10+
- type: bug
11+
text: "Make `name` field optional for channel and UUID metadata."
712
- date: 2021-11-05
813
version: 4.1.1
914
changes:
@@ -424,7 +429,7 @@ sdks:
424429
- distribution-type: source
425430
distribution-repository: GitHub release
426431
package-name: PubNub
427-
location: https://github.com/pubnub/swift/archive/refs/tags/4.1.1.zip
432+
location: https://github.com/pubnub/swift/archive/refs/tags/4.1.2.zip
428433
supported-platforms:
429434
supported-operating-systems:
430435
macOS:

PubNub.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@
25142514
"$(inherited)",
25152515
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
25162516
);
2517-
MARKETING_VERSION = 4.1.1;
2517+
MARKETING_VERSION = 4.1.2;
25182518
OTHER_CFLAGS = "$(inherited)";
25192519
OTHER_LDFLAGS = "$(inherited)";
25202520
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -2547,7 +2547,7 @@
25472547
"$(inherited)",
25482548
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
25492549
);
2550-
MARKETING_VERSION = 4.1.1;
2550+
MARKETING_VERSION = 4.1.2;
25512551
OTHER_CFLAGS = "$(inherited)";
25522552
OTHER_LDFLAGS = "$(inherited)";
25532553
OTHER_SWIFT_FLAGS = "$(inherited)";

PubNubSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'PubNubSwift'
3-
s.version = '4.1.1'
3+
s.version = '4.1.2'
44
s.homepage = 'https://github.com/pubnub/swift'
55
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
66
s.authors = { 'PubNub, Inc.' => '[email protected]' }

Sources/PubNub/Helpers/Constants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct Constant {
6262
}()
6363

6464
static let pubnubSwiftSDKVersion: String = {
65-
"4.1.1"
65+
"4.1.2"
6666
}()
6767

6868
static let appBundleId: String = {

Sources/PubNub/Models/PubNubChannelMetadata.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public protocol PubNubChannelMetadata {
3434
/// The unique identifier of the Channel
3535
var metadataId: String { get }
3636
/// The name of the Channel
37-
var name: String { get set }
37+
var name: String? { get set }
3838
/// Text describing the purpose of the channel
3939
var channelDescription: String? { get set }
4040
/// The last updated timestamp for the object
@@ -75,7 +75,7 @@ extension PubNubChannelMetadata {
7575
/// The default implementation of the `PubNubChannelMetadata` protocol
7676
public struct PubNubChannelMetadataBase: PubNubChannelMetadata, Hashable {
7777
public let metadataId: String
78-
public var name: String
78+
public var name: String?
7979
public var channelDescription: String?
8080

8181
public var updated: Date?
@@ -89,7 +89,7 @@ public struct PubNubChannelMetadataBase: PubNubChannelMetadata, Hashable {
8989

9090
public init(
9191
metadataId: String = UUID().uuidString,
92-
name: String,
92+
name: String? = nil,
9393
channelDescription: String? = nil,
9494
custom concreteCustom: [String: JSONCodableScalar]? = nil,
9595
updated: Date? = nil,

Sources/PubNub/Models/PubNubUUIDMetadata.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public protocol PubNubUUIDMetadata {
3434
/// The unique identifier of the UUID
3535
var metadataId: String { get }
3636
/// The name of the UUID
37-
var name: String { get set }
37+
var name: String? { get set }
3838
/// The external identifier for the object
3939
var externalId: String? { get set }
4040
/// The profile URL for the object
@@ -79,7 +79,7 @@ extension PubNubUUIDMetadata {
7979
/// The default implementation of the `PubNubUUIDMetadata` protocol
8080
public struct PubNubUUIDMetadataBase: PubNubUUIDMetadata, Hashable {
8181
public let metadataId: String
82-
public var name: String
82+
public var name: String?
8383
public var externalId: String?
8484
public var profileURL: String?
8585
public var email: String?
@@ -94,7 +94,7 @@ public struct PubNubUUIDMetadataBase: PubNubUUIDMetadata, Hashable {
9494

9595
public init(
9696
metadataId: String = UUID().uuidString,
97-
name: String,
97+
name: String? = nil,
9898
externalId: String? = nil,
9999
profileURL: String? = nil,
100100
email: String? = nil,

Sources/PubNub/Networking/Routers/ObjectsChannelRouter.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ObjectsChannelRouter: HTTPRouter {
5252

5353
// Custom request body object for .set endpoint
5454
struct SetChannelMetadataRequestBody: JSONCodable {
55-
var name: String
55+
var name: String?
5656
var description: String?
5757
var custom: [String: JSONCodableScalarType]?
5858
}
@@ -156,8 +156,7 @@ struct ObjectsChannelRouter: HTTPRouter {
156156
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyChannelMetadataId))
157157
case let .set(metadata, _):
158158
return isInvalidForReason(
159-
(metadata.metadataId.isEmpty && metadata.name.isEmpty,
160-
ErrorDescription.invalidChannelMetadata))
159+
(metadata.metadataId.isEmpty, ErrorDescription.invalidChannelMetadata))
161160
case let .remove(metadataId):
162161
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyChannelMetadataId))
163162
}

Sources/PubNub/Networking/Routers/ObjectsMembershipsRouter.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,9 @@ struct ObjectMetadataPartial: Codable {
362362
} else if let uuid = try? container.decodeIfPresent(PubNubUUIDMetadataBase.self, forKey: .uuid) {
363363
self.uuid = .init(metadataId: uuid.metadataId, metadataObject: uuid)
364364
channel = nil
365-
} else if let nestedContainer = try? container.nestedContainer(keyedBy: NestedCodingKeys.self, forKey: .channel) {
366-
channel = .init(metadataId: try nestedContainer.decode(String.self, forKey: .id), metadataObject: nil)
367-
uuid = nil
368365
} else {
369-
let nestedContainer = try container.nestedContainer(keyedBy: NestedCodingKeys.self, forKey: .uuid)
370-
uuid = .init(metadataId: try nestedContainer.decode(String.self, forKey: .id), metadataObject: nil)
371366
channel = nil
367+
uuid = nil
372368
}
373369
}
374370

Sources/PubNub/Networking/Routers/ObjectsUUIDRouter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ObjectsUUIDRouter: HTTPRouter {
5252

5353
// Custom request body object for .set endpoint
5454
struct SetUUIDMetadataRequestBody: JSONCodable {
55-
var name: String
55+
var name: String?
5656
var externalId: String?
5757
var profileURL: String?
5858
var email: String?
@@ -167,7 +167,7 @@ struct ObjectsUUIDRouter: HTTPRouter {
167167
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyUUIDMetadataId))
168168
case let .set(metadata, _):
169169
return isInvalidForReason(
170-
(metadata.metadataId.isEmpty && metadata.name.isEmpty, ErrorDescription.invalidUUIDMetadata))
170+
(metadata.metadataId.isEmpty, ErrorDescription.invalidUUIDMetadata))
171171
case let .remove(metadataId):
172172
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyUUIDMetadataId))
173173
}

Sources/PubNub/Networking/Routers/Subscribe Payloads/SubscribeObjectPayload.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ extension PubNubUUIDMetadataChangeset: Codable {
183183

184184
var changes = [PubNubMetadataChange<PubNubUUIDMetadata>]()
185185
if let name = try container.decodeIfPresent(String.self, forKey: .name) {
186-
changes.append(.string(\.name, name))
186+
changes.append(.stringOptional(\.name, name))
187187
}
188188
if let externalId = try container.decodeIfPresent(ValueOptionJSON<String>.self, forKey: .externalId) {
189189
changes.append(.stringOptional(\.externalId, externalId.value))
@@ -267,7 +267,7 @@ extension PubNubChannelMetadataChangeset: Codable {
267267

268268
var changes = [PubNubMetadataChange<PubNubChannelMetadata>]()
269269
if let name = try container.decodeIfPresent(String.self, forKey: .name) {
270-
changes.append(.string(\.name, name))
270+
changes.append(.stringOptional(\.name, name))
271271
}
272272
if let description = try container.decodeIfPresent(ValueOptionJSON<String>.self, forKey: .channelDescription) {
273273
changes.append(.stringOptional(\.channelDescription, description.value))

0 commit comments

Comments
 (0)