From ef44266be782a350379a6702da7e90057f06f67c Mon Sep 17 00:00:00 2001 From: Gian <47775302+gpunto@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:27:57 +0200 Subject: [PATCH 1/2] Migrate QueryReactionsRequest to the generated network model with SortParamRequest --- .../chat/android/client/api2/MoshiChatApi.kt | 13 ++++- .../client/api2/endpoint/MessageApi.kt | 2 +- .../network/models/QueryReactionsRequest.kt | 50 +++++++++++++++++++ .../models/SortParamRequest.kt} | 33 +++++++----- .../android/client/api2/MoshiChatApiTest.kt | 4 +- 5 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryReactionsRequest.kt rename stream-chat-android-client/src/main/java/io/getstream/chat/android/{client/api2/model/requests/QueryReactionsRequest.kt => network/models/SortParamRequest.kt} (51%) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt index 2b0bc153390..50cbf5f7195 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt @@ -77,7 +77,6 @@ import io.getstream.chat.android.client.api2.model.requests.QueryGroupedChannels import io.getstream.chat.android.client.api2.model.requests.QueryGroupedChannelsRequest import io.getstream.chat.android.client.api2.model.requests.QueryPollVotesRequest import io.getstream.chat.android.client.api2.model.requests.QueryPollsRequest -import io.getstream.chat.android.client.api2.model.requests.QueryReactionsRequest import io.getstream.chat.android.client.api2.model.requests.QueryRemindersRequest import io.getstream.chat.android.client.api2.model.requests.ReactionRequest import io.getstream.chat.android.client.api2.model.requests.RejectInviteRequest @@ -167,6 +166,8 @@ import io.getstream.chat.android.network.models.BlockUsersRequest import io.getstream.chat.android.network.models.CreateDeviceRequest import io.getstream.chat.android.network.models.HideChannelRequest import io.getstream.chat.android.network.models.MuteChannelRequest +import io.getstream.chat.android.network.models.QueryReactionsRequest +import io.getstream.chat.android.network.models.SortParamRequest import io.getstream.chat.android.network.models.UnblockUsersRequest import io.getstream.chat.android.network.models.UpdateChannelPartialRequest import io.getstream.log.taggedLogger @@ -431,7 +432,7 @@ constructor( filter = filter?.toMap(), limit = limit, next = next, - sort = sort?.toDto(), + sort = sort?.toSortParams(), ) return messageApi.queryReactions(messageId, body).mapDomain { QueryReactionsResult( @@ -2009,3 +2010,11 @@ constructor( private fun RetrofitCall.flatMapDomain(transform: DomainMapping.(T) -> Call): Call = flatMap { domainMapping.transform(it) } } + +internal fun QuerySorter<*>.toSortParams(): List = + toDto().map { + SortParamRequest( + field = it[QuerySorter.KEY_FIELD_NAME] as? String, + direction = (it[QuerySorter.KEY_DIRECTION] as? Number)?.toInt(), + ) + } diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/MessageApi.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/MessageApi.kt index ed665961d87..3caeaec0e2e 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/MessageApi.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/MessageApi.kt @@ -20,7 +20,6 @@ import io.getstream.chat.android.client.api.AuthenticatedApi import io.getstream.chat.android.client.api2.model.requests.PartialUpdateMessageRequest import io.getstream.chat.android.client.api2.model.requests.QueryDraftMessagesRequest import io.getstream.chat.android.client.api2.model.requests.QueryDraftsRequest -import io.getstream.chat.android.client.api2.model.requests.QueryReactionsRequest import io.getstream.chat.android.client.api2.model.requests.ReactionRequest import io.getstream.chat.android.client.api2.model.requests.SendActionRequest import io.getstream.chat.android.client.api2.model.requests.SendMessageRequest @@ -34,6 +33,7 @@ import io.getstream.chat.android.client.api2.model.response.ReactionResponse import io.getstream.chat.android.client.api2.model.response.ReactionsResponse import io.getstream.chat.android.client.api2.model.response.TranslateMessageRequest import io.getstream.chat.android.client.call.RetrofitCall +import io.getstream.chat.android.network.models.QueryReactionsRequest import io.getstream.chat.android.network.models.Response import retrofit2.http.Body import retrofit2.http.DELETE diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryReactionsRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryReactionsRequest.kt new file mode 100644 index 00000000000..0d5fd8fa979 --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryReactionsRequest.kt @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. + * + * Licensed under the Stream License; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://github.com/GetStream/stream-chat-android/blob/main/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport", +) + +package io.getstream.chat.android.network.models + +import com.squareup.moshi.Json +import kotlin.collections.List +import kotlin.collections.Map + +/** + * + */ + +@com.squareup.moshi.JsonClass(generateAdapter = true) +internal data class QueryReactionsRequest( + @Json(name = "limit") + val limit: kotlin.Int? = null, + + @Json(name = "next") + val next: kotlin.String? = null, + + @Json(name = "prev") + val prev: kotlin.String? = null, + + @Json(name = "sort") + val sort: kotlin.collections.List? = emptyList(), + + @Json(name = "filter") + val filter: kotlin.collections.Map? = emptyMap(), +) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/QueryReactionsRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SortParamRequest.kt similarity index 51% rename from stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/QueryReactionsRequest.kt rename to stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SortParamRequest.kt index b6da33f3179..b06d3bf5bd1 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/QueryReactionsRequest.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SortParamRequest.kt @@ -14,22 +14,29 @@ * limitations under the License. */ -package io.getstream.chat.android.client.api2.model.requests +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport", +) + +package io.getstream.chat.android.network.models -import com.squareup.moshi.JsonClass +import com.squareup.moshi.Json /** - * Request for querying reactions on a message. * - * @property filter The filter criteria. - * @property limit The maximum number of reactions to return. - * @property next The pagination token for fetching the next set of results. - * @property sort The sorting criteria to apply. */ -@JsonClass(generateAdapter = true) -internal data class QueryReactionsRequest( - val filter: Map<*, *>? = null, - val limit: Int? = null, - val next: String? = null, - val sort: List>? = null, + +@com.squareup.moshi.JsonClass(generateAdapter = true) +internal data class SortParamRequest( + @Json(name = "direction") + val direction: kotlin.Int? = null, + + @Json(name = "field") + val field: kotlin.String? = null, + + @Json(name = "type") + val type: kotlin.String? = null, ) diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt index 2c51d922775..23686a79407 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt @@ -70,7 +70,6 @@ import io.getstream.chat.android.client.api2.model.requests.QueryGroupedChannels import io.getstream.chat.android.client.api2.model.requests.QueryGroupedChannelsRequest import io.getstream.chat.android.client.api2.model.requests.QueryPollVotesRequest import io.getstream.chat.android.client.api2.model.requests.QueryPollsRequest -import io.getstream.chat.android.client.api2.model.requests.QueryReactionsRequest import io.getstream.chat.android.client.api2.model.requests.QueryRemindersRequest import io.getstream.chat.android.client.api2.model.requests.RejectInviteRequest import io.getstream.chat.android.client.api2.model.requests.ReminderRequest @@ -165,6 +164,7 @@ import io.getstream.chat.android.network.models.CreateDeviceRequest import io.getstream.chat.android.network.models.HideChannelRequest import io.getstream.chat.android.network.models.ListDevicesResponse import io.getstream.chat.android.network.models.MuteChannelRequest +import io.getstream.chat.android.network.models.QueryReactionsRequest import io.getstream.chat.android.network.models.Response import io.getstream.chat.android.network.models.UnblockUsersRequest import io.getstream.chat.android.network.models.UnblockUsersResponse @@ -461,7 +461,7 @@ internal class MoshiChatApiTest { filter = filter.toMap(), limit = limit, next = next, - sort = sort.toDto(), + sort = sort.toSortParams(), ) result `should be instance of` expected verify(api, times(1)).queryReactions(messageId, expectedRequest) From 08c6a3345b1877f3b392ffb9e8afae19d5e2164f Mon Sep 17 00:00:00 2001 From: Gian <47775302+gpunto@users.noreply.github.com> Date: Thu, 9 Jul 2026 17:53:08 +0200 Subject: [PATCH 2/2] Add adapter tests for QueryReactionsRequest and SortParamRequest --- .../QueryReactionsRequestAdapterTest.kt | 47 +++++++++++++ .../testdata/QueryReactionsRequestTestData.kt | 67 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryReactionsRequestAdapterTest.kt create mode 100644 stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryReactionsRequestTestData.kt diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryReactionsRequestAdapterTest.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryReactionsRequestAdapterTest.kt new file mode 100644 index 00000000000..2e80f5d56a7 --- /dev/null +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryReactionsRequestAdapterTest.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. + * + * Licensed under the Stream License; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://github.com/GetStream/stream-chat-android/blob/main/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.getstream.chat.android.client.parser2 + +import io.getstream.chat.android.client.parser2.testdata.QueryReactionsRequestTestData +import io.getstream.chat.android.network.models.QueryReactionsRequest +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +internal class QueryReactionsRequestAdapterTest { + private val parser = ParserFactory.createMoshiChatParser() + + @Test + fun `Serialize QueryReactionsRequest with all fields`() { + val json = parser.toJson(QueryReactionsRequestTestData.queryReactionsRequest) + Assertions.assertEquals(QueryReactionsRequestTestData.queryReactionsRequestJson, json) + } + + @Test + fun `Serialize QueryReactionsRequest with default fields`() { + val json = parser.toJson(QueryReactionsRequestTestData.queryReactionsRequestWithDefaults) + Assertions.assertEquals(QueryReactionsRequestTestData.queryReactionsRequestJsonWithDefaults, json) + } + + @Test + fun `Deserialize QueryReactionsRequest with all fields`() { + val request = parser.fromJson( + QueryReactionsRequestTestData.queryReactionsRequestJson, + QueryReactionsRequest::class.java, + ) + Assertions.assertEquals(QueryReactionsRequestTestData.queryReactionsRequest, request) + } +} diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryReactionsRequestTestData.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryReactionsRequestTestData.kt new file mode 100644 index 00000000000..cb31a6bae67 --- /dev/null +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryReactionsRequestTestData.kt @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. + * + * Licensed under the Stream License; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://github.com/GetStream/stream-chat-android/blob/main/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.getstream.chat.android.client.parser2.testdata + +import io.getstream.chat.android.network.models.QueryReactionsRequest +import io.getstream.chat.android.network.models.SortParamRequest +import org.intellij.lang.annotations.Language + +internal object QueryReactionsRequestTestData { + + @Language("JSON") + val queryReactionsRequestJson = + """{ + "limit": 10, + "next": "next-token", + "prev": "prev-token", + "sort": [ + { + "direction": -1, + "field": "created_at", + "type": "reaction" + } + ], + "filter": { + "type": "like" + } + }""".withoutWhitespace() + + val queryReactionsRequest = QueryReactionsRequest( + limit = 10, + next = "next-token", + prev = "prev-token", + sort = listOf( + SortParamRequest( + direction = -1, + field = "created_at", + type = "reaction", + ), + ), + filter = mapOf( + "type" to "like", + ), + ) + + @Language("JSON") + val queryReactionsRequestJsonWithDefaults = + """{ + "sort": [], + "filter": {} + }""".withoutWhitespace() + + val queryReactionsRequestWithDefaults = QueryReactionsRequest() +}