Skip to content

Commit

Permalink
Improve the type of PresenceMember.extras
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lawrence-forooghian committed Dec 17, 2024
1 parent 4d7b332 commit eda5282
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Sources/AblyChat/DefaultPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions Sources/AblyChat/Presence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit eda5282

Please sign in to comment.