From eda52820b95398fec45ca14e12590914fcb61c72 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Tue, 17 Dec 2024 16:09:52 -0300 Subject: [PATCH] Improve the type of PresenceMember.extras MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The type that I gave it in 20e7f5f was just copied from the JS SDK, but we can do better - make it strongly typed, using a type that’s consistent with PresenceData. Part of #13. --- Sources/AblyChat/DefaultPresence.swift | 7 +++++-- Sources/AblyChat/Presence.swift | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/AblyChat/DefaultPresence.swift b/Sources/AblyChat/DefaultPresence.swift index 7d17082..b6470c0 100644 --- a/Sources/AblyChat/DefaultPresence.swift +++ b/Sources/AblyChat/DefaultPresence.swift @@ -268,8 +268,11 @@ internal final class DefaultPresence: Presence, EmitsDiscontinuities { throw error } - // Seems like we want to just forward on `extras` from the cocoa SDK but that is an `ARTJsonCompatible` type which is not `Sendable`... currently just converting this to a `Sendable` type (`String`) until we know what to do with this. - let extras = member.extras?.toJSONString() + let extras: [String: JSONValue]? = if let ablyCocoaExtras = member.extras { + JSONValue.objectFromAblyCocoaExtras(ablyCocoaExtras) + } else { + nil + } let presenceMember = PresenceMember( clientID: clientID, diff --git a/Sources/AblyChat/Presence.swift b/Sources/AblyChat/Presence.swift index 5c75594..ea6e9b2 100644 --- a/Sources/AblyChat/Presence.swift +++ b/Sources/AblyChat/Presence.swift @@ -166,7 +166,7 @@ public struct PresenceMember: Sendable { } } - public init(clientID: String, data: PresenceData?, action: PresenceMember.Action, extras: (any Sendable)?, updatedAt: Date) { + public init(clientID: String, data: PresenceData?, action: PresenceMember.Action, extras: [String: JSONValue]?, updatedAt: Date) { self.clientID = clientID self.data = data self.action = action @@ -195,7 +195,7 @@ public struct PresenceMember: Sendable { /** * The extras associated with the presence member. */ - public var extras: (any Sendable)? + public var extras: [String: JSONValue]? public var updatedAt: Date }