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-5147][CHA-RC3] Fix shared channel options for messages feature #75

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

sacOO7
Copy link
Contributor

@sacOO7 sacOO7 commented Dec 2, 2024

  1. Updated DefaultMessages constructor to accept 'room` as the only argument
  2. Updated DefaultMessages.channel to accept merged options across shared features
  3. Added extention method to 'RoomOptions', messagesChannelOptions, merged modes from all shared channels ( presence and occupancy )
  4. Fixed unit/integration tests related to Messages feature

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced messaging functionality with improved error handling and dynamic channel configuration.
    • Simplified channel initialization for occupancy management.
    • Added a test class for validating shared channel functionality within room features.
  • Bug Fixes

    • Improved error reporting for accessing uninitialized properties in room management.
  • Tests

    • Streamlined mock creation for message handling tests.
    • Added new tests to ensure shared channel logic functions correctly.

Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces significant refactoring across several classes in the chat-android module, particularly focusing on the Messages, Occupancy, and Room functionalities. Key changes include the consolidation of parameters in constructors, improved error handling, and the introduction of new methods for channel options configuration. The DefaultMessages and DefaultOccupancy classes now utilize a DefaultRoom instance for better encapsulation. Additionally, new tests have been added to validate the shared channel functionality, ensuring that channel options are merged correctly and utilized efficiently.

Changes

File Path Change Summary
chat-android/src/main/java/com/ably/chat/Messages.kt Refactored DefaultMessages to use DefaultRoom, updated channel type, improved error handling in subscribe method.
chat-android/src/main/java/com/ably/chat/Occupancy.kt Simplified channel initialization to use room.messages.channel, retained error handling.
chat-android/src/main/java/com/ably/chat/Room.kt Updated messages property initialization in DefaultRoom, added error handling for feature accessors.
chat-android/src/main/java/com/ably/chat/RoomOptions.kt Changed visibility of validateRoomOptions to internal, added messagesChannelOptions method for channel configuration.
chat-android/src/test/java/com/ably/chat/MessagesTest.kt Updated mock creation methods for tests, streamlined setup logic, removed unused imports.
chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt Added new test class for validating shared channel functionality with assertions on channel options.
chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt Modified createRoomFeatureMocks to pass room object directly to DefaultMessages.

Assessment against linked issues

Objective Addressed Explanation
Merge channel options for shared channels (68, ECO-5147)
Ensure channel options are requested only once (68, ECO-5147)

Possibly related PRs

Suggested reviewers

  • ttypic

Poem

In the chat room where messages flow,
A new structure helps us grow.
Channels merged, options aligned,
With clearer paths, our code refined.
Hops of joy, let’s celebrate,
For better chats, we can’t wait! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 900e607 and 73333df.

📒 Files selected for processing (7)
  • chat-android/src/main/java/com/ably/chat/Messages.kt (2 hunks)
  • chat-android/src/main/java/com/ably/chat/Occupancy.kt (1 hunks)
  • chat-android/src/main/java/com/ably/chat/Room.kt (1 hunks)
  • chat-android/src/main/java/com/ably/chat/RoomOptions.kt (2 hunks)
  • chat-android/src/test/java/com/ably/chat/MessagesTest.kt (2 hunks)
  • chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • chat-android/src/main/java/com/ably/chat/Occupancy.kt
  • chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt
  • chat-android/src/test/java/com/ably/chat/MessagesTest.kt
  • chat-android/src/main/java/com/ably/chat/Room.kt
👮 Files not reviewed due to content moderation or server errors (3)
  • chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt
  • chat-android/src/main/java/com/ably/chat/RoomOptions.kt
  • chat-android/src/main/java/com/ably/chat/Messages.kt
🧰 Additional context used
📓 Learnings (1)
chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt (1)
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#75
File: chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt:43-45
Timestamp: 2024-12-02T12:10:18.954Z
Learning: In the `RoomFeatureSharedChannelTest.kt` tests, prefer using assertions like `Assert.assertEquals` that provide detailed error messages over general assertions like `Assert.assertTrue`, to aid in debugging when a test fails due to a missing mode.

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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

@sacOO7 sacOO7 changed the title [ECO-5147][CHA-RC3] Fix channel options for shared channels [ECO-5147][CHA-RC3] Fix shared channel options for messages feature Dec 2, 2024
Copy link

github-actions bot commented Dec 2, 2024

@sacOO7 sacOO7 force-pushed the feature/shared-channel-modes-options branch from 09b8306 to 900e607 Compare December 2, 2024 12:00
@sacOO7 sacOO7 marked this pull request as ready for review December 2, 2024 12:04
@sacOO7 sacOO7 requested a review from ttypic December 2, 2024 12:04
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: 1

🧹 Outside diff range and nitpick comments (1)
chat-android/src/test/java/com/ably/chat/MessagesTest.kt (1)

38-46: Consider adding tests for shared channel options

While the setup is cleaner, consider adding test cases to verify that channel options are properly merged when shared features are enabled.

Example test case:

@Test
fun `should merge channel options from shared features`() = runTest {
    // Given room with multiple features enabled
    val room = createMockRoom(
        "room1",
        options = RoomOptions(
            presence = PresenceOptions(),
            occupancy = OccupancyOptions()
        ),
        realtimeClient = realtimeClient,
        chatApi = chatApi
    )
    val messages = DefaultMessages(room)
    
    // When getting channel options
    val channelOptions = messages.channel.options
    
    // Then options should include modes from all features
    assertEquals(true, channelOptions.modes.contains("presence"))
    assertEquals(true, channelOptions.modes.contains("occupancy"))
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 52dee53 and 900e607.

📒 Files selected for processing (7)
  • chat-android/src/main/java/com/ably/chat/Messages.kt (2 hunks)
  • chat-android/src/main/java/com/ably/chat/Occupancy.kt (1 hunks)
  • chat-android/src/main/java/com/ably/chat/Room.kt (1 hunks)
  • chat-android/src/main/java/com/ably/chat/RoomOptions.kt (2 hunks)
  • chat-android/src/test/java/com/ably/chat/MessagesTest.kt (2 hunks)
  • chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt (1 hunks)
🧰 Additional context used
📓 Learnings (1)
chat-android/src/main/java/com/ably/chat/Occupancy.kt (1)
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#66
File: chat-android/src/main/java/com/ably/chat/Occupancy.kt:145-145
Timestamp: 2024-11-28T11:11:20.423Z
Learning: In `chat-android/src/main/java/com/ably/chat/Occupancy.kt`, within the `DefaultOccupancy` class, when methods use `room.chatApi`, which utilizes the REST API, there's no need to call `room.ensureAttached()` before performing the operation.
🔇 Additional comments (12)
chat-android/src/main/java/com/ably/chat/Messages.kt (5)

7-7: Import statement is appropriate

The import of io.ably.lib.realtime.Channel is necessary for the updated channel property.


214-215: Consolidating constructor parameters improves encapsulation

Passing the DefaultRoom instance to DefaultMessages simplifies the constructor and enhances encapsulation by reducing parameter clutter.


223-230: Initializing properties from room improves cohesion

Using properties directly from the room instance ensures consistency and reduces redundancy in accessing shared resources like roomId, chatApi, and realtimeChannels.


237-237: Channel name construction is correct

The messagesChannelName is correctly constructed using the roomId and the chat message identifiers.


239-239: Channel initialization with merged options is appropriate

Initializing channel with room.options.messagesChannelOptions() ensures that channel options are properly merged for shared features like presence and occupancy.

chat-android/src/main/java/com/ably/chat/RoomOptions.kt (2)

95-95: Changing validateRoomOptions visibility to internal improves encapsulation

Making validateRoomOptions internal restricts its accessibility to within the module, enhancing encapsulation and preventing unintended external usage.


103-127: Addition of messagesChannelOptions method enhances channel configuration

The new messagesChannelOptions method correctly merges channel options from presence and occupancy settings, facilitating the configuration of shared channels.

chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt (1)

101-101: Refactored instantiation of DefaultMessages aligns with updated constructor

Passing the room directly to DefaultMessages simplifies the test setup and ensures consistency with the updated constructor in the main codebase.

chat-android/src/main/java/com/ably/chat/Occupancy.kt (1)

86-86: Utilizing shared channel for occupancy aligns with shared channel strategy

Assigning room.messages.channel to the channel property ensures that DefaultOccupancy uses the shared channel, promoting consistency across features and adhering to the shared channel design.

chat-android/src/main/java/com/ably/chat/Room.kt (1)

130-130: LGTM: Simplified DefaultMessages initialization improves design

The simplified constructor reduces parameter coupling and allows DefaultMessages to access room configuration directly, which is essential for proper shared channel options handling.

Let's verify that DefaultMessages is using the room parameter correctly:

✅ Verification successful

Verified: DefaultMessages correctly uses room parameter for channel configuration

The implementation shows that DefaultMessages properly uses the room parameter to access channel options through room.options.messagesChannelOptions() when initializing the channel. This confirms that the simplified constructor change is working as intended, allowing DefaultMessages to access room configuration directly for proper shared channel options handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify DefaultMessages implementation uses room parameter
# Expected: DefaultMessages should access room.options for channel configuration

ast-grep --pattern 'class DefaultMessages {
  $$$
  val channel = $room.$$$
  $$$
}'

Length of output: 86


Script:

#!/bin/bash
# Let's try a broader search for DefaultMessages class implementation
ast-grep --pattern 'class DefaultMessages($$$) {
  $$$
}'

# Also search for any usage of room parameter within DefaultMessages
rg "class DefaultMessages.*\{" -A 20

Length of output: 98


Script:

#!/bin/bash
# Let's try finding the DefaultMessages file first
fd "DefaultMessages.kt"

# Then search for room usage in all Kotlin files
rg "DefaultMessages.*room.*" --type kotlin

Length of output: 422


Script:

#!/bin/bash
# Search for DefaultMessages implementation in chat-android/src/main/java/
rg "class DefaultMessages" -A 10 --type kotlin chat-android/src/main/java/

# Also search for Messages interface to understand the contract
rg "interface Messages" -A 10 --type kotlin chat-android/src/main/java/

Length of output: 4107


Script:

#!/bin/bash
# Let's check how DefaultMessages uses the room parameter to access channel or options
rg "val channel.*=.*" --type kotlin chat-android/src/main/java/com/ably/chat/Messages.kt -A 5

# Also check for any room.options usage
rg "room\.options" --type kotlin chat-android/src/main/java/com/ably/chat/Messages.kt

Length of output: 590

chat-android/src/test/java/com/ably/chat/MessagesTest.kt (2)

3-6: LGTM: Improved test setup with centralized mock utilities

The use of mock creation utilities improves test maintainability and consistency.

Also applies to: 30-31


Line range hint 49-249: LGTM: Existing test coverage remains comprehensive

The test suite maintains good coverage of core messaging functionality including message sending, subscription handling, and validation rules.

1. Updated DefaultMessages constructor to accept 'room` as the only argument
2. Updated DefaultMessages.channel to accept merged options across shared features
3. Added extention method to 'RoomOptions', messagesChannelOptions, merged
modes from all shared channels ( presence and occupancy )
4. Fixed unit/integration tests related to Messages feature
5. Added test to check shared channel is accessed only once with combined modes+params
@sacOO7 sacOO7 force-pushed the feature/shared-channel-modes-options branch from 900e607 to 73333df Compare December 2, 2024 12:15
@sacOO7 sacOO7 requested review from AndyTWF and removed request for AndyTWF December 2, 2024 14:26
Copy link
Collaborator

@ttypic ttypic left a comment

Choose a reason for hiding this comment

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

LGTM

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.

[CHA-RC3] Channel options / modes overwritten
2 participants