Skip to content

Commit 567d02e

Browse files
VelikovPetarclaude
andauthored
Fix incorrect validation for searchMessages parameters (#6180)
* Fix incorrect validation for searchMessages parameters Co-Authored-By: Claude <noreply@anthropic.com> * Fix detekt. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9a4e338 commit 567d02e

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,8 +1759,11 @@ internal constructor(
17591759
next: String? = null,
17601760
sort: QuerySorter<Message>? = null,
17611761
): Call<SearchMessagesResult> {
1762-
if (offset != null && (sort != null || next != null)) {
1763-
return ErrorCall(userScope, Error.GenericError("Cannot specify offset with sort or next parameters"))
1762+
if (offset != null && next != null) {
1763+
return ErrorCall(
1764+
userScope,
1765+
Error.GenericError("Cannot use both offset and next values. Specify only one of these options."),
1766+
)
17641767
}
17651768
return api.searchMessages(
17661769
channelFilter = channelFilter,

stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientGeneralApiTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ internal class ChatClientGeneralApiTests : BaseChatClientTest() {
232232
}
233233

234234
@Test
235-
fun searchMessagesWithoutOffsetWithSortAndNextSuccess() = runTest {
235+
fun searchMessagesWithNextAndSort() = runTest {
236236
// given
237237
val channelFilter = Filters.neutral()
238238
val messageFilter = Filters.neutral()
@@ -266,7 +266,7 @@ internal class ChatClientGeneralApiTests : BaseChatClientTest() {
266266
// when
267267
val result = sut.searchMessages(channelFilter, messageFilter, offset, limit, next, sort).await()
268268
// then
269-
verifyGenericError(result, "Cannot specify offset with sort or next parameters")
269+
verifySuccess(result, response)
270270
}
271271

272272
@Test
@@ -285,7 +285,7 @@ internal class ChatClientGeneralApiTests : BaseChatClientTest() {
285285
// when
286286
val result = sut.searchMessages(channelFilter, messageFilter, offset, limit, next, sort).await()
287287
// then
288-
verifyGenericError(result, "Cannot specify offset with sort or next parameters")
288+
verifyGenericError(result, "Cannot use both offset and next values. Specify only one of these options.")
289289
}
290290

291291
@Test

0 commit comments

Comments
 (0)