Skip to content

Commit

Permalink
Merge pull request #156 from ably/some-spec-alignment
Browse files Browse the repository at this point in the history
[ECO-5001] Some spec alignment
  • Loading branch information
lawrence-forooghian authored Nov 28, 2024
2 parents 1ca193a + b41cadc commit 86dfb3b
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 113 deletions.
10 changes: 5 additions & 5 deletions Example/AblyChatExample/Mocks/MockClients.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ actor MockMessages: Messages {
return message
}

func subscribeToDiscontinuities() -> Subscription<ARTErrorInfo?> {
func subscribeToDiscontinuities() -> Subscription<DiscontinuityEvent> {
fatalError("Not yet implemented")
}
}
Expand Down Expand Up @@ -195,7 +195,7 @@ actor MockRoomReactions: RoomReactions {
.init(mockAsyncSequence: createSubscription())
}

func subscribeToDiscontinuities() -> Subscription<ARTErrorInfo?> {
func subscribeToDiscontinuities() -> Subscription<DiscontinuityEvent> {
fatalError("Not yet implemented")
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ actor MockTyping: Typing {
}
}

func subscribeToDiscontinuities() -> Subscription<ARTErrorInfo?> {
func subscribeToDiscontinuities() -> Subscription<DiscontinuityEvent> {
fatalError("Not yet implemented")
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ actor MockPresence: Presence {
.init(mockAsyncSequence: createSubscription())
}

func subscribeToDiscontinuities() -> Subscription<ARTErrorInfo?> {
func subscribeToDiscontinuities() -> Subscription<DiscontinuityEvent> {
fatalError("Not yet implemented")
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ actor MockOccupancy: Occupancy {
OccupancyEvent(connections: 10, presenceMembers: 5)
}

func subscribeToDiscontinuities() -> Subscription<ARTErrorInfo?> {
func subscribeToDiscontinuities() -> Subscription<DiscontinuityEvent> {
fatalError("Not yet implemented")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/DefaultMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal final class DefaultMessages: Messages, EmitsDiscontinuities {
}

// (CHA-M7) Users may subscribe to discontinuity events to know when there’s been a break in messages that they need to resolve. Their listener will be called when a discontinuity event is triggered from the room lifecycle.
internal func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo?> {
internal func subscribeToDiscontinuities() async -> Subscription<DiscontinuityEvent> {
await featureChannel.subscribeToDiscontinuities()
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/DefaultOccupancy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal final class DefaultOccupancy: Occupancy, EmitsDiscontinuities {
}

// (CHA-O5) Users may subscribe to discontinuity events to know when there’s been a break in occupancy. Their listener will be called when a discontinuity event is triggered from the room lifecycle. For occupancy, there shouldn’t need to be user action as most channels will send occupancy updates regularly as clients churn.
internal func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo?> {
internal func subscribeToDiscontinuities() async -> Subscription<DiscontinuityEvent> {
await featureChannel.subscribeToDiscontinuities()
}
}
2 changes: 1 addition & 1 deletion Sources/AblyChat/DefaultPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ internal final class DefaultPresence: Presence, EmitsDiscontinuities {
}

// (CHA-PR8) Users may subscribe to discontinuity events to know when there’s been a break in presence. Their listener will be called when a discontinuity event is triggered from the room lifecycle. For presence, there shouldn’t need to be user action as the underlying core SDK will heal the presence set.
internal func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo?> {
internal func subscribeToDiscontinuities() async -> Subscription<DiscontinuityEvent> {
await featureChannel.subscribeToDiscontinuities()
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/AblyChat/DefaultRoomLifecycleContributor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Ably
internal actor DefaultRoomLifecycleContributor: RoomLifecycleContributor, EmitsDiscontinuities, CustomDebugStringConvertible {
internal nonisolated let channel: DefaultRoomLifecycleContributorChannel
internal nonisolated let feature: RoomFeature
private var discontinuitySubscriptions: [Subscription<ARTErrorInfo?>] = []
private var discontinuitySubscriptions: [Subscription<DiscontinuityEvent>] = []

internal init(channel: DefaultRoomLifecycleContributorChannel, feature: RoomFeature) {
self.channel = channel
Expand All @@ -12,14 +12,14 @@ internal actor DefaultRoomLifecycleContributor: RoomLifecycleContributor, EmitsD

// MARK: - Discontinuities

internal func emitDiscontinuity(_ error: ARTErrorInfo?) {
internal func emitDiscontinuity(_ discontinuity: DiscontinuityEvent) {
for subscription in discontinuitySubscriptions {
subscription.emit(error)
subscription.emit(discontinuity)
}
}

internal func subscribeToDiscontinuities() -> Subscription<ARTErrorInfo?> {
let subscription = Subscription<ARTErrorInfo?>(bufferingPolicy: .unbounded)
internal func subscribeToDiscontinuities() -> Subscription<DiscontinuityEvent> {
let subscription = Subscription<DiscontinuityEvent>(bufferingPolicy: .unbounded)
// TODO: clean up old subscriptions (https://github.com/ably-labs/ably-chat-swift/issues/36)
discontinuitySubscriptions.append(subscription)
return subscription
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/DefaultRoomReactions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal final class DefaultRoomReactions: RoomReactions, EmitsDiscontinuities {
}

// (CHA-ER5) Users may subscribe to discontinuity events to know when there’s been a break in reactions that they need to resolve. Their listener will be called when a discontinuity event is triggered from the room lifecycle.
internal func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo?> {
internal func subscribeToDiscontinuities() async -> Subscription<DiscontinuityEvent> {
await featureChannel.subscribeToDiscontinuities()
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/DefaultTyping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ internal final class DefaultTyping: Typing {
}

// (CHA-T7) Users may subscribe to discontinuity events to know when there’s been a break in typing indicators. Their listener will be called when a discontinuity event is triggered from the room lifecycle. For typing, there shouldn’t need to be user action as the underlying core SDK will heal the presence set.
internal func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo?> {
internal func subscribeToDiscontinuities() async -> Subscription<DiscontinuityEvent> {
await featureChannel.subscribeToDiscontinuities()
}

Expand Down
11 changes: 10 additions & 1 deletion Sources/AblyChat/EmitsDiscontinuities.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import Ably

public struct DiscontinuityEvent: Sendable, Equatable {
/// The error, if any, associated with this discontinuity.
public var error: ARTErrorInfo?

public init(error: ARTErrorInfo? = nil) {
self.error = error
}
}

public protocol EmitsDiscontinuities {
func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo?>
func subscribeToDiscontinuities() async -> Subscription<DiscontinuityEvent>
}
13 changes: 6 additions & 7 deletions Sources/AblyChat/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,25 @@ public enum ErrorCode: Int {

/// The ``ARTErrorInfo.statusCode`` that should be returned for this error.
internal var statusCode: Int {
// TODO: These are currently a guess, revisit once outstanding spec question re status codes is answered (https://github.com/ably/specification/pull/200#discussion_r1755222945), and also revisit in https://github.com/ably-labs/ably-chat-swift/issues/32
// These status codes are taken from the "Chat-specific Error Codes" section of the spec.
switch self {
case .nonspecific,
.inconsistentRoomOptions,
.messagesDetachmentFailed,
.presenceDetachmentFailed,
.reactionsDetachmentFailed,
.occupancyDetachmentFailed,
.typingDetachmentFailed,
.roomInFailedState,
.roomIsReleasing,
.roomIsReleased:
400
case
// TODO: These *AttachmentFailed ones are currently a best guess based on the limited status code information given in the spec at time of writing (i.e. CHA-RL1h4); it's not clear to me whether these error codes are always meant to have the same status code. Revisit once aforementioned spec question re status codes answered.
.messagesAttachmentFailed,
.presenceAttachmentFailed,
.reactionsAttachmentFailed,
.occupancyAttachmentFailed,
.typingAttachmentFailed,
.messagesDetachmentFailed,
.presenceDetachmentFailed,
.reactionsDetachmentFailed,
.occupancyDetachmentFailed,
.typingDetachmentFailed,
// CHA-RL9c
.roomInInvalidState:
500
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/RoomFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal struct DefaultFeatureChannel: FeatureChannel {
internal var contributor: DefaultRoomLifecycleContributor
internal var roomLifecycleManager: RoomLifecycleManager

internal func subscribeToDiscontinuities() async -> Subscription<ARTErrorInfo?> {
internal func subscribeToDiscontinuities() async -> Subscription<DiscontinuityEvent> {
await contributor.subscribeToDiscontinuities()
}

Expand Down
Loading

0 comments on commit 86dfb3b

Please sign in to comment.