From 59b4ab2e6421ea242679ed1dd520ab9ba773b5cc Mon Sep 17 00:00:00 2001 From: Gian <47775302+gpunto@users.noreply.github.com> Date: Thu, 13 Aug 2026 12:54:13 +0200 Subject: [PATCH] Migrate the live location update request body to the generated UpdateLiveLocationRequest model --- .../chat/android/client/api2/MoshiChatApi.kt | 10 ++-- .../android/client/api2/endpoint/UserApi.kt | 2 +- .../requests/UpdateLiveLocationRequest.kt | 38 ------------- .../models/UpdateLiveLocationRequest.kt | 44 +++++++++++++++ .../android/client/api2/MoshiChatApiTest.kt | 2 +- .../client/api2/MoshiChatApiTestArguments.kt | 10 ++-- .../UpdateLiveLocationRequestAdapterTest.kt | 37 +++++++++++++ .../UpdateLiveLocationRequestTestData.kt | 54 +++++++++++++++++++ 8 files changed, 145 insertions(+), 52 deletions(-) delete mode 100644 stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/UpdateLiveLocationRequest.kt create mode 100644 stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdateLiveLocationRequest.kt create mode 100644 stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/UpdateLiveLocationRequestAdapterTest.kt create mode 100644 stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/UpdateLiveLocationRequestTestData.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 ffb411991a2..b6b160f5a01 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 @@ -65,7 +65,6 @@ import io.getstream.chat.android.client.api2.model.requests.SendMessageRequest import io.getstream.chat.android.client.api2.model.requests.SyncHistoryRequest import io.getstream.chat.android.client.api2.model.requests.TruncateChannelRequest import io.getstream.chat.android.client.api2.model.requests.UpdateChannelRequest -import io.getstream.chat.android.client.api2.model.requests.UpdateLiveLocationRequest import io.getstream.chat.android.client.api2.model.requests.UpdateMessageRequest import io.getstream.chat.android.client.api2.model.requests.UpsertPushPreferencesRequest import io.getstream.chat.android.client.api2.model.response.ChannelResponse @@ -166,6 +165,7 @@ import io.getstream.chat.android.network.models.SendReactionRequest 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.UpdateLiveLocationRequest import io.getstream.chat.android.network.models.UpdateMemberPartialRequest import io.getstream.chat.android.network.models.UpdateMessagePartialRequest import io.getstream.chat.android.network.models.UpdatePollOptionRequest @@ -1991,10 +1991,9 @@ constructor( override fun updateLiveLocation(location: Location): Call = userApi.updateLiveLocation( UpdateLiveLocationRequest( - message_id = location.messageId, + messageId = location.messageId, latitude = location.latitude, longitude = location.longitude, - created_by_device_id = location.deviceId, ), ).mapDomain { response -> response.toDomain() @@ -2003,9 +2002,8 @@ constructor( override fun stopLiveLocation(location: Location): Call = userApi.updateLiveLocation( UpdateLiveLocationRequest( - message_id = location.messageId, - created_by_device_id = location.deviceId, - end_at = location.endAt, + messageId = location.messageId, + endAt = location.endAt, ), ).mapDomain { response -> response.toDomain() diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/UserApi.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/UserApi.kt index b2e9820abf8..05595c5cfcb 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/UserApi.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/UserApi.kt @@ -20,7 +20,6 @@ import io.getstream.chat.android.client.api.AuthenticatedApi import io.getstream.chat.android.client.api.QueryParams import io.getstream.chat.android.client.api2.UrlQueryPayload import io.getstream.chat.android.client.api2.model.dto.DownstreamLocationDto -import io.getstream.chat.android.client.api2.model.requests.UpdateLiveLocationRequest import io.getstream.chat.android.client.api2.model.response.LiveLocationsResponse import io.getstream.chat.android.client.api2.model.response.QueryBlockedUsersResponse import io.getstream.chat.android.client.api2.model.response.UpdateUsersResponse @@ -31,6 +30,7 @@ import io.getstream.chat.android.network.models.BlockUsersResponse import io.getstream.chat.android.network.models.QueryUsersPayload import io.getstream.chat.android.network.models.UnblockUsersRequest import io.getstream.chat.android.network.models.UnblockUsersResponse +import io.getstream.chat.android.network.models.UpdateLiveLocationRequest import io.getstream.chat.android.network.models.UpdateUsersPartialRequest import io.getstream.chat.android.network.models.UpdateUsersRequest import retrofit2.http.Body diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/UpdateLiveLocationRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/UpdateLiveLocationRequest.kt deleted file mode 100644 index a49b0f7f3c6..00000000000 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/UpdateLiveLocationRequest.kt +++ /dev/null @@ -1,38 +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 - -/** - * Used to update a live location message. - * - * @param message_id The ID of the message to update. - * @param latitude The new latitude of the live location. Required to update the live location. - * @param longitude The new longitude of the live location. Required to update the live location. - * @param created_by_device_id The ID of the device that created the live location. - * @param end_at The time when the live location should end. Required to stop the live location. - */ -@JsonClass(generateAdapter = true) -internal data class UpdateLiveLocationRequest( - val message_id: String, - val latitude: Double? = null, - val longitude: Double? = null, - val created_by_device_id: String, - val end_at: Date? = null, -) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdateLiveLocationRequest.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdateLiveLocationRequest.kt new file mode 100644 index 00000000000..4c0122737df --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/UpdateLiveLocationRequest.kt @@ -0,0 +1,44 @@ +/* + * 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 UpdateLiveLocationRequest( + @Json(name = "message_id") + internal val messageId: String, + + @Json(name = "end_at") + internal val endAt: java.util.Date? = null, + + @Json(name = "latitude") + internal val latitude: Double? = null, + + @Json(name = "longitude") + internal val longitude: Double? = 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 aacee4f8a2d..2e2969618d4 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 @@ -52,7 +52,6 @@ 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.RejectInviteRequest -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.response.ChannelResponse @@ -170,6 +169,7 @@ import io.getstream.chat.android.network.models.SortParamRequest 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.UpdateLiveLocationRequest import io.getstream.chat.android.network.models.UpdateMemberPartialRequest import io.getstream.chat.android.network.models.UpdateMessagePartialRequest import io.getstream.chat.android.network.models.UpdatePollOptionRequest diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt index bc45ff08607..28513001fb0 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt @@ -30,7 +30,6 @@ import io.getstream.chat.android.client.api2.model.dto.DownstreamLocationDto import io.getstream.chat.android.client.api2.model.dto.DownstreamReminderDto import io.getstream.chat.android.client.api2.model.dto.HealthEventDto import io.getstream.chat.android.client.api2.model.dto.utils.internal.ExactDate -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.response.ChannelResponse import io.getstream.chat.android.client.api2.model.response.EventResponse @@ -84,6 +83,7 @@ import io.getstream.chat.android.network.models.Response import io.getstream.chat.android.network.models.SearchRolesResponse import io.getstream.chat.android.network.models.SearchUserGroupsResponse import io.getstream.chat.android.network.models.UnblockUsersResponse +import io.getstream.chat.android.network.models.UpdateLiveLocationRequest import io.getstream.chat.android.network.models.UpdateUserGroupResponse import io.getstream.chat.android.positiveRandomInt import io.getstream.chat.android.randomBoolean @@ -671,10 +671,9 @@ internal object MoshiChatApiTestArguments { run { val location = randomLocation() val request = UpdateLiveLocationRequest( - message_id = location.messageId, + messageId = location.messageId, latitude = location.latitude, longitude = location.longitude, - created_by_device_id = location.deviceId, ) val response = DownstreamLocationDto( message_id = location.messageId, @@ -694,9 +693,8 @@ internal object MoshiChatApiTestArguments { run { val location = randomLocation() val request = UpdateLiveLocationRequest( - message_id = location.messageId, - created_by_device_id = location.deviceId, - end_at = location.endAt, + messageId = location.messageId, + endAt = location.endAt, ) val response = DownstreamLocationDto( message_id = location.messageId, diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/UpdateLiveLocationRequestAdapterTest.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/UpdateLiveLocationRequestAdapterTest.kt new file mode 100644 index 00000000000..4b83801504c --- /dev/null +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/UpdateLiveLocationRequestAdapterTest.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.UpdateLiveLocationRequestTestData +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +internal class UpdateLiveLocationRequestAdapterTest { + private val parser = ParserFactory.createMoshiChatParser() + + @Test + fun `Serialize UpdateLiveLocationRequest with new coordinates`() { + val json = parser.toJson(UpdateLiveLocationRequestTestData.coordinateUpdate) + Assertions.assertEquals(UpdateLiveLocationRequestTestData.coordinateUpdateJson, json) + } + + @Test + fun `Serialize UpdateLiveLocationRequest that stops sharing`() { + val json = parser.toJson(UpdateLiveLocationRequestTestData.stopSharing) + Assertions.assertEquals(UpdateLiveLocationRequestTestData.stopSharingJson, json) + } +} diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/UpdateLiveLocationRequestTestData.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/UpdateLiveLocationRequestTestData.kt new file mode 100644 index 00000000000..23c43dc4465 --- /dev/null +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/UpdateLiveLocationRequestTestData.kt @@ -0,0 +1,54 @@ +/* + * 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.UpdateLiveLocationRequest +import org.intellij.lang.annotations.Language +import java.util.Date + +internal object UpdateLiveLocationRequestTestData { + + // Coordinates a 32-bit float cannot represent, so the test fails if they are ever narrowed. + private const val LATITUDE = 37.7749295 + private const val LONGITUDE = -122.4194155 + + @Language("JSON") + val coordinateUpdateJson = + """{ + "message_id": "messageId", + "latitude": 37.7749295, + "longitude": -122.4194155 + }""".withoutWhitespace() + + val coordinateUpdate = UpdateLiveLocationRequest( + messageId = "messageId", + latitude = LATITUDE, + longitude = LONGITUDE, + ) + + @Language("JSON") + val stopSharingJson = + """{ + "message_id": "messageId", + "end_at": "2020-06-10T11:04:31.588Z" + }""".withoutWhitespace() + + val stopSharing = UpdateLiveLocationRequest( + messageId = "messageId", + endAt = Date(1591787071588), + ) +}