diff --git a/Sources/PubNub/APIs/File+PubNub.swift b/Sources/PubNub/APIs/File+PubNub.swift index 177f2ded..3e2c57db 100644 --- a/Sources/PubNub/APIs/File+PubNub.swift +++ b/Sources/PubNub/APIs/File+PubNub.swift @@ -81,7 +81,7 @@ public extension PubNub { /// The optional message that will be include alongside the File information public var additionalMessage: JSONCodable? /// Custom message type - public var customMessageType: String? = nil + public var customMessageType: String? /// If true the published message is stored in history. public var store: Bool? /// Set a per message time to live in storage. diff --git a/Sources/PubNub/Networking/Routers/HistoryRouter.swift b/Sources/PubNub/Networking/Routers/HistoryRouter.swift index 90edd916..4a5b7efb 100644 --- a/Sources/PubNub/Networking/Routers/HistoryRouter.swift +++ b/Sources/PubNub/Networking/Routers/HistoryRouter.swift @@ -221,7 +221,7 @@ struct MessageHistoryResponseDecoder: ResponseDecoder { ) } } - + return messages } diff --git a/Sources/PubNub/Networking/Routers/PublishRouter.swift b/Sources/PubNub/Networking/Routers/PublishRouter.swift index daee6710..f2d7a5be 100644 --- a/Sources/PubNub/Networking/Routers/PublishRouter.swift +++ b/Sources/PubNub/Networking/Routers/PublishRouter.swift @@ -15,11 +15,33 @@ import Foundation struct PublishRouter: HTTPRouter { // Nested Endpoint enum Endpoint: CustomStringConvertible { - case publish(message: AnyJSON, channel: String, customMessageType: String?, shouldStore: Bool?, ttl: Int?, meta: AnyJSON?) - case compressedPublish(message: AnyJSON, channel: String, customMessageType: String?, shouldStore: Bool?, ttl: Int?, meta: AnyJSON?) - case fire(message: AnyJSON, channel: String, meta: AnyJSON?) - case signal(message: AnyJSON, channel: String, customMessageType: String?) - case file(message: FilePublishPayload, customMessageType: String?, shouldStore: Bool?, ttl: Int?, meta: AnyJSON?) + case publish( + message: AnyJSON, channel: String, + customMessageType: String?, shouldStore: Bool?, + ttl: Int?, meta: AnyJSON? + ) + case compressedPublish( + message: AnyJSON, channel: String, + customMessageType: String?, shouldStore: Bool?, + ttl: Int?, meta: AnyJSON? + ) + case fire( + message: AnyJSON, + channel: String, + meta: AnyJSON? + ) + case signal( + message: AnyJSON, + channel: String, + customMessageType: String? + ) + case file( + message: FilePublishPayload, + customMessageType: String?, + shouldStore: Bool?, + ttl: Int?, + meta: AnyJSON? + ) var description: String { switch self { @@ -66,7 +88,10 @@ struct PublishRouter: HTTPRouter { case let .signal(message, channel, _): return append(message: message, to: "/signal/\(publishKey)/\(subscribeKey)/0/\(channel.urlEncodeSlash)/0/") case let .file(message, _, _, _, _): - return append(message: message, to: "/v1/files/publish-file/\(publishKey)/\(subscribeKey)/0/\(message.channel.urlEncodeSlash)/0/") + return append( + message: message, + to: "/v1/files/publish-file/\(publishKey)/\(subscribeKey)/0/\(message.channel.urlEncodeSlash)/0/" + ) } } diff --git a/Sources/PubNub/Networking/Routers/SubscribeRouter.swift b/Sources/PubNub/Networking/Routers/SubscribeRouter.swift index dc09e2de..125d7a72 100644 --- a/Sources/PubNub/Networking/Routers/SubscribeRouter.swift +++ b/Sources/PubNub/Networking/Routers/SubscribeRouter.swift @@ -316,7 +316,7 @@ public struct SubscribeMessagePayload: Codable, Hashable { /// Presence Event type /// - warning: This is a client-side type and will be encoded as nil case presence = 99 - + var asPubNubMessageType: PubNubMessageType { switch self { case .message: @@ -335,6 +335,36 @@ public struct SubscribeMessagePayload: Codable, Hashable { } } + init( + shard: String, + subscription: String?, + channel: String, + messageType: Action, + customMessageType: String? = nil, + payload: AnyJSON, + flags: Int, + publisher: String?, + subscribeKey: String, + originTimetoken: SubscribeCursor?, + publishTimetoken: SubscribeCursor, + meta: AnyJSON?, + error: PubNubError? + ) { + self.shard = shard + self.subscription = subscription + self.channel = channel + self.messageType = messageType + self.customMessageType = customMessageType + self.payload = payload + self.flags = flags + self.publisher = publisher + self.subscribeKey = subscribeKey + self.originTimetoken = originTimetoken + self.publishTimetoken = publishTimetoken + self.metadata = meta + self.error = error + } + public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) @@ -385,7 +415,7 @@ public struct SubscribeMessagePayload: Codable, Hashable { if messageType != .presence { try container.encode(messageType, forKey: .messageType) } - + try container.encode(customMessageType, forKey: .customMessageType) } // swiftlint:disable:next file_length