-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement room status change upon attach or detach #37
Conversation
WalkthroughThe changes involve significant updates to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DefaultRoom
participant DefaultRoomStatus
User->>DefaultRoom: attach()
DefaultRoom->>DefaultRoomStatus: transition(to: .attached)
DefaultRoomStatus-->>DefaultRoom: status updated
DefaultRoom-->>User: Room is now attached
User->>DefaultRoom: detach()
DefaultRoom->>DefaultRoomStatus: transition(to: .detached)
DefaultRoomStatus-->>DefaultRoom: status updated
DefaultRoom-->>User: Room is now detached
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
785c765
to
d7fdf9a
Compare
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- Sources/AblyChat/Room.swift (2 hunks)
- Sources/AblyChat/RoomStatus.swift (2 hunks)
- Tests/AblyChatTests/DefaultRoomStatusTests.swift (1 hunks)
- Tests/AblyChatTests/DefaultRoomTests.swift (2 hunks)
Additional context used
Learnings (1)
Sources/AblyChat/Room.swift (1)
Learnt from: lawrence-forooghian PR: ably-labs/ably-chat-swift#9 File: Sources/AblyChat/RoomStatus.swift:3-33 Timestamp: 2024-08-28T13:01:11.701Z Learning: When reviewing code, avoid commenting on TODOs that already have a linked GitHub issue, as per the user's preference.
Additional comments not posted (13)
Tests/AblyChatTests/DefaultRoomStatusTests.swift (3)
5-9
: LGTM!The test function is correctly implemented and follows the AAA (Arrange-Act-Assert) pattern.
11-15
: LGTM!The test function is correctly implemented and follows the AAA (Arrange-Act-Assert) pattern.
17-45
: LGTM!The test function is correctly implemented and follows the AAA (Arrange-Act-Assert) pattern.
Sources/AblyChat/RoomStatus.swift (5)
4-4
: LGTM!The change to make the
current
property an asynchronous getter is approved. It aligns with the PR objective and is necessary to support the asynchronous state management in theDefaultRoomStatus
actor.
6-6
: LGTM!The change to make the
error
property an asynchronous getter is approved. It aligns with the PR objective and is necessary to support the asynchronous state management in theDefaultRoomStatus
actor.Note: The TODO comment to consider how to avoid the need for an unwrap is acknowledged. This can be revisited in a future PR.
7-7
: LGTM!The change to make the
onChange
method return aSubscription<RoomStatusChange>
asynchronously is approved. It aligns with the PR objective and is necessary to support the asynchronous state management in theDefaultRoomStatus
actor.
35-57
: LGTM!The implementation of the
DefaultRoomStatus
actor is approved. It correctly encapsulates the state management responsibilities, maintains the state, manages subscriptions, and provides a clean way to handle state transitions and notify subscribers.Note: The TODO comments to populate the
error
property and clean up old subscriptions are acknowledged. These can be addressed in future PRs.
43-47
: LGTM!The implementation of the
onChange
method within theDefaultRoomStatus
actor is approved. The synchronous implementation is correct and necessary to maintain the state of subscriptions. Creating a new subscription, appending it to thesubscriptions
array, and returning it to the caller is the appropriate approach.Sources/AblyChat/Room.swift (3)
53-55
: LGTM!The code changes are approved for the following reasons:
- Encapsulating the status management within the actor enhances data hiding and control over the status state.
- Changing the
status
property frompublic
tointernal
is a good practice to limit the visibility of the property.
73-73
: LGTM!The code changes are approved for the following reason:
- Updating the status to
.attached
during the attachment process ensures that the status of the room reflects the current state of the room more accurately.
80-80
: LGTM!The code changes are approved for the following reason:
- Updating the status to
.detached
during the detachment process ensures that the status of the room reflects the current state of the room more accurately.Tests/AblyChatTests/DefaultRoomTests.swift (2)
21-23
: LGTM!The code changes are approved. The addition of the subscription to listen for status changes and the assertion to ensure that the room's status transitions to
.attached
after theattach
method is called improve the robustness of the test by ensuring that the room's state is accurately reflected and validated during the attach process.Also applies to: 27-27, 31-38
87-89
: LGTM!The code changes are approved. The addition of the subscription to listen for status changes and the assertion to ensure that the room's status transitions to
.detached
after thedetach
method is called improve the robustness of the test by ensuring that the room's state is accurately reflected and validated during the detach process.Also applies to: 93-93, 97-104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some questions
Based on the simplified requirements described in #19. The decision from 7d6acde to use actors as the mechanism for managing mutable state means that I’ve had to make RoomStatus.{ current, error, onChange(bufferingPolicy:) } async. As mentioned there, if later on we decide this is too weird an API, then we can think of alternatives. I really wanted to avoid making DefaultRoomStatus an actor; I tried to find a way to isolate this state to the DefaultRoom actor (who logically owns this state), by trying to make the DefaultRoomStatus access the DefaultRoom-managed state, but I was not successful and didn’t want to sink much time into it. It means that DefaultRoom has suspension points in order to access its current state, which I am not happy about. But we can revisit later, perhaps armed with more knowledge of concurrency and in less of a rush to get some initial functionality implemented. Resolves #19.
d7fdf9a
to
a63b22b
Compare
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- Sources/AblyChat/Room.swift (3 hunks)
- Sources/AblyChat/RoomStatus.swift (2 hunks)
- Tests/AblyChatTests/DefaultRoomStatusTests.swift (1 hunks)
- Tests/AblyChatTests/DefaultRoomTests.swift (2 hunks)
Files skipped from review as they are similar to previous changes (4)
- Sources/AblyChat/Room.swift
- Sources/AblyChat/RoomStatus.swift
- Tests/AblyChatTests/DefaultRoomStatusTests.swift
- Tests/AblyChatTests/DefaultRoomTests.swift
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Based on the simplified requirements described in #19.
The decision from 7d6acde to use actors as the mechanism for managing mutable state means that I’ve had to make
RoomStatus.{ current, error, onChange(bufferingPolicy:) }
async. As mentioned there, if later on we decide this is too weird an API, then we can think of alternatives.I really wanted to avoid making
DefaultRoomStatus
an actor; I tried to find a way to isolate this state to theDefaultRoom
actor (who logically owns this state), by trying to make theDefaultRoomStatus
access theDefaultRoom
-managed state, but I was not successful and didn’t want to sink much time into it. It means thatDefaultRoom
has suspension points in order to access its current state, which I am not happy about. But we can revisit later, perhaps armed with more knowledge of concurrency and in less of a rush to get some initial functionality implemented.Resolves #19.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
DefaultRoomStatus
class to validate initialization and state transitions.DefaultRoom
class to verify status changes during attach and detach processes.