Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions Sources/AblyChat/BufferingPolicy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* (This is the same as `AsyncStream<Element>.Continuation.BufferingPolicy` but with the generic type parameter `Element` removed.)
*/
public enum BufferingPolicy: Sendable {
// swiftlint:disable:next missing_docs
/// Buffer all events without limit.
case unbounded
// swiftlint:disable:next missing_docs
/// Buffer up to a specific number of oldest events.
case bufferingOldest(Int)
// swiftlint:disable:next missing_docs
/// Buffer up to a specific number of newest events.
case bufferingNewest(Int)

internal func asAsyncStreamBufferingPolicy<Element>() -> AsyncStream<Element>.Continuation.BufferingPolicy {
Expand Down
66 changes: 52 additions & 14 deletions Sources/AblyChat/ChatClient.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Ably

// This disable of attributes can be removed once missing_docs fixed here
// swiftlint:disable attributes
/**
* The protocol defining the interface for a chat client.
*
* This protocol exists to allow for easier testing and mocking of chat client functionality.
*/
@MainActor
// swiftlint:disable:next missing_docs
public protocol ChatClientProtocol: AnyObject, Sendable {
// swiftlint:enable attributes

// swiftlint:disable:next missing_docs
/// The type of the underlying Ably Realtime client.
associatedtype Realtime
// swiftlint:disable:next missing_docs
/// The type of the connection object.
associatedtype Connection: AblyChat.Connection
// swiftlint:disable:next missing_docs
/// The type of the rooms manager.
associatedtype Rooms: AblyChat.Rooms

/**
Expand Down Expand Up @@ -72,12 +72,26 @@ internal final class DefaultInternalRealtimeClientFactory<Underlying: ProxyRealt
* This is the core client for Ably chat. It provides access to chat rooms.
*/
public class ChatClient: ChatClientProtocol {
// swiftlint:disable:next missing_docs
/**
* Returns the underlying Ably Realtime client.
*
* - Returns: The Ably Realtime client.
*/
public let realtime: ARTRealtime
// swiftlint:disable:next missing_docs

/**
* Returns the resolved client options for the client, including any defaults that have been set.
*
* - Returns: The client options.
*/
public let clientOptions: ChatClientOptions
private let _rooms: DefaultRooms<DefaultRoomFactory<InternalRealtimeClientAdapter<ARTWrapperSDKProxyRealtime>>>
// swiftlint:disable:next missing_docs

/**
* Returns the rooms object, which provides access to chat rooms.
*
* - Returns: The rooms object.
*/
public var rooms: some Rooms<ARTRealtimeChannel> {
_rooms
}
Expand All @@ -87,14 +101,24 @@ public class ChatClient: ChatClientProtocol {
// (CHA-CS1) Every chat client has a status, which describes the current status of the connection.
// (CHA-CS4) The chat client must allow its connection status to be observed by clients.
private let _connection: DefaultConnection
// swiftlint:disable:next missing_docs

/**
* Returns the underlying connection to Ably, which can be used to monitor the client's
* connection to Ably servers.
*
* - Returns: The connection object.
*/
public var connection: some Connection {
_connection
}

/**
* Constructor for Chat
*
* - Important: The Ably Realtime client must have a clientId set. This can be done by configuring
* token-based authentication that returns a token with a clientId, or by setting
* the clientId directly in the Realtime client options.
*
* - Parameters:
* - realtime: The Ably Realtime client. Its `dispatchQueue` option must be the main queue (this is its default behaviour).
* - clientOptions: The client options.
Expand Down Expand Up @@ -127,7 +151,15 @@ public class ChatClient: ChatClientProtocol {
_connection = DefaultConnection(realtime: internalRealtime)
}

// swiftlint:disable:next missing_docs
/**
* Returns the clientID of the current client, if known.
*
* - Important: When using an Ably key for authentication, this value is determined immediately. If using a token,
* the clientID is not known until the client has successfully connected to and authenticated with
* the server. Use the `chatClient.connection.status` to check the connection status.
*
* - Returns: The clientID, or `nil` if unknown.
*/
public var clientID: String? {
realtime.clientId
}
Expand All @@ -151,7 +183,13 @@ public struct ChatClientOptions: Sendable {
*/
public var logLevel: LogLevel? = .error

// swiftlint:disable:next missing_docs
/**
* Creates a new instance of ``ChatClientOptions``.
*
* - Parameters:
* - logHandler: A custom log handler for logging messages from the client.
* - logLevel: The minimum log level at which messages will be logged.
*/
public init(logHandler: LogHandler? = nil, logLevel: LogLevel? = .error) {
self.logHandler = logHandler
self.logLevel = logLevel
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Ably
*/
@MainActor
public protocol Connection: AnyObject, Sendable {
// swiftlint:disable:next missing_docs
/// The type of the status subscription.
associatedtype StatusSubscription: AblyChat.StatusSubscription

/**
Expand Down
14 changes: 9 additions & 5 deletions Sources/AblyChat/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ public enum ChatMessageAction: Sendable {
* Action applied to a new message.
*/
case messageCreate
// swiftlint:disable:next missing_docs
/**
* Action applied to an updated message.
*/
case messageUpdate
// swiftlint:disable:next missing_docs
/**
* Action applied to a deleted message.
*/
case messageDelete

internal static func fromRealtimeAction(_ action: ARTMessageAction) -> Self? {
Expand Down Expand Up @@ -81,9 +85,9 @@ internal enum OccupancyEvents: String {

/// Enum representing the typing event types.
public enum TypingEventType: Sendable {
// swiftlint:disable:next missing_docs
/// Event triggered when a user is typing.
case started
// swiftlint:disable:next missing_docs
/// Event triggered when a user stops typing.
case stopped

internal var rawValue: String {
Expand All @@ -98,7 +102,7 @@ public enum TypingEventType: Sendable {

/// Enum representing the typing set event types.
public enum TypingSetEventType: Sendable {
// swiftlint:disable:next missing_docs
/// Event triggered when a change occurs in the set of typers.
case setChanged

internal var rawValue: String {
Expand Down
16 changes: 8 additions & 8 deletions Sources/AblyChat/Headers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import Ably

/// A value that can be used in ``Headers``. It is the same as ``JSONValue`` except it does not have the `object` or `array` cases.
public enum HeadersValue: Sendable, Equatable {
// swiftlint:disable:next missing_docs
/// A string value.
case string(String)
// swiftlint:disable:next missing_docs
/// A numeric value.
case number(Double)
// swiftlint:disable:next missing_docs
/// A boolean value.
case bool(Bool)
// swiftlint:disable:next missing_docs
/// A null value.
case null

// MARK: - Convenience getters for associated values
Expand Down Expand Up @@ -51,28 +51,28 @@ public enum HeadersValue: Sendable, Equatable {
}

extension HeadersValue: ExpressibleByStringLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `HeadersValue` from a string literal.
public init(stringLiteral value: String) {
self = .string(value)
}
}

extension HeadersValue: ExpressibleByIntegerLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `HeadersValue` from an integer literal.
public init(integerLiteral value: Int) {
self = .number(Double(value))
}
}

extension HeadersValue: ExpressibleByFloatLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `HeadersValue` from a float literal.
public init(floatLiteral value: Double) {
self = .number(value)
}
}

extension HeadersValue: ExpressibleByBooleanLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `HeadersValue` from a boolean literal.
public init(booleanLiteral value: Bool) {
self = .bool(value)
}
Expand Down
24 changes: 12 additions & 12 deletions Sources/AblyChat/JSONValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public typealias JSONObject = [String: JSONValue]
///
/// > Note: To write a `JSONValue` that corresponds to the `null` JSON value, you must explicitly write `.null`. `JSONValue` deliberately does not implement the `ExpressibleByNilLiteral` protocol in order to avoid confusion between a value of type `JSONValue?` and a `JSONValue` with case `.null`.
public indirect enum JSONValue: Sendable, Equatable {
// swiftlint:disable:next missing_docs
/// A JSON object value.
case object(JSONObject)
// swiftlint:disable:next missing_docs
/// A JSON array value.
case array([JSONValue])
// swiftlint:disable:next missing_docs
/// A JSON string value.
case string(String)
// swiftlint:disable:next missing_docs
/// A JSON numeric value.
case number(Double)
// swiftlint:disable:next missing_docs
/// A JSON boolean value.
case bool(Bool)
// swiftlint:disable:next missing_docs
/// A JSON null value.
case null

// MARK: - Convenience getters for associated values
Expand Down Expand Up @@ -100,42 +100,42 @@ public indirect enum JSONValue: Sendable, Equatable {
}

extension JSONValue: ExpressibleByDictionaryLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `JSONValue` from a dictionary literal.
public init(dictionaryLiteral elements: (String, JSONValue)...) {
self = .object(.init(uniqueKeysWithValues: elements))
}
}

extension JSONValue: ExpressibleByArrayLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `JSONValue` from an array literal.
public init(arrayLiteral elements: JSONValue...) {
self = .array(elements)
}
}

extension JSONValue: ExpressibleByStringLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `JSONValue` from a string literal.
public init(stringLiteral value: String) {
self = .string(value)
}
}

extension JSONValue: ExpressibleByIntegerLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `JSONValue` from an integer literal.
public init(integerLiteral value: Int) {
self = .number(Double(value))
}
}

extension JSONValue: ExpressibleByFloatLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `JSONValue` from a float literal.
public init(floatLiteral value: Double) {
self = .number(value)
}
}

extension JSONValue: ExpressibleByBooleanLiteral {
// swiftlint:disable:next missing_docs
/// Creates a `JSONValue` from a boolean literal.
public init(booleanLiteral value: Bool) {
self = .bool(value)
}
Expand Down
14 changes: 8 additions & 6 deletions Sources/AblyChat/Logging.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

// swiftlint:disable:next missing_docs
/**
* A handler for processing log messages from the Chat SDK.
*/
public struct LogHandler: Sendable {
fileprivate let simple: any Simple

Expand Down Expand Up @@ -34,15 +36,15 @@ public struct LogHandler: Sendable {
* Represents the different levels of logging that can be used.
*/
public enum LogLevel: Sendable, Comparable {
// swiftlint:disable:next missing_docs
/// Verbose trace logging.
case trace
// swiftlint:disable:next missing_docs
/// Debug logging.
case debug
// swiftlint:disable:next missing_docs
/// Informational logging.
case info
// swiftlint:disable:next missing_docs
/// Warning logging.
case warn
// swiftlint:disable:next missing_docs
/// Error logging.
case error
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ internal extension MessageVersion {
}
}

// swiftlint:disable:next missing_docs
/// Extension providing message reaction summary utilities.
public extension Message {
/**
* Creates a new message instance with the event applied.
Expand Down
8 changes: 6 additions & 2 deletions Sources/AblyChat/MessageReaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public struct MessageReactionSummary: Sendable, Equatable {
*/
public var clipped: Bool // TM7c1c

// swiftlint:disable:next missing_docs
/// Memberwise initializer to create a `ClientIDList`.
///
/// - Note: You should not need to use this initializer when using the Chat SDK. It is exposed only to allow users to create mock versions of the SDK's protocols.
public init(total: Int, clientIDs: [String], clipped: Bool) {
self.total = total
self.clientIDs = clientIDs
Expand Down Expand Up @@ -176,7 +178,9 @@ public struct MessageReactionSummary: Sendable, Equatable {
*/
public var totalClientIDs: Int // TM7d1e

// swiftlint:disable:next missing_docs
/// Memberwise initializer to create a `ClientIDCounts`.
///
/// - Note: You should not need to use this initializer when using the Chat SDK. It is exposed only to allow users to create mock versions of the SDK's protocols.
public init(total: Int, clientIDs: [String: Int], totalUnidentified: Int, clipped: Bool, totalClientIDs: Int) {
self.total = total
self.clientIDs = clientIDs
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/MessageReactions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Ably
*/
@MainActor
public protocol MessageReactions: AnyObject, Sendable {
// swiftlint:disable:next missing_docs
/// The type of the subscription.
associatedtype Subscription: AblyChat.Subscription

/**
Expand Down
Loading