Skip to content

Conversation

@maratal
Copy link
Collaborator

@maratal maratal commented Jul 26, 2025

Closes #315

Summary by CodeRabbit

  • New Features
    • Retrieve the latest occupancy data instantly via a new synchronous current() call.
  • Improvements
    • Clearer error when occupancy events are not enabled for a room (current() now indicates this).
  • Tests
    • Expanded occupancy test coverage: enabling events, realtime occupancy emits, current() behavior, and error handling when events are disabled.

@coderabbitai
Copy link

coderabbitai bot commented Jul 26, 2025

Walkthrough

A synchronous current() method and cached lastOccupancyData were added to Occupancy implementations; a new occupancyEventsNotEnabled ChatError was added; mocks and tests were updated to exercise current() and its error behavior.

Changes

Cohort / File(s) Change Summary
Core implementation
Sources/AblyChat/DefaultOccupancy.swift
Added private var lastOccupancyData: OccupancyData?, assigned it on realtime occupancy events, and implemented internal func current() throws(ARTErrorInfo) -> OccupancyData? which validates events are enabled and returns cached data.
API surface
Sources/AblyChat/Occupancy.swift
Added protocol method func current() throws(ARTErrorInfo) -> OccupancyData?.
Errors
Sources/AblyChat/Errors.swift
Added occupancyEventsNotEnabled case to ChatError with status/code and description.
Mocks / Examples
Example/AblyChatExample/Mocks/MockClients.swift
Added current() to MockOccupancy returning fixed OccupancyData.
Tests
Tests/AblyChatTests/DefaultRoomOccupancyTests.swift
Renamed requestOccupancyCheck()occupancyGet(), added occupancyCurrentThrowsError() and updated tests to enable events, emit occupancy messages on subscribe, and assert current() behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DefaultOccupancy
    participant Realtime

    Client->>DefaultOccupancy: call current()
    alt occupancy events enabled
        DefaultOccupancy->>DefaultOccupancy: return lastOccupancyData (cached)
        DefaultOccupancy-->>Client: OccupancyData? (may be nil)
    else occupancy events not enabled
        DefaultOccupancy-->>Client: throw ARTErrorInfo (occupancyEventsNotEnabled)
    end

    Note over Realtime,DefaultOccupancy: Realtime events update lastOccupancyData when received
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective (issue) Addressed Explanation
Implement Occupancy.current() method (#315)
Implement Occupancy.current() method (ECO-5432)

Poem

"I’m a rabbit with data, soft and spry,
I cache the counts that scurry by.
If events are off I’ll shout, 'Not enabled!'
Else I’ll return what was just registered.
Hop on — the occupancy’s mine to spy."

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 315-occupancy-current

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/343/AblyChat July 26, 2025 21:33 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Sources/AblyChat/Occupancy.swift (1)

31-38: Fix documentation terminology for Swift.

The documentation mentions "undefined" which is JavaScript terminology. In Swift, we should use "nil" instead.

-     * - Returns: The latest occupancy data, or undefined if no realtime events have been received yet.
+     * - Returns: The latest occupancy data, or nil if no realtime events have been received yet.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb914a1 and c3f9d07.

📒 Files selected for processing (3)
  • Sources/AblyChat/DefaultOccupancy.swift (3 hunks)
  • Sources/AblyChat/Errors.swift (4 hunks)
  • Sources/AblyChat/Occupancy.swift (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The `Occupancy` protocol in the Ably Chat Swift SDK is annotated with `@MainActor`, making all conforming types like `DefaultOccupancy` automatically main actor-isolated without requiring explicit annotations on their methods.
Learnt from: maratal
PR: ably/ably-chat-swift#165
File: Sources/AblyChat/Reaction.swift:14-14
Timestamp: 2024-12-10T01:59:02.065Z
Learning: For the 'ably-chat-swift' repository, documentation-only PRs should focus exclusively on public methods and properties. Avoid suggesting changes to internal comments or private methods in such PRs.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/DefaultTyping.swift:131-138
Timestamp: 2025-05-12T21:04:36.263Z
Learning: In the AblyChat Swift codebase, SubscriptionHandle closures should capture self weakly with `[weak self]` to avoid potential retain cycles, particularly when calling channel.unsubscribe() within the closure.
Sources/AblyChat/Errors.swift (4)

Learnt from: maratal
PR: #286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The Occupancy protocol in the Ably Chat Swift SDK is annotated with @MainActor, making all conforming types like DefaultOccupancy automatically main actor-isolated without requiring explicit annotations on their methods.

Learnt from: maratal
PR: #286
File: Sources/AblyChat/SubscriptionAsyncSequence.swift:36-41
Timestamp: 2025-06-29T16:02:43.988Z
Learning: In the AblyChat Swift codebase, the fatalError in SubscriptionAsyncSequence.swift's mock async sequence handling (around line 39) is intentional and should not be flagged. This fatalError catches programmer errors when a throwing AsyncSequence is incorrectly passed to the mock initializer, which is meant for testing/development purposes.

Learnt from: maratal
PR: #293
File: Example/AblyChatExample/ContentView.swift:94-99
Timestamp: 2025-06-14T21:47:20.509Z
Learning: In the Ably Chat Swift example app, using fatalError for missing clientID is intentional and appropriate since it represents a programmer error rather than a recoverable runtime condition. The clientID is considered an essential configuration requirement.

Learnt from: maratal
PR: #165
File: Sources/AblyChat/Reaction.swift:14-14
Timestamp: 2024-12-10T01:59:02.065Z
Learning: For the 'ably-chat-swift' repository, documentation-only PRs should focus exclusively on public methods and properties. Avoid suggesting changes to internal comments or private methods in such PRs.

Sources/AblyChat/Occupancy.swift (4)

Learnt from: maratal
PR: #286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The Occupancy protocol in the Ably Chat Swift SDK is annotated with @MainActor, making all conforming types like DefaultOccupancy automatically main actor-isolated without requiring explicit annotations on their methods.

Learnt from: maratal
PR: #286
File: Sources/AblyChat/DefaultTyping.swift:11-14
Timestamp: 2025-05-12T21:03:31.914Z
Learning: The Typing protocol in the Ably Chat Swift SDK is annotated with @MainActor, making all conforming types like DefaultTyping automatically main actor-isolated without requiring explicit annotations on their methods.

Learnt from: maratal
PR: #286
File: Sources/AblyChat/DefaultTyping.swift:11-14
Timestamp: 2025-05-12T21:03:31.914Z
Learning: The Typing protocol in the Ably Chat Swift SDK is annotated with @MainActor, making all conforming types like DefaultTyping automatically main actor-isolated without requiring explicit annotations on their methods.

Learnt from: maratal
PR: #286
File: Example/AblyChatExample/Mocks/MockClients.swift:83-95
Timestamp: 2025-05-12T21:46:44.489Z
Learning: The periodic function in Example/AblyChatExample/Misc/Utils.swift is designed to execute its closure on the main actor (@MainActor), ensuring thread safety when used with shared mutable state that's only accessed from the main actor.

Sources/AblyChat/DefaultOccupancy.swift (3)

Learnt from: maratal
PR: #286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The Occupancy protocol in the Ably Chat Swift SDK is annotated with @MainActor, making all conforming types like DefaultOccupancy automatically main actor-isolated without requiring explicit annotations on their methods.

Learnt from: maratal
PR: #286
File: Sources/AblyChat/DefaultTyping.swift:131-138
Timestamp: 2025-05-12T21:04:36.263Z
Learning: In the AblyChat Swift codebase, SubscriptionHandle closures should capture self weakly with [weak self] to avoid potential retain cycles, particularly when calling channel.unsubscribe() within the closure.

Learnt from: maratal
PR: #286
File: Sources/AblyChat/RoomLifecycleManager.swift:611-624
Timestamp: 2025-05-22T20:57:48.147Z
Learning: In AblyChat Swift, when using continuations with subscription callbacks, the continuation object is captured directly by the closure and doesn't depend on self. Even with [weak self] capture, the continuation will still be resumed properly.

🧬 Code Graph Analysis (1)
Sources/AblyChat/Occupancy.swift (1)
Sources/AblyChat/DefaultOccupancy.swift (1)
  • current (71-79)
🔇 Additional comments (7)
Sources/AblyChat/Errors.swift (4)

180-180: LGTM! New error case properly defined.

The error case follows the established patterns in the codebase.


219-220: LGTM! Appropriate status code mapping.

Using .badRequest (400) for the occupancy events not enabled error is appropriate as it represents a client precondition failure.


281-282: LGTM! Clear and descriptive error message.

The error message clearly explains the issue and is consistent with similar error messages in the codebase.


307-308: LGTM! Properly included in cause handling.

The error case is correctly included in the list of cases that don't have an underlying cause.

Sources/AblyChat/DefaultOccupancy.swift (3)

10-10: LGTM! Appropriate property for caching latest occupancy data.

The optional property correctly stores the most recent occupancy data received from realtime events.


46-46: LGTM! Cache update in the right location.

Updating the cached data when receiving new occupancy events is the correct approach and placement.


71-79: LGTM! Correct implementation of the current() method.

The implementation properly:

  • Validates the precondition (events enabled) and throws the appropriate error
  • Returns the cached occupancy data
  • Includes proper specification references
  • Follows the established error handling patterns

@maratal maratal force-pushed the 315-occupancy-current branch from c3f9d07 to 6aab393 Compare July 26, 2025 21:45
@github-actions github-actions bot temporarily deployed to staging/pull/343/AblyChat July 26, 2025 21:46 Inactive
@maratal maratal force-pushed the 315-occupancy-current branch from 6aab393 to 1e5f227 Compare July 26, 2025 22:29
@github-actions github-actions bot temporarily deployed to staging/pull/343/AblyChat July 26, 2025 22:30 Inactive
@maratal maratal requested review from ttypic and umair-ably July 26, 2025 22:40
@maratal maratal force-pushed the 315-occupancy-current branch from 1e5f227 to e4b8d13 Compare July 27, 2025 01:12
@github-actions github-actions bot temporarily deployed to staging/pull/343/AblyChat July 27, 2025 01:13 Inactive
Base automatically changed from 339-remove-implementation-class to main August 18, 2025 11:40
@maratal maratal force-pushed the 315-occupancy-current branch from e4b8d13 to 054b5d2 Compare August 18, 2025 12:00
@github-actions github-actions bot temporarily deployed to staging/pull/343/AblyChat August 18, 2025 12:01 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
Sources/AblyChat/Occupancy.swift (1)

34-34: Doc fix: use “nil” instead of “undefined” in Swift

Swift uses nil, not “undefined”. Please update the Returns doc accordingly.

Apply this diff:

-     * - Returns: The latest occupancy data, or undefined if no realtime events have been received yet.
+     * - Returns: The latest occupancy data, or nil if no realtime events have been received yet.
Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (2)

53-69: Nit: slim down the mock message to essentials

Only data["metrics"] is read by the production code; the extra fields (action, serial, clientId, version) add noise without value. Trimming them simplifies the test fixture.

Apply this diff:

 let channel = MockRealtimeChannel(
     name: "basketball::$chat",
     messageToEmitOnSubscribe: {
         let message = ARTMessage()
-        message.action = .create // arbitrary
-        message.serial = "" // arbitrary
-        message.clientId = "" // arbitrary
         message.data = [
             "metrics": [
                 "connections": 5, // arbitrary
                 "presenceMembers": 2, // arbitrary
             ],
         ]
-        message.version = "0" // arbitrary
         return message
     }()
 )

125-151: Error-path test is correct; minor typo in comment

The test correctly verifies current() throws occupancyEventsNotEnabled when events are disabled. Small typo at Line 137 (“Wnen”).

Apply this diff:

-            // Wnen
+            // When
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e4b8d13 and 054b5d2.

📒 Files selected for processing (5)
  • Example/AblyChatExample/Mocks/MockClients.swift (1 hunks)
  • Sources/AblyChat/DefaultOccupancy.swift (3 hunks)
  • Sources/AblyChat/Errors.swift (4 hunks)
  • Sources/AblyChat/Occupancy.swift (1 hunks)
  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • Sources/AblyChat/Errors.swift
  • Example/AblyChatExample/Mocks/MockClients.swift
  • Sources/AblyChat/DefaultOccupancy.swift
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The `Occupancy` protocol in the Ably Chat Swift SDK is annotated with `MainActor`, making all conforming types like `DefaultOccupancy` automatically main actor-isolated without requiring explicit annotations on their methods.
📚 Learning: 2025-05-12T21:01:14.109Z
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The `Occupancy` protocol in the Ably Chat Swift SDK is annotated with `MainActor`, making all conforming types like `DefaultOccupancy` automatically main actor-isolated without requiring explicit annotations on their methods.

Applied to files:

  • Sources/AblyChat/Occupancy.swift
  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift
📚 Learning: 2025-05-23T16:20:38.904Z
Learnt from: maratal
PR: ably/ably-chat-swift#262
File: Tests/AblyChatTests/DefaultRoomReactionsTests.swift:0-0
Timestamp: 2025-05-23T16:20:38.904Z
Learning: In Swift tests using mock objects like MockRealtimeChannel, explicit subscription cleanup (via unsubscribe() or similar methods) is generally unnecessary since the mocks don't maintain real connections and will be garbage collected after the test completes.

Applied to files:

  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift
📚 Learning: 2025-05-23T16:29:39.712Z
Learnt from: maratal
PR: ably/ably-chat-swift#262
File: Tests/AblyChatTests/DefaultRoomReactionsTests.swift:0-0
Timestamp: 2025-05-23T16:29:39.712Z
Learning: In the ably-chat-swift project, MockRealtimeChannel processes messages synchronously when subscribe is called, immediately delivering the configured messages to the callback.

Applied to files:

  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift
📚 Learning: 2025-06-14T16:19:29.327Z
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/Mocks/MockRealtime.swift:348-384
Timestamp: 2025-06-14T16:19:29.327Z
Learning: The MockRealtime class in Example/AblyChatExample/Mocks/MockRealtime.swift is specifically for example app construction, not for testing. The actual test mocks are located in the Tests directory. If example app mocks are unused, fatalError calls are appropriate to catch accidental usage.

Applied to files:

  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift
🧬 Code Graph Analysis (2)
Sources/AblyChat/Occupancy.swift (2)
Sources/AblyChat/DefaultOccupancy.swift (1)
  • current (71-79)
Example/AblyChatExample/Mocks/MockClients.swift (1)
  • current (567-569)
Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (2)
Sources/AblyChat/DefaultOccupancy.swift (2)
  • current (71-79)
  • subscribe (20-58)
Sources/AblyChat/Occupancy.swift (2)
  • subscribe (53-67)
  • subscribe (70-72)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (34)
  • GitHub Check: Example app, macOS (Xcode 16.3)
  • GitHub Check: Xcode, iOS (Xcode 16.1)
  • GitHub Check: Example app, tvOS (Xcode 16.2)
  • GitHub Check: Example app, tvOS (Xcode 16.3)
  • GitHub Check: Xcode, release configuration, tvOS (Xcode 16.2)
  • GitHub Check: Example app, macOS (Xcode 16.2)
  • GitHub Check: Example app, tvOS (Xcode 16.1)
  • GitHub Check: Example app, iOS (Xcode 16.2)
  • GitHub Check: Example app, iOS (Xcode 16.3)
  • GitHub Check: Xcode, iOS (Xcode 16.2)
  • GitHub Check: Xcode, macOS (Xcode 16.2)
  • GitHub Check: Xcode, tvOS (Xcode 16.3)
  • GitHub Check: Example app, iOS (Xcode 16.1)
  • GitHub Check: Xcode, iOS (Xcode 16.3)
  • GitHub Check: Example app, macOS (Xcode 16.1)
  • GitHub Check: Xcode, tvOS (Xcode 16.2)
  • GitHub Check: Xcode, macOS (Xcode 16.1)
  • GitHub Check: Xcode, release configuration, tvOS (Xcode 16.1)
  • GitHub Check: Xcode, macOS (Xcode 16.3)
  • GitHub Check: Xcode, release configuration, macOS (Xcode 16.3)
  • GitHub Check: Xcode, tvOS (Xcode 16.1)
  • GitHub Check: Xcode, release configuration, tvOS (Xcode 16.3)
  • GitHub Check: Xcode, release configuration, iOS (Xcode 16.3)
  • GitHub Check: Xcode, release configuration, iOS (Xcode 16.1)
  • GitHub Check: Xcode, release configuration, macOS (Xcode 16.2)
  • GitHub Check: Xcode, release configuration, iOS (Xcode 16.2)
  • GitHub Check: Xcode, release configuration, macOS (Xcode 16.1)
  • GitHub Check: SPM (Xcode 16.1)
  • GitHub Check: SPM, release configuration (Xcode 16.1)
  • GitHub Check: SPM, release configuration (Xcode 16.2)
  • GitHub Check: SPM (Xcode 16.2)
  • GitHub Check: SPM, release configuration (Xcode 16.3)
  • GitHub Check: SPM (Xcode 16.3)
  • GitHub Check: Generate code coverage
🔇 Additional comments (3)
Sources/AblyChat/Occupancy.swift (1)

31-38: Solid addition: synchronous cache-backed current() API fits the spec and actor model

The API shape looks good: current() complements get() with immediate, cached access, enforces enableEvents via typed throws, and leverages @MainActor via the protocol annotation (consistent with our prior approach).

Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (2)

10-41: Good coverage: verifies current() is nil before any realtime events

Asserting that current() returns nil after a successful get() (but before receiving any occupancy event) is exactly the expected behavior for a cache-backed API.


88-91: LGTM: confirms current() reflects last emitted occupancy

Validates that after a realtime update, the cache is populated and returned by current(). Matches the implementation that updates lastOccupancyData before invoking callbacks.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Sources/AblyChat/Occupancy.swift (1)

31-38: Doc fix: use “nil” (Swift) instead of “undefined” and reference the specific error case.

The method returns an Optional; in Swift, “nil” is the correct term (not “undefined”). Also consider explicitly naming the error case thrown for clarity.

Apply this diff to update the doc comment:

     /**
      * Get the latest occupancy data received from realtime events.
      *
-     * - Returns: The latest occupancy data, or undefined if no realtime events have been received yet.
+     * - Returns: The latest occupancy data, or nil if no realtime events have been received yet.
      *
-     * - Throws: ``ARTErrorInfo`` if occupancy events are not enabled for this room.
+     * - Throws: ``ARTErrorInfo`` (``ChatError.occupancyEventsNotEnabled``) if occupancy events are not enabled for this room.
      */
     func current() throws(ARTErrorInfo) -> OccupancyData?
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 054b5d2 and 956f65c.

📒 Files selected for processing (5)
  • Example/AblyChatExample/Mocks/MockClients.swift (1 hunks)
  • Sources/AblyChat/DefaultOccupancy.swift (3 hunks)
  • Sources/AblyChat/Errors.swift (4 hunks)
  • Sources/AblyChat/Occupancy.swift (1 hunks)
  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • Example/AblyChatExample/Mocks/MockClients.swift
  • Sources/AblyChat/DefaultOccupancy.swift
  • Sources/AblyChat/Errors.swift
  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The `Occupancy` protocol in the Ably Chat Swift SDK is annotated with `MainActor`, making all conforming types like `DefaultOccupancy` automatically main actor-isolated without requiring explicit annotations on their methods.
📚 Learning: 2025-05-12T21:01:14.109Z
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The `Occupancy` protocol in the Ably Chat Swift SDK is annotated with `MainActor`, making all conforming types like `DefaultOccupancy` automatically main actor-isolated without requiring explicit annotations on their methods.

Applied to files:

  • Sources/AblyChat/Occupancy.swift
🧬 Code Graph Analysis (1)
Sources/AblyChat/Occupancy.swift (2)
Sources/AblyChat/DefaultOccupancy.swift (1)
  • current (71-79)
Example/AblyChatExample/Mocks/MockClients.swift (1)
  • current (567-569)
🔇 Additional comments (1)
Sources/AblyChat/Occupancy.swift (1)

31-38: New protocol requirement is a source-breaking change

We confirmed that within this repo only two types conform to Occupancy and both already implement current():

  • Sources/AblyChat/DefaultOccupancy.swift
  • Example/AblyChatExample/Mocks/MockClients.swift

However, because Occupancy is a public protocol, any external client code that previously conformed to it (and didn’t implement current()) will now fail to compile. Please choose one of the following:

• Option A (preserve backwards compatibility):
Add a default implementation in a public extension Occupancy, for example:

public extension Occupancy {
  func current() throws(ARTErrorInfo) -> OccupancyData? {
    return nil
  }
}

SDK types (like DefaultOccupancy) continue to override this with their real logic.

• Option B (intentional breaking change):
Acknowledge the break, plan a semver-major release, and call it out in your release notes.

@maratal maratal merged commit abed8e1 into main Aug 18, 2025
19 checks passed
@maratal maratal deleted the 315-occupancy-current branch August 18, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Implement Occupancy.current() method

3 participants