Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Oct 4, 2024
1 parent 5d0c392 commit 9b84308
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/PubNub/APIs/File+PubNub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Networking/Routers/HistoryRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ struct MessageHistoryResponseDecoder: ResponseDecoder {
)
}
}

return messages
}

Expand Down
37 changes: 31 additions & 6 deletions Sources/PubNub/Networking/Routers/PublishRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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/"
)
}
}

Expand Down
34 changes: 32 additions & 2 deletions Sources/PubNub/Networking/Routers/SubscribeRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9b84308

Please sign in to comment.