Skip to content

Fix incorrect validation for searchMessages parameters#6180

Merged
VelikovPetar merged 2 commits intodevelopfrom
bug/AND-1086_fix_wrong_search_messages_front_end_check
Feb 25, 2026
Merged

Fix incorrect validation for searchMessages parameters#6180
VelikovPetar merged 2 commits intodevelopfrom
bug/AND-1086_fix_wrong_search_messages_front_end_check

Conversation

@VelikovPetar
Copy link
Contributor

@VelikovPetar VelikovPetar commented Feb 23, 2026

Goal

Fix an incorrect front-end validation in searchMessages that was rejecting valid parameter combinations.

The validation was incorrectly blocking requests that used both sort and next parameters together, even though this is a valid combination. Only offset and next should be mutually exclusive.

Implementation

  • Changed the validation condition from offset != null && (sort != null || next != null) to offset != null && next != null
  • This allows using sort with either offset or next pagination
  • Updated error message to be clearer: "Cannot use both offset and next values. Specify only one of these options."
  • Updated unit tests to reflect the correct behavior

UI Changes

No UI changes.

Testing

  • Call ChatClient.searchMessages with offset+sort - it should return results.

Summary by CodeRabbit

  • Bug Fixes
    • Improved searchMessages parameter validation to better reflect supported parameter combinations. The method now allows offset with sort parameters, previously prohibited. Additionally, error messaging is enhanced to clearly indicate that offset and next parameters cannot be used together, providing clearer guidance to callers on valid parameter combinations.

@VelikovPetar VelikovPetar added the pr:bug Bug fix label Feb 23, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled.

🎉 Great job! This PR is ready for review.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.26 MB 0.00 MB 🟢
stream-chat-android-offline 5.48 MB 5.48 MB 0.00 MB 🟢
stream-chat-android-ui-components 10.63 MB 10.63 MB 0.00 MB 🟢
stream-chat-android-compose 12.85 MB 12.85 MB 0.00 MB 🟢

@sonarqubecloud
Copy link

@VelikovPetar VelikovPetar marked this pull request as ready for review February 23, 2026 16:37
@VelikovPetar VelikovPetar requested a review from a team as a code owner February 23, 2026 16:37
@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

Walkthrough

The 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

Cohort / File(s) Summary
Validation Logic
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt
Modified searchMessages parameter validation to forbid offset with next (instead of offset with sort or next), allowing offset and sort to be used together. Error message updated to clarify the specific constraint.
Test Updates
stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientGeneralApiTests.kt
Test renamed and scenario updated: now validates that offset with sort succeeds, and maintains assertion for error when both offset and next are provided with specific error message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hop-hooray! The rules have shifted near,
Offset and sort now skip the fear,
But next and offset? Still not dear,
One dance partner, crystal clear! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing incorrect validation logic for searchMessages parameters.
Description check ✅ Passed The description covers the required sections (Goal, Implementation, Testing) with clear explanations, though UI Changes and Checklist sections are minimal.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/AND-1086_fix_wrong_search_messages_front_end_check

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

> [!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 | 🟡 Minor

Use 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 | 🟡 Minor

Update 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."sort is now permitted alongside offset.
  • 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 7abef21 and 866ee34.

📒 Files selected for processing (2)
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientGeneralApiTests.kt

@VelikovPetar VelikovPetar merged commit 567d02e into develop Feb 25, 2026
17 checks passed
@VelikovPetar VelikovPetar deleted the bug/AND-1086_fix_wrong_search_messages_front_end_check branch February 25, 2026 09:27
@stream-public-bot stream-public-bot added the released Included in a release label Feb 27, 2026
@stream-public-bot
Copy link
Contributor

🚀 Available in v6.33.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bug Bug fix released Included in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants