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 efc57f146bf..e6f5d5a9896 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 @@ -52,7 +52,6 @@ import io.getstream.chat.android.client.api2.model.dto.UpstreamPushPreferenceInp import io.getstream.chat.android.client.api2.model.requests.AcceptInviteRequest import io.getstream.chat.android.client.api2.model.requests.AddMembersRequest import io.getstream.chat.android.client.api2.model.requests.BanUserRequest -import io.getstream.chat.android.client.api2.model.requests.CreatePollRequest import io.getstream.chat.android.client.api2.model.requests.FlagMessageRequest import io.getstream.chat.android.client.api2.model.requests.FlagRequest import io.getstream.chat.android.client.api2.model.requests.FlagUserRequest @@ -80,7 +79,6 @@ import io.getstream.chat.android.client.api2.model.requests.UpdateLiveLocationRe import io.getstream.chat.android.client.api2.model.requests.UpdateMessageRequest import io.getstream.chat.android.client.api2.model.requests.UpdateUsersRequest import io.getstream.chat.android.client.api2.model.requests.UpsertPushPreferencesRequest -import io.getstream.chat.android.client.api2.model.requests.UpstreamOptionDto import io.getstream.chat.android.client.api2.model.response.ChannelResponse import io.getstream.chat.android.client.api2.model.response.PushPreferencesResponse import io.getstream.chat.android.client.api2.model.response.TranslateMessageRequest @@ -148,6 +146,8 @@ import io.getstream.chat.android.network.models.AddUserGroupMembersResponse import io.getstream.chat.android.network.models.BlockUsersRequest import io.getstream.chat.android.network.models.CastPollVoteRequest import io.getstream.chat.android.network.models.CreateDeviceRequest +import io.getstream.chat.android.network.models.CreatePollOptionRequest +import io.getstream.chat.android.network.models.CreatePollRequest import io.getstream.chat.android.network.models.CreateUserGroupRequest import io.getstream.chat.android.network.models.CreateUserGroupResponse import io.getstream.chat.android.network.models.DeliveredMessagePayload @@ -159,6 +159,8 @@ import io.getstream.chat.android.network.models.MarkReadRequest import io.getstream.chat.android.network.models.MarkUnreadRequest import io.getstream.chat.android.network.models.MessageActionRequest import io.getstream.chat.android.network.models.MuteChannelRequest +import io.getstream.chat.android.network.models.PollOptionInput +import io.getstream.chat.android.network.models.PollOptionRequest import io.getstream.chat.android.network.models.QueryPollVotesRequest import io.getstream.chat.android.network.models.QueryPollsRequest import io.getstream.chat.android.network.models.QueryReactionsRequest @@ -170,6 +172,7 @@ 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.chat.android.network.models.UpdateMemberPartialRequest +import io.getstream.chat.android.network.models.UpdatePollOptionRequest import io.getstream.chat.android.network.models.UpdatePollPartialRequest import io.getstream.chat.android.network.models.UpdateUserGroupRequest import io.getstream.chat.android.network.models.UpdateUserGroupResponse @@ -190,6 +193,7 @@ import okhttp3.ResponseBody import java.io.File import java.util.Date import io.getstream.chat.android.client.api.models.SendActionRequest as DomainSendActionRequest +import io.getstream.chat.android.network.models.UpdatePollRequest as UpdatePollRequestDto @Suppress("TooManyFunctions", "LargeClass") internal class MoshiChatApi @@ -1823,18 +1827,18 @@ constructor( } override fun createPollOption(pollId: String, option: PollOption): Call { - val body = UpstreamOptionDto( + val body = CreatePollOptionRequest( text = option.text, - extraData = option.extraData, + custom = option.extraData, ) return pollsApi.createPollOption(pollId, body).mapDomain { it.poll_option.toPollOption() } } override fun updatePollOption(pollId: String, option: PollOption): Call { - val body = UpstreamOptionDto( - id = option.id, + val body = UpdatePollOptionRequest( + id = option.id.orEmpty(), text = option.text, - extraData = option.extraData, + custom = option.extraData, ) return pollsApi.updatePollOption(pollId, body).mapDomain { it.poll_option.toPollOption() } } @@ -1877,49 +1881,49 @@ constructor( override fun createPoll(createPollParams: CreatePollParams): Call { return pollsApi.createPoll( CreatePollRequest( - allow_answers = createPollParams.allowAnswers, - allow_user_suggested_options = createPollParams.allowUserSuggestedOptions, + allowAnswers = createPollParams.allowAnswers, + allowUserSuggestedOptions = createPollParams.allowUserSuggestedOptions, description = createPollParams.description, - enforce_unique_vote = createPollParams.enforceUniqueVote, - max_votes_allowed = createPollParams.maxVotesAllowed, + enforceUniqueVote = createPollParams.enforceUniqueVote, + maxVotesAllowed = createPollParams.maxVotesAllowed, name = createPollParams.name, options = createPollParams.optionsWithExtraData.map { - UpstreamOptionDto( + PollOptionInput( text = it.text, - extraData = it.extraData, + custom = it.extraData, ) }, - voting_visibility = when (createPollParams.votingVisibility) { - VotingVisibility.PUBLIC -> CreatePollRequest.VOTING_VISIBILITY_PUBLIC - VotingVisibility.ANONYMOUS -> CreatePollRequest.VOTING_VISIBILITY_ANONYMOUS + votingVisibility = when (createPollParams.votingVisibility) { + VotingVisibility.PUBLIC -> CreatePollRequest.VotingVisibility.Public + VotingVisibility.ANONYMOUS -> CreatePollRequest.VotingVisibility.Anonymous }, - extraData = createPollParams.extraData, + custom = createPollParams.extraData, ), ).mapDomain { it.poll.toDomain() } } override fun updatePoll(request: UpdatePollRequest): Call { - val body = io.getstream.chat.android.client.api2.model.requests.UpdatePollRequest( - allow_answers = request.allowAnswers, - allow_user_suggested_options = request.allowUserSuggestedOptions, + val body = UpdatePollRequestDto( + allowAnswers = request.allowAnswers, + allowUserSuggestedOptions = request.allowUserSuggestedOptions, description = request.description, - enforce_unique_vote = request.enforceUniqueVote, + enforceUniqueVote = request.enforceUniqueVote, id = request.id, - is_closed = request.isClosed, - max_votes_allowed = request.maxVotesAllowed, + isClosed = request.isClosed, + maxVotesAllowed = request.maxVotesAllowed, name = request.name, options = request.options?.map { - UpstreamOptionDto( - id = it.id, + PollOptionRequest( + id = it.id.orEmpty(), text = it.text, - extraData = it.extraData, + custom = it.extraData, ) }, - voting_visibility = when (request.votingVisibility) { - VotingVisibility.PUBLIC -> CreatePollRequest.VOTING_VISIBILITY_PUBLIC - VotingVisibility.ANONYMOUS -> CreatePollRequest.VOTING_VISIBILITY_ANONYMOUS + votingVisibility = when (request.votingVisibility) { + VotingVisibility.PUBLIC -> UpdatePollRequestDto.VotingVisibility.Public + VotingVisibility.ANONYMOUS -> UpdatePollRequestDto.VotingVisibility.Anonymous }, - extraData = request.extraData, + custom = request.extraData, ) return pollsApi.updatePoll(body).mapDomain { it.poll.toDomain() } } diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/PollsApi.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/PollsApi.kt index 1bd572dc042..324158ccba4 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/PollsApi.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/PollsApi.kt @@ -17,9 +17,6 @@ package io.getstream.chat.android.client.api2.endpoint import io.getstream.chat.android.client.api.AuthenticatedApi -import io.getstream.chat.android.client.api2.model.requests.CreatePollRequest -import io.getstream.chat.android.client.api2.model.requests.UpdatePollRequest -import io.getstream.chat.android.client.api2.model.requests.UpstreamOptionDto import io.getstream.chat.android.client.api2.model.response.PollOptionResponse import io.getstream.chat.android.client.api2.model.response.PollResponse import io.getstream.chat.android.client.api2.model.response.PollVoteResponse @@ -27,10 +24,14 @@ import io.getstream.chat.android.client.api2.model.response.QueryPollVotesRespon import io.getstream.chat.android.client.api2.model.response.QueryPollsResponse import io.getstream.chat.android.client.call.RetrofitCall import io.getstream.chat.android.network.models.CastPollVoteRequest +import io.getstream.chat.android.network.models.CreatePollOptionRequest +import io.getstream.chat.android.network.models.CreatePollRequest import io.getstream.chat.android.network.models.QueryPollVotesRequest import io.getstream.chat.android.network.models.QueryPollsRequest import io.getstream.chat.android.network.models.Response +import io.getstream.chat.android.network.models.UpdatePollOptionRequest import io.getstream.chat.android.network.models.UpdatePollPartialRequest +import io.getstream.chat.android.network.models.UpdatePollRequest import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET @@ -119,7 +120,7 @@ internal interface PollsApi { @POST("/polls/{poll_id}/options") fun createPollOption( @Path("poll_id") pollId: String, - @Body body: UpstreamOptionDto, + @Body body: CreatePollOptionRequest, ): RetrofitCall /** @@ -133,7 +134,7 @@ internal interface PollsApi { @PUT("/polls/{poll_id}/options") fun updatePollOption( @Path("poll_id") pollId: String, - @Body body: UpstreamOptionDto, + @Body body: UpdatePollOptionRequest, ): RetrofitCall /** diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/PollRequests.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/PollRequests.kt deleted file mode 100644 index 1b0d2073580..00000000000 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/PollRequests.kt +++ /dev/null @@ -1,96 +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 io.getstream.chat.android.client.api2.model.dto.ExtraDataDto - -/** - * Request body for creating a new poll. - * - * @property allow_answers Indicates whether users can suggest user defined answers. - * @property allow_user_suggested_options Indicates whether users can suggest new options. - * @property description A description of the poll. - * @property enforce_unique_vote Indicates whether users can cast multiple votes. - * @property max_votes_allowed Indicates the maximum amount of votes a user can cast. - * @property name The name of the poll. - * @property options The list of options for the poll. - * @property voting_visibility The visibility of the poll. Accepted values are "public" and "anonymous". - * @property extraData Any additional custom fields. - */ -@JsonClass(generateAdapter = true) -internal data class CreatePollRequest( - val allow_answers: Boolean, - val allow_user_suggested_options: Boolean, - val description: String, - val enforce_unique_vote: Boolean, - val max_votes_allowed: Int?, - val name: String, - val options: List, - val voting_visibility: String, - val extraData: Map, -) : ExtraDataDto { - - internal companion object { - internal const val VOTING_VISIBILITY_PUBLIC = "public" - internal const val VOTING_VISIBILITY_ANONYMOUS = "anonymous" - } -} - -/** - * Request body for updating an existing poll. - * - * @property allow_answers Indicates whether users can suggest user defined answers. - * @property allow_user_suggested_options Indicates whether users can suggest new options. - * @property description A description of the poll. - * @property enforce_unique_vote Indicates whether users can cast multiple votes. - * @property id The id of the poll to update. - * @property is_closed Indicates whether the poll is closed. - * @property max_votes_allowed Indicates the maximum amount of votes a user can cast. - * @property name The name of the poll. - * @property options The list of options for the poll. - * @property voting_visibility The visibility of the poll. Accepted values are "public" and "anonymous". - * @property extraData Any additional custom fields. - */ -@JsonClass(generateAdapter = true) -internal data class UpdatePollRequest( - val allow_answers: Boolean?, - val allow_user_suggested_options: Boolean?, - val description: String?, - val enforce_unique_vote: Boolean?, - val id: String, - val is_closed: Boolean?, - val max_votes_allowed: Int?, - val name: String, - val options: List?, - val voting_visibility: String?, - val extraData: Map, -) : ExtraDataDto - -/** - * Model representing a poll option to be sent upstream. - * - * @property id the id of the option. If not provided, it will be generated by the server. - * @property text the text of the option. - * @property extraData any additional custom fields. - */ -@JsonClass(generateAdapter = true) -internal data class UpstreamOptionDto( - val id: String? = null, - val text: String, - val extraData: Map, -) : ExtraDataDto diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/MoshiChatParser.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/MoshiChatParser.kt index 2655a7d279e..e4875fa96c1 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/MoshiChatParser.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/MoshiChatParser.kt @@ -31,6 +31,7 @@ import io.getstream.chat.android.client.events.ConnectedEvent import io.getstream.chat.android.client.extensions.internal.enrichIfNeeded import io.getstream.chat.android.client.parser.ChatParser import io.getstream.chat.android.client.parser2.adapters.AttachmentDtoAdapter +import io.getstream.chat.android.client.parser2.adapters.CreatePollOptionRequestAdapter import io.getstream.chat.android.client.parser2.adapters.CreatePollRequestAdapter import io.getstream.chat.android.client.parser2.adapters.DownstreamChannelDtoAdapter import io.getstream.chat.android.client.parser2.adapters.DownstreamMemberDtoAdapter @@ -44,15 +45,20 @@ import io.getstream.chat.android.client.parser2.adapters.DownstreamThreadInfoDto import io.getstream.chat.android.client.parser2.adapters.DownstreamUserDtoAdapter import io.getstream.chat.android.client.parser2.adapters.EventAdapterFactory import io.getstream.chat.android.client.parser2.adapters.ExactDateAdapter +import io.getstream.chat.android.client.parser2.adapters.PollOptionInputAdapter +import io.getstream.chat.android.client.parser2.adapters.PollOptionRequestAdapter +import io.getstream.chat.android.client.parser2.adapters.UpdatePollOptionRequestAdapter +import io.getstream.chat.android.client.parser2.adapters.UpdatePollRequestAdapter import io.getstream.chat.android.client.parser2.adapters.UpstreamMemberDataDtoAdapter import io.getstream.chat.android.client.parser2.adapters.UpstreamMemberDtoAdapter import io.getstream.chat.android.client.parser2.adapters.UpstreamMessageDtoAdapter -import io.getstream.chat.android.client.parser2.adapters.UpstreamOptionDtoAdapter import io.getstream.chat.android.client.parser2.adapters.UpstreamReactionDtoAdapter import io.getstream.chat.android.client.parser2.adapters.UpstreamUserDtoAdapter import io.getstream.chat.android.client.socket.ErrorResponse import io.getstream.chat.android.client.socket.SocketErrorMessage import io.getstream.chat.android.network.infrastructure.Serializer +import io.getstream.chat.android.network.models.CreatePollRequest +import io.getstream.chat.android.network.models.UpdatePollRequest import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory @@ -84,7 +90,19 @@ internal class MoshiChatParser( .add(DownstreamPollDtoAdapter) .add(DownstreamPollOptionDtoAdapter) .add(CreatePollRequestAdapter) - .add(UpstreamOptionDtoAdapter) + .add(UpdatePollRequestAdapter) + .add(CreatePollOptionRequestAdapter) + .add(UpdatePollOptionRequestAdapter) + .add(PollOptionInputAdapter) + .add(PollOptionRequestAdapter) + .add( + CreatePollRequest.VotingVisibility::class.java, + CreatePollRequest.VotingVisibility.VotingVisibilityAdapter(), + ) + .add( + UpdatePollRequest.VotingVisibility::class.java, + UpdatePollRequest.VotingVisibility.VotingVisibilityAdapter(), + ) .build() } diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/PollDtoAdapters.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/PollDtoAdapters.kt index c8819bb8569..3947a8ce2b1 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/PollDtoAdapters.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/PollDtoAdapters.kt @@ -23,8 +23,12 @@ import com.squareup.moshi.JsonWriter import com.squareup.moshi.ToJson import io.getstream.chat.android.client.api2.model.dto.DownstreamPollDto import io.getstream.chat.android.client.api2.model.dto.DownstreamPollOptionDto -import io.getstream.chat.android.client.api2.model.requests.CreatePollRequest -import io.getstream.chat.android.client.api2.model.requests.UpstreamOptionDto +import io.getstream.chat.android.network.models.CreatePollOptionRequest +import io.getstream.chat.android.network.models.CreatePollRequest +import io.getstream.chat.android.network.models.PollOptionInput +import io.getstream.chat.android.network.models.PollOptionRequest +import io.getstream.chat.android.network.models.UpdatePollOptionRequest +import io.getstream.chat.android.network.models.UpdatePollRequest /** * Deserializer for [DownstreamPollDto] that handles the [io.getstream.chat.android.client.api2.model.dto.ExtraDataDto] @@ -61,11 +65,11 @@ internal object DownstreamPollOptionDtoAdapter : fun toJson(jsonWriter: JsonWriter, value: DownstreamPollOptionDto): Unit = error("Can't convert this to Json") } -/** - * Serializer for [CreatePollRequest] that handles the [io.getstream.chat.android.client.api2.model.dto.ExtraDataDto] - * implementation. - */ -internal object CreatePollRequestAdapter : CustomObjectDtoAdapter(CreatePollRequest::class) { +// The generated poll write-request models carry custom data in a `custom` field that must be +// flattened to the JSON root on the wire; extraDataPropertyName matches their @Json(name = "custom"). + +internal object CreatePollRequestAdapter : + CustomObjectDtoAdapter(CreatePollRequest::class, extraDataPropertyName = "custom") { @FromJson @Suppress("UNUSED_PARAMETER") @@ -80,22 +84,82 @@ internal object CreatePollRequestAdapter : CustomObjectDtoAdapter(UpstreamOptionDto::class) { +internal object UpdatePollRequestAdapter : + CustomObjectDtoAdapter(UpdatePollRequest::class, extraDataPropertyName = "custom") { + + @FromJson + @Suppress("UNUSED_PARAMETER") + fun fromJson(jsonReader: JsonReader): UpdatePollRequest = error("Can't parse this from Json") + + @ToJson + fun toJson( + jsonWriter: JsonWriter, + request: UpdatePollRequest?, + mapAdapter: JsonAdapter>, + requestAdapter: JsonAdapter, + ) = serializeWithExtraData(jsonWriter, request, mapAdapter, requestAdapter) +} + +internal object CreatePollOptionRequestAdapter : + CustomObjectDtoAdapter(CreatePollOptionRequest::class, extraDataPropertyName = "custom") { + + @FromJson + @Suppress("UNUSED_PARAMETER") + fun fromJson(jsonReader: JsonReader): CreatePollOptionRequest = error("Can't parse this from Json") + + @ToJson + fun toJson( + jsonWriter: JsonWriter, + request: CreatePollOptionRequest?, + mapAdapter: JsonAdapter>, + requestAdapter: JsonAdapter, + ) = serializeWithExtraData(jsonWriter, request, mapAdapter, requestAdapter) +} + +internal object UpdatePollOptionRequestAdapter : + CustomObjectDtoAdapter(UpdatePollOptionRequest::class, extraDataPropertyName = "custom") { + + @FromJson + @Suppress("UNUSED_PARAMETER") + fun fromJson(jsonReader: JsonReader): UpdatePollOptionRequest = error("Can't parse this from Json") + + @ToJson + fun toJson( + jsonWriter: JsonWriter, + request: UpdatePollOptionRequest?, + mapAdapter: JsonAdapter>, + requestAdapter: JsonAdapter, + ) = serializeWithExtraData(jsonWriter, request, mapAdapter, requestAdapter) +} + +internal object PollOptionInputAdapter : + CustomObjectDtoAdapter(PollOptionInput::class, extraDataPropertyName = "custom") { @FromJson @Suppress("UNUSED_PARAMETER") - fun fromJson(jsonReader: JsonReader): UpstreamOptionDto = error("Can't parse this from Json") + fun fromJson(jsonReader: JsonReader): PollOptionInput = error("Can't parse this from Json") @ToJson fun toJson( jsonWriter: JsonWriter, - option: UpstreamOptionDto?, + request: PollOptionInput?, mapAdapter: JsonAdapter>, - optionAdapter: JsonAdapter, - ) = serializeWithExtraData(jsonWriter, option, mapAdapter, optionAdapter) + requestAdapter: JsonAdapter, + ) = serializeWithExtraData(jsonWriter, request, mapAdapter, requestAdapter) +} + +internal object PollOptionRequestAdapter : + CustomObjectDtoAdapter(PollOptionRequest::class, extraDataPropertyName = "custom") { + + @FromJson + @Suppress("UNUSED_PARAMETER") + fun fromJson(jsonReader: JsonReader): PollOptionRequest = error("Can't parse this from Json") + + @ToJson + fun toJson( + jsonWriter: JsonWriter, + request: PollOptionRequest?, + mapAdapter: JsonAdapter>, + requestAdapter: JsonAdapter, + ) = serializeWithExtraData(jsonWriter, request, mapAdapter, requestAdapter) } diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/CreatePollOptionRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/CreatePollOptionRequest.kt new file mode 100644 index 00000000000..0ae223dfd86 --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/CreatePollOptionRequest.kt @@ -0,0 +1,38 @@ +/* + * 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 CreatePollOptionRequest( + @Json(name = "text") + internal val text: String, + + @Json(name = "custom") + internal val custom: Map? = emptyMap(), +) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/CreatePollRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/CreatePollRequest.kt new file mode 100644 index 00000000000..17cff4e9e5f --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/CreatePollRequest.kt @@ -0,0 +1,102 @@ +/* + * 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.FromJson +import com.squareup.moshi.Json +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonReader +import com.squareup.moshi.JsonWriter +import com.squareup.moshi.ToJson + +/** + * Contains all information needed to create a new poll + */ +@com.squareup.moshi.JsonClass(generateAdapter = true) +internal data class CreatePollRequest( + @Json(name = "name") + internal val name: String, + + @Json(name = "allow_answers") + internal val allowAnswers: Boolean? = null, + + @Json(name = "allow_user_suggested_options") + internal val allowUserSuggestedOptions: Boolean? = null, + + @Json(name = "description") + internal val description: String? = null, + + @Json(name = "enforce_unique_vote") + internal val enforceUniqueVote: Boolean? = null, + + @Json(name = "id") + internal val id: String? = null, + + @Json(name = "is_closed") + internal val isClosed: Boolean? = null, + + @Json(name = "max_votes_allowed") + internal val maxVotesAllowed: Int? = null, + + @Json(name = "voting_visibility") + internal val votingVisibility: VotingVisibility? = null, + + @Json(name = "options") + internal val options: List? = emptyList(), + + @Json(name = "custom") + internal val custom: Map? = emptyMap(), +) { + + /** + * VotingVisibility Enum + */ + internal sealed class VotingVisibility(internal val value: String) { + override fun toString(): String = value + + internal companion object { + internal fun fromString(s: String): VotingVisibility = when (s) { + "anonymous" -> Anonymous + "public" -> Public + else -> Unknown(s) + } + } + internal object Anonymous : VotingVisibility("anonymous") + internal object Public : VotingVisibility("public") + internal data class Unknown(val unknownValue: String) : VotingVisibility(unknownValue) + + internal class VotingVisibilityAdapter : JsonAdapter() { + @FromJson + override fun fromJson(reader: JsonReader): VotingVisibility? { + val s = reader.nextString() ?: return null + return VotingVisibility.fromString(s) + } + + @ToJson + override fun toJson(writer: JsonWriter, value: VotingVisibility?) { + writer.value(value?.value) + } + } + } +} diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/PollOptionInput.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/PollOptionInput.kt new file mode 100644 index 00000000000..5de4be9767f --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/PollOptionInput.kt @@ -0,0 +1,38 @@ +/* + * 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 PollOptionInput( + @Json(name = "text") + internal val text: String? = null, + + @Json(name = "custom") + internal val custom: Map? = emptyMap(), +) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/PollOptionRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/PollOptionRequest.kt new file mode 100644 index 00000000000..12b6834c8a1 --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/PollOptionRequest.kt @@ -0,0 +1,41 @@ +/* + * 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 PollOptionRequest( + @Json(name = "id") + internal val id: String, + + @Json(name = "text") + internal val text: String? = null, + + @Json(name = "custom") + internal val custom: Map? = emptyMap(), +) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdatePollOptionRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdatePollOptionRequest.kt new file mode 100644 index 00000000000..11fe6584f01 --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdatePollOptionRequest.kt @@ -0,0 +1,41 @@ +/* + * 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 UpdatePollOptionRequest( + @Json(name = "id") + internal val id: String, + + @Json(name = "text") + internal val text: String, + + @Json(name = "custom") + internal val custom: Map? = emptyMap(), +) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdatePollRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdatePollRequest.kt new file mode 100644 index 00000000000..6e35d30db3d --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdatePollRequest.kt @@ -0,0 +1,102 @@ +/* + * 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.FromJson +import com.squareup.moshi.Json +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonReader +import com.squareup.moshi.JsonWriter +import com.squareup.moshi.ToJson + +/** + * + */ +@com.squareup.moshi.JsonClass(generateAdapter = true) +internal data class UpdatePollRequest( + @Json(name = "id") + internal val id: String, + + @Json(name = "name") + internal val name: String, + + @Json(name = "allow_answers") + internal val allowAnswers: Boolean? = null, + + @Json(name = "allow_user_suggested_options") + internal val allowUserSuggestedOptions: Boolean? = null, + + @Json(name = "description") + internal val description: String? = null, + + @Json(name = "enforce_unique_vote") + internal val enforceUniqueVote: Boolean? = null, + + @Json(name = "is_closed") + internal val isClosed: Boolean? = null, + + @Json(name = "max_votes_allowed") + internal val maxVotesAllowed: Int? = null, + + @Json(name = "voting_visibility") + internal val votingVisibility: VotingVisibility? = null, + + @Json(name = "options") + internal val options: List? = emptyList(), + + @Json(name = "custom") + internal val custom: Map? = emptyMap(), +) { + + /** + * VotingVisibility Enum + */ + internal sealed class VotingVisibility(internal val value: String) { + override fun toString(): String = value + + internal companion object { + internal fun fromString(s: String): VotingVisibility = when (s) { + "anonymous" -> Anonymous + "public" -> Public + else -> Unknown(s) + } + } + internal object Anonymous : VotingVisibility("anonymous") + internal object Public : VotingVisibility("public") + internal data class Unknown(val unknownValue: String) : VotingVisibility(unknownValue) + + internal class VotingVisibilityAdapter : JsonAdapter() { + @FromJson + override fun fromJson(reader: JsonReader): VotingVisibility? { + val s = reader.nextString() ?: return null + return VotingVisibility.fromString(s) + } + + @ToJson + override fun toJson(writer: JsonWriter, value: VotingVisibility?) { + writer.value(value?.value) + } + } + } +} 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 501ea16bded..8a99578c0eb 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 @@ -48,7 +48,6 @@ import io.getstream.chat.android.client.api2.model.dto.UpstreamChatPreferencesDt import io.getstream.chat.android.client.api2.model.dto.UpstreamPushPreferenceInputDto import io.getstream.chat.android.client.api2.model.requests.AcceptInviteRequest import io.getstream.chat.android.client.api2.model.requests.BanUserRequest -import io.getstream.chat.android.client.api2.model.requests.CreatePollRequest 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.GuestUserRequest @@ -66,7 +65,6 @@ import io.getstream.chat.android.client.api2.model.requests.UpdateCooldownReques import io.getstream.chat.android.client.api2.model.requests.UpdateLiveLocationRequest import io.getstream.chat.android.client.api2.model.requests.UpdateMemberPartialResponse import io.getstream.chat.android.client.api2.model.requests.UpsertPushPreferencesRequest -import io.getstream.chat.android.client.api2.model.requests.UpstreamOptionDto import io.getstream.chat.android.client.api2.model.response.AppSettingsResponse import io.getstream.chat.android.client.api2.model.response.ChannelResponse import io.getstream.chat.android.client.api2.model.response.DraftMessageResponse @@ -144,6 +142,8 @@ import io.getstream.chat.android.network.models.BlockUsersRequest import io.getstream.chat.android.network.models.BlockUsersResponse import io.getstream.chat.android.network.models.CastPollVoteRequest import io.getstream.chat.android.network.models.CreateDeviceRequest +import io.getstream.chat.android.network.models.CreatePollOptionRequest +import io.getstream.chat.android.network.models.CreatePollRequest import io.getstream.chat.android.network.models.CreateUserGroupRequest import io.getstream.chat.android.network.models.CreateUserGroupResponse import io.getstream.chat.android.network.models.DeliveredMessagePayload @@ -158,6 +158,8 @@ import io.getstream.chat.android.network.models.MarkReadRequest import io.getstream.chat.android.network.models.MarkUnreadRequest import io.getstream.chat.android.network.models.MessageActionRequest import io.getstream.chat.android.network.models.MuteChannelRequest +import io.getstream.chat.android.network.models.PollOptionInput +import io.getstream.chat.android.network.models.PollOptionRequest import io.getstream.chat.android.network.models.QueryPollVotesRequest import io.getstream.chat.android.network.models.QueryPollsRequest import io.getstream.chat.android.network.models.QueryReactionsRequest @@ -171,6 +173,7 @@ import io.getstream.chat.android.network.models.UnblockUsersRequest import io.getstream.chat.android.network.models.UnblockUsersResponse import io.getstream.chat.android.network.models.UpdateChannelPartialRequest import io.getstream.chat.android.network.models.UpdateMemberPartialRequest +import io.getstream.chat.android.network.models.UpdatePollOptionRequest import io.getstream.chat.android.network.models.UpdatePollPartialRequest import io.getstream.chat.android.network.models.UpdateUserGroupRequest import io.getstream.chat.android.network.models.UpdateUserGroupResponse @@ -219,6 +222,7 @@ import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import kotlin.reflect.KClass +import io.getstream.chat.android.network.models.UpdatePollRequest as UpdatePollRequestDto @Suppress("LargeClass") internal class MoshiChatApiTest { @@ -2561,7 +2565,7 @@ internal class MoshiChatApiTest { val option = randomPollOption() val result = sut.createPollOption(pollId, option).await() // then - val expectedOption = UpstreamOptionDto(text = option.text, extraData = option.extraData) + val expectedOption = CreatePollOptionRequest(text = option.text, custom = option.extraData) result `should be instance of` expected verify(api, times(1)).createPollOption(pollId, expectedOption) } @@ -2580,7 +2584,11 @@ internal class MoshiChatApiTest { val option = randomPollOption() val result = sut.updatePollOption(pollId, option).await() // then - val expectedOption = UpstreamOptionDto(option.id, option.text, option.extraData) + val expectedOption = UpdatePollOptionRequest( + id = option.id.orEmpty(), + text = option.text, + custom = option.extraData, + ) result `should be instance of` expected verify(api, times(1)).updatePollOption(pollId, expectedOption) } @@ -2620,20 +2628,20 @@ internal class MoshiChatApiTest { name = pollConfig.name, description = pollConfig.description, options = pollConfig.optionsWithExtraData.map { - UpstreamOptionDto( + PollOptionInput( text = it.text, - extraData = it.extraData, + custom = it.extraData, ) }, - voting_visibility = when (pollConfig.votingVisibility) { - VotingVisibility.PUBLIC -> CreatePollRequest.VOTING_VISIBILITY_PUBLIC - VotingVisibility.ANONYMOUS -> CreatePollRequest.VOTING_VISIBILITY_ANONYMOUS + votingVisibility = when (pollConfig.votingVisibility) { + VotingVisibility.PUBLIC -> CreatePollRequest.VotingVisibility.Public + VotingVisibility.ANONYMOUS -> CreatePollRequest.VotingVisibility.Anonymous }, - enforce_unique_vote = pollConfig.enforceUniqueVote, - max_votes_allowed = pollConfig.maxVotesAllowed, - allow_user_suggested_options = pollConfig.allowUserSuggestedOptions, - allow_answers = pollConfig.allowAnswers, - extraData = pollConfig.extraData, + enforceUniqueVote = pollConfig.enforceUniqueVote, + maxVotesAllowed = pollConfig.maxVotesAllowed, + allowUserSuggestedOptions = pollConfig.allowUserSuggestedOptions, + allowAnswers = pollConfig.allowAnswers, + custom = pollConfig.extraData, ) result `should be instance of` expected verify(api, times(1)).createPoll(expectedBody) @@ -2675,24 +2683,24 @@ internal class MoshiChatApiTest { ) val result = sut.updatePoll(request).await() // then - val expectedBody = io.getstream.chat.android.client.api2.model.requests.UpdatePollRequest( + val expectedBody = UpdatePollRequestDto( id = pollId, name = name, description = description, options = options.map { - UpstreamOptionDto( - id = it.id, + PollOptionRequest( + id = it.id.orEmpty(), text = it.text, - extraData = it.extraData, + custom = it.extraData, ) }, - voting_visibility = CreatePollRequest.VOTING_VISIBILITY_PUBLIC, - enforce_unique_vote = enforceUniqueVote, - max_votes_allowed = maxVotesAllowed, - allow_user_suggested_options = allowUserSuggestedOptions, - allow_answers = allowAnswers, - is_closed = isClosed, - extraData = extraData, + votingVisibility = UpdatePollRequestDto.VotingVisibility.Public, + enforceUniqueVote = enforceUniqueVote, + maxVotesAllowed = maxVotesAllowed, + allowUserSuggestedOptions = allowUserSuggestedOptions, + allowAnswers = allowAnswers, + isClosed = isClosed, + custom = extraData, ) result `should be instance of` expected verify(api, times(1)).updatePoll(expectedBody) diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/UpstreamOptionDtoAdapterTest.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/PollOptionInputAdapterTest.kt similarity index 65% rename from stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/UpstreamOptionDtoAdapterTest.kt rename to stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/PollOptionInputAdapterTest.kt index 8d0bf23650f..41926a80c70 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/UpstreamOptionDtoAdapterTest.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/PollOptionInputAdapterTest.kt @@ -20,18 +20,18 @@ import io.getstream.chat.android.client.parser2.testdata.PollDtoTestData import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test -internal class UpstreamOptionDtoAdapterTest { +internal class PollOptionInputAdapterTest { private val parser = ParserFactory.createMoshiChatParser() @Test - fun `Serialize UpstreamOptionDto with custom fields`() { - val json = parser.toJson(PollDtoTestData.upstreamOption) - Assertions.assertEquals(PollDtoTestData.upstreamOptionJson, json) + fun `Serialize PollOptionInput with custom fields`() { + val json = parser.toJson(PollDtoTestData.pollOptionInput) + Assertions.assertEquals(PollDtoTestData.pollOptionInputJson, json) } @Test - fun `Serialize UpstreamOptionDto without custom fields`() { - val json = parser.toJson(PollDtoTestData.upstreamOptionWithoutExtraData) - Assertions.assertEquals(PollDtoTestData.upstreamOptionJsonWithoutExtraData, json) + fun `Serialize PollOptionInput without custom fields`() { + val json = parser.toJson(PollDtoTestData.pollOptionInputWithoutExtraData) + Assertions.assertEquals(PollDtoTestData.pollOptionInputJsonWithoutExtraData, json) } } diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/PollWriteRequestAdapterTest.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/PollWriteRequestAdapterTest.kt new file mode 100644 index 00000000000..c89d5101f7f --- /dev/null +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/PollWriteRequestAdapterTest.kt @@ -0,0 +1,73 @@ +/* + * 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.PollDtoTestData +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +internal class PollWriteRequestAdapterTest { + private val parser = ParserFactory.createMoshiChatParser() + + @Test + fun `Serialize UpdatePollRequest with custom fields`() { + val json = parser.toJson(PollDtoTestData.updatePollRequest) + Assertions.assertEquals(PollDtoTestData.updatePollRequestJson, json) + } + + @Test + fun `Serialize UpdatePollRequest without custom fields`() { + val json = parser.toJson(PollDtoTestData.updatePollRequestWithoutExtraData) + Assertions.assertEquals(PollDtoTestData.updatePollRequestJsonWithoutExtraData, json) + } + + @Test + fun `Serialize PollOptionRequest with custom fields`() { + val json = parser.toJson(PollDtoTestData.pollOptionRequest) + Assertions.assertEquals(PollDtoTestData.pollOptionRequestJson, json) + } + + @Test + fun `Serialize PollOptionRequest without custom fields`() { + val json = parser.toJson(PollDtoTestData.pollOptionRequestWithoutExtraData) + Assertions.assertEquals(PollDtoTestData.pollOptionRequestJsonWithoutExtraData, json) + } + + @Test + fun `Serialize CreatePollOptionRequest with custom fields`() { + val json = parser.toJson(PollDtoTestData.createPollOptionRequest) + Assertions.assertEquals(PollDtoTestData.createPollOptionRequestJson, json) + } + + @Test + fun `Serialize CreatePollOptionRequest without custom fields`() { + val json = parser.toJson(PollDtoTestData.createPollOptionRequestWithoutExtraData) + Assertions.assertEquals(PollDtoTestData.createPollOptionRequestJsonWithoutExtraData, json) + } + + @Test + fun `Serialize UpdatePollOptionRequest with custom fields`() { + val json = parser.toJson(PollDtoTestData.updatePollOptionRequest) + Assertions.assertEquals(PollDtoTestData.updatePollOptionRequestJson, json) + } + + @Test + fun `Serialize UpdatePollOptionRequest without custom fields`() { + val json = parser.toJson(PollDtoTestData.updatePollOptionRequestWithoutExtraData) + Assertions.assertEquals(PollDtoTestData.updatePollOptionRequestJsonWithoutExtraData, json) + } +} diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/PollDtoTestData.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/PollDtoTestData.kt index 8765785114f..653d5862e06 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/PollDtoTestData.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/PollDtoTestData.kt @@ -18,8 +18,12 @@ package io.getstream.chat.android.client.parser2.testdata import io.getstream.chat.android.client.api2.model.dto.DownstreamPollDto import io.getstream.chat.android.client.api2.model.dto.DownstreamPollOptionDto -import io.getstream.chat.android.client.api2.model.requests.CreatePollRequest -import io.getstream.chat.android.client.api2.model.requests.UpstreamOptionDto +import io.getstream.chat.android.network.models.CreatePollOptionRequest +import io.getstream.chat.android.network.models.CreatePollRequest +import io.getstream.chat.android.network.models.PollOptionInput +import io.getstream.chat.android.network.models.PollOptionRequest +import io.getstream.chat.android.network.models.UpdatePollOptionRequest +import io.getstream.chat.android.network.models.UpdatePollRequest import org.intellij.lang.annotations.Language import java.util.Date @@ -186,33 +190,33 @@ internal object PollDtoTestData { extraData = emptyMap(), ) - // UpstreamOptionDto Test Data + // PollOptionInput Test Data @Language("JSON") - val upstreamOptionJson = + val pollOptionInputJson = """{ "text": "option", "customKey1": "customValue1", "customKey2": 42.0 }""".withoutWhitespace() - val upstreamOption = UpstreamOptionDto( + val pollOptionInput = PollOptionInput( text = "option", - extraData = mapOf( + custom = mapOf( "customKey1" to "customValue1", "customKey2" to 42.0, // JSON numbers are parsed as Double ), ) @Language("JSON") - val upstreamOptionJsonWithoutExtraData = + val pollOptionInputJsonWithoutExtraData = """{ "text": "option" }""".withoutWhitespace() - val upstreamOptionWithoutExtraData = UpstreamOptionDto( + val pollOptionInputWithoutExtraData = PollOptionInput( text = "option", - extraData = emptyMap(), + custom = emptyMap(), ) // CreatePollRequest Test Data @@ -220,36 +224,36 @@ internal object PollDtoTestData { @Language("JSON") val createPollRequestJson = """{ + "name": "poll", "allow_answers": true, "allow_user_suggested_options": false, "description": "description", "enforce_unique_vote": true, "max_votes_allowed": 1, - "name": "poll", + "voting_visibility": "public", "options": [ { "text": "option" } ], - "voting_visibility": "public", "customRequestKey": "customRequestValue" }""".withoutWhitespace() val createPollRequest = CreatePollRequest( - allow_answers = true, - allow_user_suggested_options = false, - description = "description", - enforce_unique_vote = true, - max_votes_allowed = 1, name = "poll", + allowAnswers = true, + allowUserSuggestedOptions = false, + description = "description", + enforceUniqueVote = true, + maxVotesAllowed = 1, + votingVisibility = CreatePollRequest.VotingVisibility.Public, options = listOf( - UpstreamOptionDto( + PollOptionInput( text = "option", - extraData = emptyMap(), + custom = emptyMap(), ), ), - voting_visibility = "public", - extraData = mapOf( + custom = mapOf( "customRequestKey" to "customRequestValue", ), ) @@ -257,25 +261,156 @@ internal object PollDtoTestData { @Language("JSON") val createPollRequestJsonWithoutExtraData = """{ + "name": "poll", "allow_answers": false, "allow_user_suggested_options": false, "description": "", "enforce_unique_vote": false, "max_votes_allowed": 1, - "name": "poll", - "options": [], - "voting_visibility": "public" + "voting_visibility": "public", + "options": [] }""".withoutWhitespace() val createPollRequestWithoutExtraData = CreatePollRequest( - allow_answers = false, - allow_user_suggested_options = false, + name = "poll", + allowAnswers = false, + allowUserSuggestedOptions = false, description = "", - enforce_unique_vote = false, - max_votes_allowed = 1, + enforceUniqueVote = false, + maxVotesAllowed = 1, + votingVisibility = CreatePollRequest.VotingVisibility.Public, + options = emptyList(), + custom = emptyMap(), + ) + + // UpdatePollRequest Test Data + + @Language("JSON") + val updatePollRequestJson = + """{ + "id": "poll1", + "name": "poll", + "voting_visibility": "public", + "options": [ + { + "id": "option1", + "text": "option" + } + ], + "customRequestKey": "customRequestValue" + }""".withoutWhitespace() + + val updatePollRequest = UpdatePollRequest( + id = "poll1", name = "poll", + votingVisibility = UpdatePollRequest.VotingVisibility.Public, + options = listOf( + PollOptionRequest( + id = "option1", + text = "option", + custom = emptyMap(), + ), + ), + custom = mapOf("customRequestKey" to "customRequestValue"), + ) + + @Language("JSON") + val updatePollRequestJsonWithoutExtraData = + """{ + "id": "poll2", + "name": "poll", + "voting_visibility": "public", + "options": [] + }""".withoutWhitespace() + + val updatePollRequestWithoutExtraData = UpdatePollRequest( + id = "poll2", + name = "poll", + votingVisibility = UpdatePollRequest.VotingVisibility.Public, options = emptyList(), - voting_visibility = "public", - extraData = emptyMap(), + custom = emptyMap(), + ) + + // PollOptionRequest Test Data + + @Language("JSON") + val pollOptionRequestJson = + """{ + "id": "option1", + "text": "option", + "customKey": "customValue" + }""".withoutWhitespace() + + val pollOptionRequest = PollOptionRequest( + id = "option1", + text = "option", + custom = mapOf("customKey" to "customValue"), + ) + + @Language("JSON") + val pollOptionRequestJsonWithoutExtraData = + """{ + "id": "option2", + "text": "option" + }""".withoutWhitespace() + + val pollOptionRequestWithoutExtraData = PollOptionRequest( + id = "option2", + text = "option", + custom = emptyMap(), + ) + + // CreatePollOptionRequest Test Data + + @Language("JSON") + val createPollOptionRequestJson = + """{ + "text": "option", + "customKey": "customValue" + }""".withoutWhitespace() + + val createPollOptionRequest = CreatePollOptionRequest( + text = "option", + custom = mapOf("customKey" to "customValue"), + ) + + @Language("JSON") + val createPollOptionRequestJsonWithoutExtraData = + """{ + "text": "option" + }""".withoutWhitespace() + + val createPollOptionRequestWithoutExtraData = CreatePollOptionRequest( + text = "option", + custom = emptyMap(), + ) + + // UpdatePollOptionRequest Test Data + + @Language("JSON") + val updatePollOptionRequestJson = + """{ + "id": "option1", + "text": "option", + "customKey": "customValue" + }""".withoutWhitespace() + + val updatePollOptionRequest = UpdatePollOptionRequest( + id = "option1", + text = "option", + custom = mapOf("customKey" to "customValue"), + ) + + @Language("JSON") + val updatePollOptionRequestJsonWithoutExtraData = + """{ + "id": "option2", + "text": "option" + }""".withoutWhitespace() + + val updatePollOptionRequestWithoutExtraData = UpdatePollOptionRequest( + id = "option2", + text = "option", + custom = emptyMap(), ) }