Skip to content

Commit

Permalink
Use ARTRealtimeOptions's NSCopying support
Browse files Browse the repository at this point in the history
Introduced in TODO.
  • Loading branch information
lawrence-forooghian committed Jan 28, 2025
1 parent 691259f commit 08cfe03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
34 changes: 8 additions & 26 deletions Sources/AblyChat/Dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,19 @@ public protocol RealtimePresenceProtocol: ARTRealtimePresenceProtocol, Sendable
/// Expresses the requirements of the object returned by ``RealtimeClientProtocol/connection``.
public protocol ConnectionProtocol: ARTConnectionProtocol, Sendable {}

/// Like (a subset of) `ARTRealtimeChannelOptions` but with value semantics. (It’s unfortunate that `ARTRealtimeChannelOptions` doesn’t have a `-copy` method.)
internal struct RealtimeChannelOptions {
internal var modes: ARTChannelMode
internal var params: [String: String]?
internal var attachOnSubscribe: Bool

internal init() {
// Get our default values from ably-cocoa
let artRealtimeChannelOptions = ARTRealtimeChannelOptions()
modes = artRealtimeChannelOptions.modes
params = artRealtimeChannelOptions.params
attachOnSubscribe = artRealtimeChannelOptions.attachOnSubscribe
}

internal var toARTRealtimeChannelOptions: ARTRealtimeChannelOptions {
let result = ARTRealtimeChannelOptions()
result.modes = modes
result.params = params
result.attachOnSubscribe = attachOnSubscribe
return result
}
}

internal extension RealtimeClientProtocol {
// Function to get the channel with Chat's default options
func getChannel(_ name: String, opts: RealtimeChannelOptions? = nil) -> any RealtimeChannelProtocol {
var resolvedOptions = opts ?? .init()
func getChannel(_ name: String, opts: ARTRealtimeChannelOptions? = nil) -> any RealtimeChannelProtocol {
let resolvedOptions: ARTRealtimeChannelOptions = if let opts {
// swiftlint:disable:next force_cast
opts.copy() as! ARTRealtimeChannelOptions
} else {
.init()
}

// CHA-GP2a
resolvedOptions.attachOnSubscribe = false

return channels.get(name, options: resolvedOptions.toARTRealtimeChannelOptions)
return channels.get(name, options: resolvedOptions)
}
}
2 changes: 1 addition & 1 deletion Sources/AblyChat/Room.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ internal actor DefaultRoom<LifecycleManagerFactory: RoomLifecycleManagerFactory>
let featuresGroupedByChannelName = Dictionary(grouping: featuresWithOptions) { $0.toRoomFeature.channelNameForRoomID(roomID) }

let unorderedResult = featuresGroupedByChannelName.map { channelName, features in
var channelOptions = RealtimeChannelOptions()
let channelOptions = ARTRealtimeChannelOptions()

// channel setup for presence and occupancy
for feature in features {
Expand Down

0 comments on commit 08cfe03

Please sign in to comment.