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

[ECO-5178] Fix sending and receiving of message headers and metadata #196

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions Sources/AblyChat/JSONCodable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
internal protocol JSONEncodable {
var toJSONObjectValue: [String: JSONValue] { get }
}

internal protocol JSONDecodable {
init(jsonValue: JSONValue) throws
}

internal typealias JSONCodable = JSONDecodable & JSONEncodable
maratal marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 6 additions & 6 deletions Sources/AblyChat/PresenceDataDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ internal struct PresenceDataDTO: Equatable {
internal var userCustomData: PresenceData?
}

// MARK: - Conversion to and from JSONValue
// MARK: - JSONCodable

internal extension PresenceDataDTO {
enum JSONKey: String {
extension PresenceDataDTO: JSONCodable {
internal enum JSONKey: String {
case userCustomData
}

enum DecodingError: Error {
internal enum DecodingError: Error {
case valueHasWrongType(key: JSONKey)
}

init(jsonValue: JSONValue) throws {
internal init(jsonValue: JSONValue) throws {
guard case let .object(jsonObject) = jsonValue else {
throw DecodingError.valueHasWrongType(key: .userCustomData)
}

userCustomData = jsonObject[JSONKey.userCustomData.rawValue]
}

var toJSONObjectValue: [String: JSONValue] {
internal var toJSONObjectValue: [String: JSONValue] {
var result: [String: JSONValue] = [:]

if let userCustomData {
Expand Down
4 changes: 2 additions & 2 deletions Tests/AblyChatTests/PresenceDataDTOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Testing

struct PresenceDataDTOTests {
// MARK: - Creating from JSON value
// MARK: - JSONDecodable

@Test(arguments: [
// If the `userCustomData` key is missing (indicating that no data was passed when performing the presence operation), then the DTO’s `userCustomData` should be nil
Expand All @@ -22,7 +22,7 @@ struct PresenceDataDTOTests {
}
}

// MARK: - Conversion to JSON object value
// MARK: - JSONCodable

@Test(
arguments: [
Expand Down