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

fix: latestAction -> action renaming + test #85

Merged
merged 1 commit into from
Dec 6, 2024
Merged

Conversation

ttypic
Copy link
Collaborator

@ttypic ttypic commented Dec 5, 2024

Follow chat-js changes ably/ably-chat-js#427

Summary by CodeRabbit

  • New Features

    • Enhanced message handling with updated property naming for clarity.
    • Introduced a new test for sending and retrieving messages from history.
    • Updated the user interface to display context-sensitive action buttons in the chat input field.
  • Bug Fixes

    • Adjusted tests to ensure correct handling of message properties and exception logic.
  • Tests

    • Updated existing tests to reflect changes in message property names.
    • Added a new test to validate message retrieval functionality.
  • Chores

    • Updated utility function to support suspending operations for improved functionality.

@ttypic ttypic requested a review from sacOO7 December 5, 2024 21:58
Copy link

coderabbitai bot commented Dec 5, 2024

Walkthrough

The changes in this pull request primarily involve renaming the JSON field "latestAction" to "action" across multiple classes and tests within the chat-android module. This renaming affects the Message data class, the ChatApi, and the Messages interface, ensuring consistency in how message actions are handled. Additionally, a new test method is introduced to verify message sending and retrieval functionality, and the assertWaiter function is updated to support suspend functions, enhancing its usability in coroutine contexts.

Changes

File Path Change Summary
chat-android/src/main/java/com/ably/chat/ChatApi.kt Renamed JSON field from latestAction to action in getMessages and sendMessage methods.
chat-android/src/main/java/com/ably/chat/Message.kt Renamed property latestAction to action in Message data class.
chat-android/src/main/java/com/ably/chat/Messages.kt Updated subscribe method to use action instead of latestAction; refined channel state handling.
chat-android/src/test/java/com/ably/chat/ChatApiTest.kt Updated tests to reflect the change from latestAction to action in mocked API responses.
chat-android/src/test/java/com/ably/chat/MessagesTest.kt Renamed latestAction to action in tests for send and subscribe methods.
chat-android/src/test/java/com/ably/chat/SandboxTest.kt Added new test method to verify sending and retrieving messages from history.
chat-android/src/test/java/com/ably/chat/TestUtils.kt Changed assertWaiter function parameter type from () -> Boolean to suspend () -> Boolean.

Possibly related PRs

  • [ECO-5139] feat: switched API to v2 #67: The changes in ChatApi.kt regarding the renaming of the JSON field from "latestAction" to "action" are related to the modifications in the Message class and the handling of message actions in the getMessages and sendMessage methods.
  • [ECO-5147][CHA-RC3] Fix shared channel options for messages feature #75: The updates in the Messages.kt file to ensure that only messages with the MESSAGE_CREATE action are processed align with the changes made in the main PR regarding the handling of message actions.
  • [CHA-M5] Improved message subscription history implementation #78: The transition from DeferredValue to CompletableDeferred in the Messages class and tests reflects a broader improvement in message handling, which is consistent with the changes made in the main PR regarding message action handling.
  • chore: public API tweaks #80: The conversion of RoomReactionsOptions and OccupancyOptions from objects to classes may indirectly relate to the overall restructuring of message handling and options management, which is a theme present in the main PR's changes.

Suggested reviewers

  • sacOO7

🐰 In the chat where messages flow,
The actions change, as we now know.
From "latest" to "action," clear and bright,
Our code now shines, a joyful sight!
With tests to check and functions to wait,
We hop along, it’s looking great! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8fc510a and 7627409.

📒 Files selected for processing (8)
  • chat-android/src/main/java/com/ably/chat/ChatApi.kt (3 hunks)
  • chat-android/src/main/java/com/ably/chat/Message.kt (1 hunks)
  • chat-android/src/main/java/com/ably/chat/Messages.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/ChatApiTest.kt (4 hunks)
  • chat-android/src/test/java/com/ably/chat/MessagesTest.kt (2 hunks)
  • chat-android/src/test/java/com/ably/chat/SandboxTest.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/TestUtils.kt (1 hunks)
  • example/src/main/java/com/ably/chat/example/MainActivity.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • chat-android/src/main/java/com/ably/chat/Message.kt
  • chat-android/src/test/java/com/ably/chat/SandboxTest.kt
  • chat-android/src/main/java/com/ably/chat/ChatApi.kt
  • chat-android/src/test/java/com/ably/chat/ChatApiTest.kt
  • chat-android/src/test/java/com/ably/chat/TestUtils.kt
  • chat-android/src/test/java/com/ably/chat/MessagesTest.kt
  • chat-android/src/main/java/com/ably/chat/Messages.kt
🔇 Additional comments (1)
example/src/main/java/com/ably/chat/example/MainActivity.kt (1)

323-323: LGTM! Property rename aligns with PR objectives.

The change from latestAction to action in the preview function is consistent with the PR's objective.

Let's verify that this example correctly reflects the core API usage:

✅ Verification successful

Property rename from latestAction to action is consistently implemented

The verification confirms that:

  • No instances of latestAction property remain in the Kotlin codebase
  • The action property is consistently used across both the example app and core library
  • The example correctly reflects the API usage pattern seen in ChatApi.kt and other core components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Message class property rename across the codebase
# Expected: All instances of Message creation should use 'action' instead of 'latestAction'

# Search for any remaining instances of 'latestAction' in Message class usage
rg 'latestAction.*MessageAction' --type kotlin

# Search for new 'action' property usage to confirm consistent adoption
rg 'action.*=.*MessageAction' --type kotlin

Length of output: 1236


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.

Copy link

github-actions bot commented Dec 5, 2024

Code Coverage

File Coverage [88.11%]
chat-android/src/main/java/com/ably/chat/ChatApi.kt 83.19%
chat-android/src/main/java/com/ably/chat/Message.kt 100.00%
chat-android/src/main/java/com/ably/chat/Messages.kt 92.93%
Total Project Coverage 83.88%

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: 2

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

76-76: Update documentation to reflect renamed property

The documentation comment above still refers to "latest action" while the property has been renamed to action. Please update the comment to maintain consistency.

-    /**
-     * The latest action of the message. This can be used to determine if the message was created, updated, or deleted.
-     */
+    /**
+     * The action of the message. This can be used to determine if the message was created, updated, or deleted.
+     */
chat-android/src/test/java/com/ably/chat/ChatApiTest.kt (1)

35-35: LGTM! Consider adding explicit action value tests

The property rename from latestAction to action is consistently applied across all test cases. However, consider adding explicit tests for different action values (create, update, delete) to ensure the property rename handles all cases correctly.

Example test case:

@Test
fun `getMessages should handle different message actions`() = runTest {
    val actions = listOf(
        "message.create" to MessageAction.MESSAGE_CREATE,
        "message.update" to MessageAction.MESSAGE_UPDATE,
        "message.delete" to MessageAction.MESSAGE_DELETE
    )
    
    for ((actionString, expectedAction) in actions) {
        mockMessagesApiResponse(
            realtime,
            listOf(
                JsonObject().apply {
                    addProperty("serial", "timeserial")
                    addProperty("roomId", "roomId")
                    addProperty("clientId", "clientId")
                    addProperty("text", "hello")
                    addProperty("createdAt", 1_000_000)
                    addProperty("action", actionString)
                }
            )
        )

        val messages = chatApi.getMessages("roomId", QueryOptions())
        assertEquals(expectedAction, messages.items.first().action)
    }
}

Also applies to: 52-52, 69-69, 106-106

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

38-38: Consider renaming variable for consistency.

The variable name latestActionName should be renamed to actionName to maintain consistency with the new naming convention.

-            val latestActionName = it.requireJsonObject().get("action")?.asString
+            val actionName = it.requireJsonObject().get("action")?.asString
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cb58c0b and 8fc510a.

📒 Files selected for processing (7)
  • chat-android/src/main/java/com/ably/chat/ChatApi.kt (3 hunks)
  • chat-android/src/main/java/com/ably/chat/Message.kt (1 hunks)
  • chat-android/src/main/java/com/ably/chat/Messages.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/ChatApiTest.kt (4 hunks)
  • chat-android/src/test/java/com/ably/chat/MessagesTest.kt (2 hunks)
  • chat-android/src/test/java/com/ably/chat/SandboxTest.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/TestUtils.kt (1 hunks)
🔇 Additional comments (5)
chat-android/src/test/java/com/ably/chat/TestUtils.kt (1)

Line range hint 72-80: LGTM! Good enhancement to support suspend functions

The modification to accept a suspend block parameter improves the utility's flexibility for testing asynchronous operations while maintaining proper timeout and context handling.

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

131-152: LGTM! Well-structured test for message history.

The test effectively verifies message sending and retrieval functionality, with proper assertions for all relevant message properties.

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

50-50: LGTM! Consistent property renaming.

The action property is consistently used in Message construction across both methods.

Also applies to: 90-90

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

78-78: LGTM! Tests properly updated for property renaming.

The tests have been consistently updated to use the new action property name in all relevant assertions.

Also applies to: 138-138


Line range hint 38-38: Verify complete migration of property renaming.

Let's ensure no instances of latestAction remain in the codebase.

@@ -290,7 +290,7 @@ internal class DefaultMessages(
text = data.text,
metadata = data.metadata,
headers = pubSubMessage.extras.asJsonObject().get("headers")?.toMap() ?: mapOf(),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Remaining instances of latestAction found in the codebase

The verification revealed that latestAction is still being used in two files:

  • ChatApi.kt: Used as local variables (latestActionName, latestAction) for processing message actions
  • MainActivity.kt in the example app: Still using the old property name

The local variables in ChatApi.kt are fine as they serve a different purpose, but the example app needs to be updated to maintain consistency.

  • example/src/main/java/com/ably/chat/example/MainActivity.kt: Update latestAction to action in Message construction
🔗 Analysis chain

LGTM: Property renamed from latestAction to action

The renaming aligns with the PR objectives to match changes in the chat-js repository. The hardcoded MessageAction.MESSAGE_CREATE value is consistent with the message listener's action check.

Let's verify the consistent renaming across the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent renaming from latestAction to action across the codebase

# Check for any remaining instances of latestAction
echo "Checking for remaining instances of 'latestAction'..."
rg --type kotlin --type java "latestAction"

# Check for consistent usage of 'action' property in Message construction
echo "Checking Message construction patterns..."
ast-grep --pattern 'Message($$$, action = $_, $$$)'

Length of output: 7784

Comment on lines 292 to 294
headers = pubSubMessage.extras.asJsonObject().get("headers")?.toMap() ?: mapOf(),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
)
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Update needed in example app's MainActivity

The Message class constructor has been properly updated to use action parameter, but there's an inconsistency in the example app's MainActivity.kt which still uses the old latestAction parameter name. This needs to be updated to match the current Message class definition.

  • example/src/main/java/com/ably/chat/example/MainActivity.kt:323: Change latestAction = MessageAction.MESSAGE_CREATE to action = MessageAction.MESSAGE_CREATE
🔗 Analysis chain

Verify Message class constructor parameter update

While the property renaming here looks correct, we should ensure the Message class constructor has been updated to accept action instead of latestAction.

Let's verify the Message class changes:


Let me generate another verification script to check the Message class definition since the previous pattern didn't match.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Message class constructor parameter update

# Check Message class definition
echo "Checking Message class definition..."
ast-grep --pattern 'class Message($$$, action: MessageAction, $$$)'

# Check all Message instantiations
echo "Checking Message instantiations..."
ast-grep --pattern 'Message($$$)'

Length of output: 8257


Script:

#!/bin/bash
# Search for Message class definition with a more flexible pattern
echo "Checking Message class definition..."
rg -A 10 "^data class Message\b" --type kotlin

# Also check for any remaining references to latestAction
echo -e "\nChecking for latestAction references..."
rg "latestAction" --type kotlin

Length of output: 1534


Script:

#!/bin/bash
# Get more context around Message class definition
echo "Getting full Message class definition..."
rg -B 5 -A 20 "^data class Message\b" chat-android/src/main/java/com/ably/chat/Message.kt

# Get context around latestAction usage in MainActivity
echo -e "\nChecking MainActivity latestAction context..."
rg -B 5 -A 5 "latestAction = MessageAction" example/src/main/java/com/ably/chat/example/MainActivity.kt

Length of output: 1164

Copy link
Contributor

@sacOO7 sacOO7 left a comment

Choose a reason for hiding this comment

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

LGTM
Added few comments

@ttypic ttypic merged commit fa89dc8 into main Dec 6, 2024
3 checks passed
@ttypic ttypic deleted the fix-action-field branch December 6, 2024 13:00
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.

2 participants