Skip to content

Commit

Permalink
Merge pull request #230 from ably/ECO-5232
Browse files Browse the repository at this point in the history
[ECO-5232] Updates Chat client options name
  • Loading branch information
umair-ably authored Feb 27, 2025
2 parents ba194e5 + 7d5bc1b commit bb01d60
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The following features have been added in this release:

The included example app has been updated to demonstrate the new features.

#### Breaking Changes

- Renames `ClientOptions` within this SDK to `ChatClientOptions` (https://github.com/ably/ably-chat-swift/pull/230)

**Full Changelog**: https://github.com/ably/ably-chat-swift/compare/0.1.2...0.2.0

## [0.1.2](https://github.com/ably/ably-chat-swift/tree/0.1.2)
Expand Down
2 changes: 1 addition & 1 deletion Example/AblyChatExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private enum Environment: Equatable {
case .mock:
return MockChatClient(
realtime: MockRealtime(),
clientOptions: ClientOptions()
clientOptions: ChatClientOptions()
)
case let .live(key: key, clientId: clientId):
let realtimeOptions = ARTClientOptions()
Expand Down
8 changes: 4 additions & 4 deletions Example/AblyChatExample/Mocks/MockClients.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import AblyChat

actor MockChatClient: ChatClient {
let realtime: RealtimeClient
nonisolated let clientOptions: ClientOptions
nonisolated let clientOptions: ChatClientOptions
nonisolated let rooms: Rooms
nonisolated let connection: Connection

init(realtime: RealtimeClient, clientOptions: ClientOptions?) {
init(realtime: RealtimeClient, clientOptions: ChatClientOptions?) {
self.realtime = realtime
self.clientOptions = clientOptions ?? .init()
connection = MockConnection(status: .connected, error: nil)
Expand All @@ -20,7 +20,7 @@ actor MockChatClient: ChatClient {
}

actor MockRooms: Rooms {
let clientOptions: ClientOptions
let clientOptions: ChatClientOptions
private var rooms = [String: MockRoom]()

func get(roomID: String, options: RoomOptions) async throws -> any Room {
Expand All @@ -36,7 +36,7 @@ actor MockRooms: Rooms {
fatalError("Not yet implemented")
}

init(clientOptions: ClientOptions) {
init(clientOptions: ChatClientOptions) {
self.clientOptions = clientOptions
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/AblyChat/ChatClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public protocol ChatClient: AnyObject, Sendable {
*
* - Returns: The client options.
*/
var clientOptions: ClientOptions { get }
var clientOptions: ChatClientOptions { get }
}

public typealias RealtimeClient = any RealtimeClientProtocol
Expand All @@ -45,7 +45,7 @@ public typealias RealtimeClient = any RealtimeClientProtocol
*/
public actor DefaultChatClient: ChatClient {
public nonisolated let realtime: RealtimeClient
public nonisolated let clientOptions: ClientOptions
public nonisolated let clientOptions: ChatClientOptions
public nonisolated let rooms: Rooms
private let logger: InternalLogger

Expand All @@ -60,7 +60,7 @@ public actor DefaultChatClient: ChatClient {
* - realtime: The Ably Realtime client.
* - clientOptions: The client options.
*/
public init(realtime suppliedRealtime: any SuppliedRealtimeClientProtocol, clientOptions: ClientOptions?) {
public init(realtime suppliedRealtime: any SuppliedRealtimeClientProtocol, clientOptions: ChatClientOptions?) {
self.realtime = suppliedRealtime
self.clientOptions = clientOptions ?? .init()

Expand All @@ -83,7 +83,7 @@ public actor DefaultChatClient: ChatClient {
/**
* Configuration options for the chat client.
*/
public struct ClientOptions: Sendable {
public struct ChatClientOptions: Sendable {
/**
* A custom log handler that will be used to log messages from the client.
*
Expand All @@ -104,7 +104,7 @@ public struct ClientOptions: Sendable {
}

/// Used for comparing these instances in tests without having to make this Equatable, which I’m not yet sure makes sense (we’ll decide in https://github.com/ably-labs/ably-chat-swift/issues/10)
internal func isEqualForTestPurposes(_ other: ClientOptions) -> Bool {
internal func isEqualForTestPurposes(_ other: ChatClientOptions) -> Bool {
logHandler === other.logHandler && logLevel == other.logLevel
}
}
6 changes: 3 additions & 3 deletions Sources/AblyChat/Rooms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public protocol Rooms: AnyObject, Sendable {
*
* - Returns: ``ClientOptions`` object.
*/
var clientOptions: ClientOptions { get }
var clientOptions: ChatClientOptions { get }
}

internal actor DefaultRooms<RoomFactory: AblyChat.RoomFactory>: Rooms {
Expand All @@ -60,7 +60,7 @@ internal actor DefaultRooms<RoomFactory: AblyChat.RoomFactory>: Rooms {
}
#endif

internal nonisolated let clientOptions: ClientOptions
internal nonisolated let clientOptions: ChatClientOptions

private let logger: InternalLogger
private let roomFactory: RoomFactory
Expand Down Expand Up @@ -115,7 +115,7 @@ internal actor DefaultRooms<RoomFactory: AblyChat.RoomFactory>: Rooms {
/// The value for a given room ID is the state that corresponds to that room ID.
private var roomStates: [String: RoomState] = [:]

internal init(realtime: RealtimeClient, clientOptions: ClientOptions, logger: InternalLogger, roomFactory: RoomFactory) {
internal init(realtime: RealtimeClient, clientOptions: ChatClientOptions, logger: InternalLogger, roomFactory: RoomFactory) {
self.realtime = realtime
self.clientOptions = clientOptions
self.logger = logger
Expand Down
8 changes: 4 additions & 4 deletions Tests/AblyChatTests/DefaultChatClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ struct DefaultChatClientTests {
)

// Then: It uses the default client options
let defaultOptions = ClientOptions()
let defaultOptions = ChatClientOptions()
#expect(client.clientOptions.isEqualForTestPurposes(defaultOptions))
}

@Test
func test_realtime() {
// Given: An instance of DefaultChatClient
let realtime = MockRealtime(createWrapperSDKProxyReturnValue: .init())
let options = ClientOptions()
let options = ChatClientOptions()
let client = DefaultChatClient(realtime: realtime, clientOptions: options)

// Then: Its `realtime` property returns the client that was passed to the initializer (i.e. as opposed to the proxy client created by `createWrapperSDKProxy(with:)`
Expand All @@ -31,7 +31,7 @@ struct DefaultChatClientTests {
@Test
func createsWrapperSDKProxyRealtimeClientWithAgents() throws {
let realtime = MockRealtime(createWrapperSDKProxyReturnValue: .init())
let options = ClientOptions()
let options = ChatClientOptions()
_ = DefaultChatClient(realtime: realtime, clientOptions: options)

#expect(realtime.createWrapperSDKProxyOptionsArgument?.agents == ["chat-swift": AblyChat.version])
Expand All @@ -43,7 +43,7 @@ struct DefaultChatClientTests {
// Given: An instance of DefaultChatClient
let proxyClient = MockRealtime()
let realtime = MockRealtime(createWrapperSDKProxyReturnValue: proxyClient)
let options = ClientOptions()
let options = ChatClientOptions()
let client = DefaultChatClient(realtime: realtime, clientOptions: options)

// Then: Its `rooms` property returns an instance of DefaultRooms with the wrapper SDK proxy realtime client and same client options
Expand Down
2 changes: 1 addition & 1 deletion Tests/AblyChatTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct IntegrationTests {

private static func createSandboxChatClient(apiKey: String, loggingLabel: String) -> DefaultChatClient {
let realtime = createSandboxRealtime(apiKey: apiKey, loggingLabel: loggingLabel)
let clientOptions = TestLogger.loggingEnabled ? ClientOptions(logHandler: ChatLogger(label: loggingLabel), logLevel: .trace) : nil
let clientOptions = TestLogger.loggingEnabled ? ChatClientOptions(logHandler: ChatLogger(label: loggingLabel), logLevel: .trace) : nil

return DefaultChatClient(realtime: realtime, clientOptions: clientOptions)
}
Expand Down

0 comments on commit bb01d60

Please sign in to comment.