Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-4936] Implement the ability to attach and detach a room #20

Conversation

ruancomelli
Copy link
Collaborator

Based on the simplified requirements described in #19. This doesn’t include the emission of a room status change; will do that in a separate PR.

Summary by CodeRabbit

  • New Features

    • Introduced a new mock implementation for real-time channels, enhancing testing capabilities.
    • Added asynchronous methods for attaching and detaching channels, improving usability within Swift's concurrency model.
    • Implemented new protocols for real-time client interactions, streamlining channel management.
  • Bug Fixes

    • Improved error handling in the attach and detach methods to ensure consistent behavior during failures.
  • Tests

    • Added unit tests for the DefaultRoom class to validate channel attachment and detachment functionality.

I didn’t know about this feature in 646c220.
Based on the simplified requirements described in #19. This doesn’t
include the emission of a room status change; will do that in a separate
PR.
@ruancomelli
Copy link
Collaborator Author

This is an experiment review for experiment multiple_mermaid_diagram_types
Run ID: multiple_mermaid_diagram_types/run_2024-10-01T15-06-26_v1-23-0-47-g5ce327d76-dirty
The benchmark review for this pull request can be found at #12.
This pull request was cloned from https://github.com/ably-labs/ably-chat-swift/pull/35. (Note: the URL is not a link to avoid triggering a notification on the original pull request.)

Experiment configuration
review_config:
  # User configuration for the review
  # - benchmark - use the user config from the benchmark reviews
  # - <value> - use the value directly
  user_review_config:
    enable_ai_review: true
    enable_rule_comments: false

    enable_complexity_comments: false
    enable_security_comments: false
    enable_tests_comments: false
    enable_comment_suggestions: false
    enable_functionality_review: false

    enable_pull_request_summary: false
    enable_review_guide: true

    enable_approvals: false

  ai_review_config:
    # The model responses to use for the experiment
    # - benchmark - use the model responses from the benchmark reviews
    # - llm - call the language model to generate responses
    model_responses:
      comments_model: benchmark
      comment_area_model: benchmark
      comment_validation_model: benchmark
      comment_suggestion_model: benchmark
      complexity_model: benchmark
      functionality_model: benchmark
      security_model: benchmark
      tests_model: benchmark
      pull_request_summary_model: benchmark
      review_guide_model: llm
      overall_comments_model: benchmark

# The pull request dataset to run the experiment on
pull_request_dataset:
  # Sourcery core examples:
- https://github.com/sourcery-ai/core/pull/4607
- https://github.com/sourcery-ai/core/pull/4631
- https://github.com/sourcery-ai/core/pull/4647
  # CodeRabbit examples:
- https://github.com/2lambda123/-Orange-OpenSource-oorobot/pull/15
- https://github.com/2lambda123/galaxyproject-galaxy/pull/12
- https://github.com/a0v0/avtoolz/pull/79
- https://github.com/adityask98/Hotaru/pull/10
- https://github.com/agdas/vscode/pull/2
- https://github.com/agluszak/hirschgarten/pull/2
- https://github.com/alexsnow348/insightface/pull/46
- https://github.com/alikuxac/utilities/pull/10
- https://github.com/AlphaDev87/timba-api/pull/49
- https://github.com/AngeloTadeucci/Maple2/pull/239
- https://github.com/AngeloTadeucci/Maple2.File/pull/36
- https://github.com/AngeloTadeucci/Maple2/pull/233
  # Examples where CodeRabbit does not generate diagrams
- https://github.com/baptisteArno/typebot.io/pull/1778
- https://github.com/btipling/foundations/pull/33
- https://github.com/btipling/foundations/pull/31
- https://github.com/chintu-777/jaeger/pull/1
- https://github.com/coji/remix-docs-ja/pull/55
- https://github.com/DaveMBush/SmartNgRX/pull/622
- https://github.com/DaveMBush/SmartNgRX/pull/481
- https://github.com/dkittle/party-connections/pull/6
- https://github.com/Drajad-Kusuma-Adi/onstudy-backend/pull/6
- https://github.com/imaami/libcanth/pull/2
  # Requested by Tim
- https://github.com/2lambda123/-Orange-OpenSource-oorobot/pull/15
- https://github.com/2lambda123/galaxyproject-galaxy/pull/12
- https://github.com/a0v0/avtoolz/pull/79
- https://github.com/adityask98/Hotaru/pull/10
- https://github.com/agdas/vscode/pull/2
- https://github.com/agluszak/hirschgarten/pull/2
- https://github.com/4DNucleome/PartSeg/pull/1183
- https://github.com/ably/ably-cocoa/pull/1973
- https://github.com/ably-labs/ably-chat-swift/pull/54
- https://github.com/ably-labs/ably-chat-swift/pull/35
  # A ton of new classes:
- https://github.com/sourcery-ai/core/pull/4618
  # Including database changes to evaluate entity-relationship diagrams
- https://github.com/sourcery-ai/core/pull/4579
  # TODO: find some with Alembic
  # Brilliant existing examples:
- https://github.com/sourcery-ai/core/pull/4680
- https://github.com/sourcery-ai/core/pull/4684

# Questions to ask to label the review comments
review_comment_labels: []
# - label: correct
#   question: Is this comment correct?

# Benchmark reviews generated by running
#   python -m scripts.experiment benchmark <experiment_name>
benchmark_reviews:
- dataset_pull_request: https://github.com/sourcery-ai/core/pull/4607
  review_pull_request: https://github.com/sourcery-ai-experiments/core/pull/374
- dataset_pull_request: https://github.com/sourcery-ai/core/pull/4631
  review_pull_request: https://github.com/sourcery-ai-experiments/core/pull/375
- dataset_pull_request: https://github.com/sourcery-ai/core/pull/4647
  review_pull_request: https://github.com/sourcery-ai-experiments/core/pull/376
- dataset_pull_request: https://github.com/2lambda123/-Orange-OpenSource-oorobot/pull/15
  review_pull_request: https://github.com/sourcery-ai-experiments/-Orange-OpenSource-oorobot/pull/5
- dataset_pull_request: https://github.com/2lambda123/galaxyproject-galaxy/pull/12
  review_pull_request: https://github.com/sourcery-ai-experiments/galaxyproject-galaxy/pull/13
- dataset_pull_request: https://github.com/adityask98/Hotaru/pull/10
  review_pull_request: https://github.com/sourcery-ai-experiments/Hotaru/pull/14
- dataset_pull_request: https://github.com/agdas/vscode/pull/2
  review_pull_request: https://github.com/sourcery-ai-experiments/vscode/pull/14
- dataset_pull_request: https://github.com/agluszak/hirschgarten/pull/2
  review_pull_request: https://github.com/sourcery-ai-experiments/hirschgarten/pull/13
- dataset_pull_request: https://github.com/alikuxac/utilities/pull/10
  review_pull_request: https://github.com/sourcery-ai-experiments/utilities/pull/4
- dataset_pull_request: https://github.com/AlphaDev87/timba-api/pull/49
  review_pull_request: https://github.com/sourcery-ai-experiments/timba-api/pull/12
- dataset_pull_request: https://github.com/AngeloTadeucci/Maple2/pull/239
  review_pull_request: https://github.com/sourcery-ai-experiments/Maple2/pull/23
- dataset_pull_request: https://github.com/AngeloTadeucci/Maple2.File/pull/36
  review_pull_request: https://github.com/sourcery-ai-experiments/Maple2.File/pull/12
- dataset_pull_request: https://github.com/AngeloTadeucci/Maple2/pull/233
  review_pull_request: https://github.com/sourcery-ai-experiments/Maple2/pull/24
- dataset_pull_request: https://github.com/baptisteArno/typebot.io/pull/1778
  review_pull_request: https://github.com/sourcery-ai-experiments/typebot.io/pull/7
- dataset_pull_request: https://github.com/btipling/foundations/pull/33
  review_pull_request: https://github.com/sourcery-ai-experiments/foundations/pull/13
- dataset_pull_request: https://github.com/btipling/foundations/pull/31
  review_pull_request: https://github.com/sourcery-ai-experiments/foundations/pull/14
- dataset_pull_request: https://github.com/chintu-777/jaeger/pull/1
  review_pull_request: https://github.com/sourcery-ai-experiments/jaeger/pull/7
- dataset_pull_request: https://github.com/coji/remix-docs-ja/pull/55
  review_pull_request: https://github.com/sourcery-ai-experiments/remix-docs-ja/pull/7
- dataset_pull_request: https://github.com/DaveMBush/SmartNgRX/pull/622
  review_pull_request: https://github.com/sourcery-ai-experiments/SmartNgRX/pull/13
- dataset_pull_request: https://github.com/DaveMBush/SmartNgRX/pull/481
  review_pull_request: https://github.com/sourcery-ai-experiments/SmartNgRX/pull/14
- dataset_pull_request: https://github.com/dkittle/party-connections/pull/6
  review_pull_request: https://github.com/sourcery-ai-experiments/party-connections/pull/7
- dataset_pull_request: https://github.com/Drajad-Kusuma-Adi/onstudy-backend/pull/6
  review_pull_request: https://github.com/sourcery-ai-experiments/onstudy-backend/pull/7
- dataset_pull_request: https://github.com/imaami/libcanth/pull/2
  review_pull_request: https://github.com/sourcery-ai-experiments/libcanth/pull/7
- dataset_pull_request: https://github.com/2lambda123/-Orange-OpenSource-oorobot/pull/15
  review_pull_request: https://github.com/sourcery-ai-experiments/-Orange-OpenSource-oorobot/pull/6
- dataset_pull_request: https://github.com/2lambda123/galaxyproject-galaxy/pull/12
  review_pull_request: https://github.com/sourcery-ai-experiments/galaxyproject-galaxy/pull/14
- dataset_pull_request: https://github.com/adityask98/Hotaru/pull/10
  review_pull_request: https://github.com/sourcery-ai-experiments/Hotaru/pull/15
- dataset_pull_request: https://github.com/agdas/vscode/pull/2
  review_pull_request: https://github.com/sourcery-ai-experiments/vscode/pull/15
- dataset_pull_request: https://github.com/agluszak/hirschgarten/pull/2
  review_pull_request: https://github.com/sourcery-ai-experiments/hirschgarten/pull/14
- dataset_pull_request: https://github.com/4DNucleome/PartSeg/pull/1183
  review_pull_request: https://github.com/sourcery-ai-experiments/PartSeg/pull/7
- dataset_pull_request: https://github.com/ably/ably-cocoa/pull/1973
  review_pull_request: https://github.com/sourcery-ai-experiments/ably-cocoa/pull/6
- dataset_pull_request: https://github.com/ably-labs/ably-chat-swift/pull/54
  review_pull_request: https://github.com/sourcery-ai-experiments/ably-chat-swift/pull/11
- dataset_pull_request: https://github.com/ably-labs/ably-chat-swift/pull/35
  review_pull_request: https://github.com/sourcery-ai-experiments/ably-chat-swift/pull/12
- dataset_pull_request: https://github.com/sourcery-ai/core/pull/4579
  review_pull_request: https://github.com/sourcery-ai-experiments/core/pull/377

@SourceryAI
Copy link

SourceryAI commented Oct 1, 2024

Reviewer's Guide by Sourcery

This pull request implements the ability to attach and detach a room in the Ably Chat SDK. It introduces new protocols for real-time client interactions, adds asynchronous methods for attaching and detaching channels, and includes unit tests for the new functionality. The changes also include some refactoring and improvements to the existing mock implementations.

Class diagram for MockRealtime and related classes

classDiagram
    class MockRealtime {
        +Channels channels
        +init(options: ARTClientOptions)
        +init(key: String)
        +init(token: String)
        +init(channels: MockChannels)
        +static create(channels: MockChannels) MockRealtime
    }
    class Channels {
        +get(name: String) Channel
        +exists(name: String) Bool
        +release(name: String, callback: ARTCallback)
        +release(name: String)
    }
    class Channel {
        +ARTRealtimeChannelState state
        +ARTErrorInfo errorReason
        +ARTRealtimeChannelOptions options
        +attach()
        +attach(callback: ARTCallback)
        +detach()
        +detach(callback: ARTCallback)
        +subscribe(callback: ARTMessageCallback) ARTEventListener
        +unsubscribe()
        +unsubscribe(listener: ARTEventListener)
        +unsubscribe(name: String, listener: ARTEventListener)
        +history(query: ARTRealtimeHistoryQuery, callback: ARTPaginatedMessagesCallback)
        +setOptions(options: ARTRealtimeChannelOptions, callback: ARTCallback)
        +on(event: ARTChannelEvent, callback: ARTChannelStateChange) ARTEventListener
        +once(event: ARTChannelEvent, callback: ARTChannelStateChange) ARTEventListener
        +off(event: ARTChannelEvent, listener: ARTEventListener)
        +off(listener: ARTEventListener)
        +off()
        +String name
        +publish(name: String, data: Any)
        +publish(name: String, data: Any, callback: ARTCallback)
        +publish(name: String, data: Any, clientId: String)
        +publish(name: String, data: Any, clientId: String, callback: ARTCallback)
        +publish(name: String, data: Any, extras: ARTJsonCompatible)
        +publish(name: String, data: Any, extras: ARTJsonCompatible, callback: ARTCallback)
        +publish(name: String, data: Any, clientId: String, extras: ARTJsonCompatible)
        +publish(name: String, data: Any, clientId: String, extras: ARTJsonCompatible, callback: ARTCallback)
        +publish(messages: [ARTMessage])
        +publish(messages: [ARTMessage], callback: ARTCallback)
        +history(callback: ARTPaginatedMessagesCallback)
    }
    MockRealtime --> Channels
    Channels --> Channel
Loading

Class diagram for DefaultRoom and related extensions

classDiagram
    class DefaultRoom {
        +attach() async throws
        +detach() async throws
    }
    class ARTRealtimeChannelProtocol {
        +attachAsync() async throws
        +detachAsync() async throws
    }
    DefaultRoom --> ARTRealtimeChannelProtocol : uses
    ARTRealtimeChannelProtocol <|-- RealtimeChannelProtocol
    RealtimeChannelProtocol <|-- MockRealtimeChannel
    MockRealtimeChannel --> AttachOrDetachResult
    class AttachOrDetachResult {
        +success
        +failure(ARTErrorInfo)
        +performCallback(callback: ARTCallback)
    }
Loading

Class diagram for RealtimeClientProtocol and related protocols

classDiagram
    class RealtimeClientProtocol {
        +Channels channels
    }
    class RealtimeChannelsProtocol {
        +Channel get(name: String)
    }
    class RealtimeChannelProtocol {
    }
    RealtimeClientProtocol --> RealtimeChannelsProtocol : has
    RealtimeChannelsProtocol --> RealtimeChannelProtocol : has
    RealtimeClientProtocol <|.. ARTRealtime
    RealtimeChannelsProtocol <|.. ARTRealtimeChannels
    RealtimeChannelProtocol <|.. ARTRealtimeChannel
Loading

File-Level Changes

Change Details Files
Implemented attach and detach functionality for rooms
  • Added attach() and detach() methods to DefaultRoom class
  • Implemented channels() method to fetch channels contributing to a room
  • Added asynchronous attachAsync() and detachAsync() extensions for ARTRealtimeChannelProtocol
Sources/AblyChat/Room.swift
Sources/AblyChat/AblyCocoaExtensions/Ably+Concurrency.swift
Introduced new protocols for real-time client interactions
  • Created RealtimeClientProtocol, RealtimeChannelsProtocol, and RealtimeChannelProtocol
  • Updated existing types to conform to new protocols
  • Refactored MockRealtime to implement RealtimeClientProtocol
Sources/AblyChat/Dependencies.swift
Sources/AblyChat/AblyCocoaExtensions/Ably+Dependencies.swift
Example/AblyChatExample/Mocks/MockRealtime.swift
Tests/AblyChatTests/Mocks/MockRealtime.swift
Added unit tests for DefaultRoom
  • Created tests for successful and failing attach scenarios
  • Created tests for successful and failing detach scenarios
  • Implemented MockRealtimeChannel and MockChannels for testing
Tests/AblyChatTests/DefaultRoomTests.swift
Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift
Tests/AblyChatTests/Mocks/MockChannels.swift
Refactored and improved existing code
  • Updated ChatClient to use RealtimeClientProtocol
  • Improved error handling in ProcessRunner
  • Made minor adjustments to improve Swift 6 compatibility
Sources/AblyChat/ChatClient.swift
Sources/BuildTool/ProcessRunner.swift
Sources/AblyChat/AblyCocoaExtensions/Ably+Dependencies.swift

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@SourceryAI SourceryAI left a comment

Choose a reason for hiding this comment

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

Hey @ruancomelli - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider tracking the TODOs in the issue tracker to ensure they're not forgotten.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Documentation: all looks good

LangSmith trace

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ruancomelli ruancomelli closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants