Fix incorrect validation for searchMessages parameters#6180
Fix incorrect validation for searchMessages parameters#6180VelikovPetar merged 2 commits intodevelopfrom
Conversation
Co-Authored-By: Claude <[email protected]>
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
SDK Size Comparison 📏
|
|
WalkthroughThe searchMessages API validation logic is modified to allow combining offset with sort parameters, while maintaining the prohibition against using offset and next together. Error handling is updated with a more specific error message for this constraint. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
> [!CAUTION]
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientGeneralApiTests.kt (1)
235-251:⚠️ Potential issue | 🟡 MinorUse backtick test name per project coding guidelines.
The renamed test uses plain camelCase instead of the required backtick style.
✏️ Suggested rename
- fun searchMessagesWithNextAndSort() = runTest { + fun `search messages with next and sort succeeds`() = runTest {As per coding guidelines: "Use backtick test names (for example:
fun \message list filters muted channels`()`) for readability."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientGeneralApiTests.kt` around lines 235 - 251, The test function searchMessagesWithNextAndSort uses camelCase but should follow project guidelines and be renamed to a backtick-style test name (e.g. fun `search messages with next and sort`())—update the function declaration for searchMessagesWithNextAndSort to a backtick-wrapped descriptive name, leaving the test body (Fixture setup, givenSearchMessagesResult, sut.get(), sut.searchMessages(...).await(), and verifySuccess(result, response)) unchanged so references like Fixture, givenSearchMessagesResult, searchMessages, and verifySuccess still work.stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt (1)
1733-1749:⚠️ Potential issue | 🟡 MinorUpdate stale KDoc after the validation relaxation.
Three documentation statements now contradict the new behavior:
- Line 1737 (body): "You will not be able to sort using limit and offset." —
sortis now permitted alongsideoffset.- Line 1746 (
@param offset): "cannot be used with sort or next" — should read "cannot be used with next".- Line 1749 (
@param sort): "cannot be used with non-zero offset" — restriction no longer exists.📝 Suggested KDoc update
* Limit and offset will allow you to access up to 1000 results matching your query. - * You will not be able to sort using limit and offset. The results will instead be - * sorted by relevance and message ID. + * Note: using offset with next is not permitted. * * Next pagination will allow you to access all search results that match your query, * and you will be able to sort using any filter-able fields and custom fields. * Pages of sort results will be returned with **next** and **previous** strings which * can be supplied as a next parameter when making a query to get a new page of results. * * `@param` channelFilter Channel filter conditions. * `@param` messageFilter Message filter conditions. - * `@param` offset Pagination offset, cannot be used with sort or next. + * `@param` offset Pagination offset, cannot be used with next. * `@param` limit The number of messages to return. - * `@param` next Pagination parameter, cannot be used with non-zero offset. - * `@param` sort The sort criteria applied to the result, cannot be used with non-zero offset. + * `@param` next Pagination parameter, cannot be used with non-zero offset. + * `@param` sort The sort criteria applied to the result.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt` around lines 1733 - 1749, The KDoc for the ChatClient method that accepts channelFilter, messageFilter, offset, limit, next, and sort is stale after validation changes: remove or update the sentence "You will not be able to sort using limit and offset.", change the `@param` offset description from "cannot be used with sort or next" to "cannot be used with next", and remove the restriction text from `@param` sort (no longer "cannot be used with non-zero offset"); update these comments above the method (the KDoc for the search/queries method in ChatClient.kt) to reflect that sort is allowed with offset and only next conflicts with offset.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt`:
- Around line 1733-1749: The KDoc for the ChatClient method that accepts
channelFilter, messageFilter, offset, limit, next, and sort is stale after
validation changes: remove or update the sentence "You will not be able to sort
using limit and offset.", change the `@param` offset description from "cannot be
used with sort or next" to "cannot be used with next", and remove the
restriction text from `@param` sort (no longer "cannot be used with non-zero
offset"); update these comments above the method (the KDoc for the
search/queries method in ChatClient.kt) to reflect that sort is allowed with
offset and only next conflicts with offset.
In
`@stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientGeneralApiTests.kt`:
- Around line 235-251: The test function searchMessagesWithNextAndSort uses
camelCase but should follow project guidelines and be renamed to a
backtick-style test name (e.g. fun `search messages with next and
sort`())—update the function declaration for searchMessagesWithNextAndSort to a
backtick-wrapped descriptive name, leaving the test body (Fixture setup,
givenSearchMessagesResult, sut.get(), sut.searchMessages(...).await(), and
verifySuccess(result, response)) unchanged so references like Fixture,
givenSearchMessagesResult, searchMessages, and verifySuccess still work.
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.ktstream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientGeneralApiTests.kt
|
🚀 Available in v6.33.0 |



Goal
Fix an incorrect front-end validation in
searchMessagesthat was rejecting valid parameter combinations.The validation was incorrectly blocking requests that used both
sortandnextparameters together, even though this is a valid combination. Onlyoffsetandnextshould be mutually exclusive.Implementation
offset != null && (sort != null || next != null)tooffset != null && next != nullsortwith eitheroffsetornextpaginationUI Changes
No UI changes.
Testing
ChatClient.searchMessageswithoffset+sort- it should return results.Summary by CodeRabbit