From 3192a5b0ae2fea211a23625112e5e1ba57b82ad7 Mon Sep 17 00:00:00 2001 From: Gian <47775302+gpunto@users.noreply.github.com> Date: Fri, 25 Sep 2026 14:57:08 +0200 Subject: [PATCH] Send the query banned users payload with the generated QueryBannedUsersPayload --- .../chat/android/client/api2/MoshiChatApi.kt | 16 ++--- .../client/api2/endpoint/ModerationApi.kt | 4 +- .../model/requests/QueryBannedUsersRequest.kt | 32 ---------- .../network/models/QueryBannedUsersPayload.kt | 59 ++++++++++++++++++ .../android/client/api2/MoshiChatApiTest.kt | 16 ++--- .../QueryBannedUsersPayloadAdapterTest.kt | 37 +++++++++++ .../QueryBannedUsersPayloadTestData.kt | 61 +++++++++++++++++++ 7 files changed, 175 insertions(+), 50 deletions(-) delete mode 100644 stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/QueryBannedUsersRequest.kt create mode 100644 stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryBannedUsersPayload.kt create mode 100644 stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryBannedUsersPayloadAdapterTest.kt create mode 100644 stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryBannedUsersPayloadTestData.kt 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 cb2c8d48fdc1..dce04aaf9ad6 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 @@ -53,7 +53,6 @@ import io.getstream.chat.android.client.api2.model.requests.FlagRequest import io.getstream.chat.android.client.api2.model.requests.FlagUserRequest import io.getstream.chat.android.client.api2.model.requests.MuteUserRequest import io.getstream.chat.android.client.api2.model.requests.PinnedMessagesRequest -import io.getstream.chat.android.client.api2.model.requests.QueryBannedUsersRequest import io.getstream.chat.android.client.api2.model.requests.SyncHistoryRequest import io.getstream.chat.android.client.api2.model.response.ChannelResponse import io.getstream.chat.android.client.call.RetrofitCall @@ -142,6 +141,7 @@ import io.getstream.chat.android.network.models.PollOptionInput import io.getstream.chat.android.network.models.PollOptionRequest import io.getstream.chat.android.network.models.PollVoteResponse import io.getstream.chat.android.network.models.PushPreferenceInput +import io.getstream.chat.android.network.models.QueryBannedUsersPayload import io.getstream.chat.android.network.models.QueryDraftsRequest import io.getstream.chat.android.network.models.QueryMembersPayload import io.getstream.chat.android.network.models.QueryPollVotesRequest @@ -969,15 +969,15 @@ constructor( createdAtBeforeOrEqual: Date?, ): Call> { return moderationApi.queryBannedUsers( - payload = QueryBannedUsersRequest( - filter_conditions = filter.toMap(), - sort = sort.toDto(), + payload = QueryBannedUsersPayload( + filterConditions = filter.toMap(), + sort = sort.toSortParams(), offset = offset, limit = limit, - created_at_after = createdAtAfter, - created_at_after_or_equal = createdAtAfterOrEqual, - created_at_before = createdAtBefore, - created_at_before_or_equal = createdAtBeforeOrEqual, + createdAtAfter = createdAtAfter, + createdAtAfterOrEqual = createdAtAfterOrEqual, + createdAtBefore = createdAtBefore, + createdAtBeforeOrEqual = createdAtBeforeOrEqual, ), ).flatMapDomain { response -> val bans = response.bans.mapNotNull { it.toDomain() } diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/ModerationApi.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/ModerationApi.kt index 6991d87773ff..7a20508a7cca 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/ModerationApi.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/ModerationApi.kt @@ -21,11 +21,11 @@ import io.getstream.chat.android.client.api2.UrlQueryPayload import io.getstream.chat.android.client.api2.model.requests.BanUserRequest import io.getstream.chat.android.client.api2.model.requests.FlagRequest import io.getstream.chat.android.client.api2.model.requests.MuteUserRequest -import io.getstream.chat.android.client.api2.model.requests.QueryBannedUsersRequest import io.getstream.chat.android.client.api2.model.response.FlagResponse import io.getstream.chat.android.client.api2.model.response.MuteUserResponse import io.getstream.chat.android.client.call.RetrofitCall import io.getstream.chat.android.network.models.MuteChannelRequest +import io.getstream.chat.android.network.models.QueryBannedUsersPayload import io.getstream.chat.android.network.models.QueryBannedUsersResponse import io.getstream.chat.android.network.models.Response import retrofit2.http.Body @@ -68,6 +68,6 @@ internal interface ModerationApi { @GET("/query_banned_users") fun queryBannedUsers( - @UrlQueryPayload @Query("payload") payload: QueryBannedUsersRequest, + @UrlQueryPayload @Query("payload") payload: QueryBannedUsersPayload, ): RetrofitCall } diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/QueryBannedUsersRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/QueryBannedUsersRequest.kt deleted file mode 100644 index 5cac3c41ed64..000000000000 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/QueryBannedUsersRequest.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.api2.model.requests - -import com.squareup.moshi.JsonClass -import java.util.Date - -@JsonClass(generateAdapter = true) -internal data class QueryBannedUsersRequest( - var filter_conditions: Map<*, *>, - val sort: List>, - val offset: Int?, - val limit: Int?, - val created_at_after: Date?, - val created_at_after_or_equal: Date?, - val created_at_before: Date?, - val created_at_before_or_equal: Date?, -) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryBannedUsersPayload.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryBannedUsersPayload.kt new file mode 100644 index 000000000000..9b061f93b026 --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/QueryBannedUsersPayload.kt @@ -0,0 +1,59 @@ +/* + * 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 + +/** + * + */ +@com.squareup.moshi.JsonClass(generateAdapter = true) +internal data class QueryBannedUsersPayload( + @Json(name = "filter_conditions") + internal val filterConditions: Map = emptyMap(), + + @Json(name = "created_at_after") + internal val createdAtAfter: java.util.Date? = null, + + @Json(name = "created_at_after_or_equal") + internal val createdAtAfterOrEqual: java.util.Date? = null, + + @Json(name = "created_at_before") + internal val createdAtBefore: java.util.Date? = null, + + @Json(name = "created_at_before_or_equal") + internal val createdAtBeforeOrEqual: java.util.Date? = null, + + @Json(name = "exclude_expired_bans") + internal val excludeExpiredBans: Boolean? = null, + + @Json(name = "limit") + internal val limit: Int? = null, + + @Json(name = "offset") + internal val offset: Int? = null, + + @Json(name = "sort") + internal val sort: List? = 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 4a4930892e5f..604a41dc3367 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 @@ -44,7 +44,6 @@ import io.getstream.chat.android.client.api2.model.requests.FlagMessageRequest import io.getstream.chat.android.client.api2.model.requests.FlagUserRequest import io.getstream.chat.android.client.api2.model.requests.MuteUserRequest import io.getstream.chat.android.client.api2.model.requests.PinnedMessagesRequest -import io.getstream.chat.android.client.api2.model.requests.QueryBannedUsersRequest import io.getstream.chat.android.client.api2.model.response.ChannelResponse import io.getstream.chat.android.client.api2.model.response.DraftMessageResponse import io.getstream.chat.android.client.api2.model.response.EventResponse @@ -148,6 +147,7 @@ import io.getstream.chat.android.network.models.PollVoteResponse import io.getstream.chat.android.network.models.PollVotesResponse import io.getstream.chat.android.network.models.PushPreferenceInput import io.getstream.chat.android.network.models.PushPreferencesResponse +import io.getstream.chat.android.network.models.QueryBannedUsersPayload import io.getstream.chat.android.network.models.QueryBannedUsersResponse import io.getstream.chat.android.network.models.QueryDraftsRequest import io.getstream.chat.android.network.models.QueryMembersPayload @@ -1217,15 +1217,15 @@ internal class MoshiChatApiTest { createdAtBeforeOrEqual = createdAtBeforeOrEqual, ).await() // then - val expectedPayload = QueryBannedUsersRequest( - filter_conditions = filter.toMap(), - sort = sort.toDto(), + val expectedPayload = QueryBannedUsersPayload( + filterConditions = filter.toMap(), + sort = listOf(SortParamRequest(field = "created_at", direction = 1)), offset = offset, limit = limit, - created_at_after = createdAtAfter, - created_at_after_or_equal = createdAtAfterOrEqual, - created_at_before = createdAtBefore, - created_at_before_or_equal = createdAtBeforeOrEqual, + createdAtAfter = createdAtAfter, + createdAtAfterOrEqual = createdAtAfterOrEqual, + createdAtBefore = createdAtBefore, + createdAtBeforeOrEqual = createdAtBeforeOrEqual, ) result `should be instance of` expected verify(api, times(1)).queryBannedUsers(expectedPayload) diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryBannedUsersPayloadAdapterTest.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryBannedUsersPayloadAdapterTest.kt new file mode 100644 index 000000000000..79f6a21a80fb --- /dev/null +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/QueryBannedUsersPayloadAdapterTest.kt @@ -0,0 +1,37 @@ +/* + * 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.QueryBannedUsersPayloadTestData +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +internal class QueryBannedUsersPayloadAdapterTest { + private val parser = ParserFactory.createMoshiChatParser() + + @Test + fun `Serialize QueryBannedUsersPayload with all fields`() { + val json = parser.toJson(QueryBannedUsersPayloadTestData.payload) + Assertions.assertEquals(QueryBannedUsersPayloadTestData.payloadJson, json) + } + + @Test + fun `Serialize QueryBannedUsersPayload with default fields`() { + val json = parser.toJson(QueryBannedUsersPayloadTestData.payloadWithDefaults) + Assertions.assertEquals(QueryBannedUsersPayloadTestData.payloadJsonWithDefaults, json) + } +} diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryBannedUsersPayloadTestData.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryBannedUsersPayloadTestData.kt new file mode 100644 index 000000000000..cce37a2ce336 --- /dev/null +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/QueryBannedUsersPayloadTestData.kt @@ -0,0 +1,61 @@ +/* + * 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.QueryBannedUsersPayload +import io.getstream.chat.android.network.models.SortParamRequest +import org.intellij.lang.annotations.Language +import java.util.Date + +internal object QueryBannedUsersPayloadTestData { + + @Language("JSON") + val payloadJson = + """{ + "filter_conditions": { + "channel_cid": "messaging:abc" + }, + "created_at_after": "2023-11-14T22:13:20.123Z", + "created_at_after_or_equal": "2023-11-14T22:13:21.000Z", + "created_at_before": "2027-01-15T08:00:00.000Z", + "created_at_before_or_equal": "1970-01-01T00:00:00.001Z", + "limit": 10, + "offset": 5, + "sort": [ + { + "direction": -1, + "field": "created_at" + } + ] + }""".withoutWhitespace() + + val payload = QueryBannedUsersPayload( + filterConditions = mapOf("channel_cid" to "messaging:abc"), + createdAtAfter = Date(1_700_000_000_123), + createdAtAfterOrEqual = Date(1_700_000_001_000), + createdAtBefore = Date(1_800_000_000_000), + createdAtBeforeOrEqual = Date(1), + limit = 10, + offset = 5, + sort = listOf(SortParamRequest(direction = -1, field = "created_at")), + ) + + @Language("JSON") + val payloadJsonWithDefaults = """{"filter_conditions":{}}""" + + val payloadWithDefaults = QueryBannedUsersPayload() +}