Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ complexity:
LongMethod:
active: true
threshold: 60
# Generated code cannot be restructured to satisfy this rule: the next re-vendor would undo it.
excludes: [ '**/io/getstream/chat/android/network/**' ]
ignoreAnnotated: [ 'ParameterizedRobolectricTestRunner.Parameters' ]
LongParameterList:
active: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.getstream.chat.android.client.api

import io.getstream.chat.android.client.api.models.UploadFileResponse
import io.getstream.chat.android.client.call.RetrofitCall
import io.getstream.chat.android.client.utils.ProgressCallback
import io.getstream.chat.android.network.models.FileUploadResponse
import io.getstream.chat.android.network.models.Response
import okhttp3.MultipartBody
import retrofit2.http.DELETE
Expand All @@ -38,7 +38,7 @@ internal interface RetrofitCdnApi {
@Path("id") channelId: String,
@Part file: MultipartBody.Part,
@Tag progressCallback: ProgressCallback?,
): RetrofitCall<UploadFileResponse>
): RetrofitCall<FileUploadResponse>

@Multipart
@POST("/channels/{type}/{id}/file")
Expand All @@ -47,7 +47,7 @@ internal interface RetrofitCdnApi {
@Path("id") channelId: String,
@Part file: MultipartBody.Part,
@Tag progressCallback: ProgressCallback?,
): RetrofitCall<UploadFileResponse>
): RetrofitCall<FileUploadResponse>

@DELETE("/channels/{type}/{id}/file")
fun deleteFile(
Expand All @@ -68,7 +68,7 @@ internal interface RetrofitCdnApi {
fun uploadFile(
@Part file: MultipartBody.Part,
@Tag progressCallback: ProgressCallback?,
): RetrofitCall<UploadFileResponse>
): RetrofitCall<FileUploadResponse>

@DELETE("/uploads/file")
fun deleteFile(
Expand All @@ -80,7 +80,7 @@ internal interface RetrofitCdnApi {
fun uploadImage(
@Part file: MultipartBody.Part,
@Tag progressCallback: ProgressCallback?,
): RetrofitCall<UploadFileResponse>
): RetrofitCall<FileUploadResponse>

@DELETE("/uploads/image")
fun deleteImage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ 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
import io.getstream.chat.android.client.api2.model.response.PushPreferencesResponse
import io.getstream.chat.android.client.api2.model.response.TranslateMessageRequest
import io.getstream.chat.android.client.api2.model.response.getUserChannelPreference
import io.getstream.chat.android.client.api2.model.response.getUserPreference
import io.getstream.chat.android.client.call.RetrofitCall
Expand Down Expand Up @@ -164,6 +163,7 @@ import io.getstream.chat.android.network.models.SearchUserGroupsResponse
import io.getstream.chat.android.network.models.SendEventRequest
import io.getstream.chat.android.network.models.SendReactionRequest
import io.getstream.chat.android.network.models.SortParamRequest
import io.getstream.chat.android.network.models.TranslateMessageRequest
import io.getstream.chat.android.network.models.UnblockUsersRequest
import io.getstream.chat.android.network.models.UpdateChannelPartialRequest
import io.getstream.chat.android.network.models.UpdateMemberPartialRequest
Expand Down Expand Up @@ -1438,7 +1438,7 @@ constructor(
override fun translate(messageId: String, language: String): Call<Message> {
return messageApi.translate(
messageId = messageId,
request = TranslateMessageRequest(language),
request = TranslateMessageRequest(TranslateMessageRequest.Language.fromString(language)),
).mapDomain { response ->
response.message.toDomain()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import io.getstream.chat.android.client.api2.model.response.QueryDraftMessagesRe
import io.getstream.chat.android.client.api2.model.response.QueryReactionsResponse
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.MessageActionRequest
import io.getstream.chat.android.network.models.QueryDraftsRequest
import io.getstream.chat.android.network.models.QueryReactionsRequest
import io.getstream.chat.android.network.models.Response
import io.getstream.chat.android.network.models.SendReactionRequest
import io.getstream.chat.android.network.models.TranslateMessageRequest
import io.getstream.chat.android.network.models.UpdateMessagePartialRequest
import retrofit2.http.Body
import retrofit2.http.DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@

package io.getstream.chat.android.client.api2.mapping

import io.getstream.chat.android.client.Mother
import io.getstream.chat.android.models.UploadedFile
import org.amshove.kluent.shouldBeEqualTo
import org.junit.jupiter.api.Test
import io.getstream.chat.android.network.models.FileUploadResponse
import io.getstream.result.Error
import io.getstream.result.Result

internal class UploadFileResponseMappingTest {

@Test
fun `UploadFileResponse is correctly mapped to UploadedFile`() {
val dto = Mother.randomUploadFileResponse()
val expected = UploadedFile(
file = dto.file,
thumbUrl = dto.thumb_url,
/**
* The upload endpoints omit `file` when the asset URL is empty, which leaves nothing to attach, so
* that is reported as a failure rather than an upload with a blank URL.
*/
internal fun FileUploadResponse.toUploadedFile(): Result<UploadedFile> =
when (val uploadedFileUrl = file) {
null -> Result.Failure(Error.GenericError(message = "Missing file URL in the upload response"))
else -> Result.Success(
UploadedFile(
file = uploadedFileUrl,
thumbUrl = thumbUrl,
),
)
dto.toUploadedFile() shouldBeEqualTo expected
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ 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.TranslateMessageRequest
import io.getstream.chat.android.network.models.UpdatePollRequest
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
Expand Down Expand Up @@ -107,6 +108,10 @@ internal class MoshiChatParser(
UpdatePollRequest.VotingVisibility::class.java,
UpdatePollRequest.VotingVisibility.VotingVisibilityAdapter(),
)
.add(
TranslateMessageRequest.Language::class.java,
TranslateMessageRequest.Language.LanguageAdapter(),
)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package io.getstream.chat.android.client.uploader

import io.getstream.chat.android.client.api.RetrofitCdnApi
import io.getstream.chat.android.client.api.models.UploadFileResponse
import io.getstream.chat.android.client.api2.mapping.toUploadedFile
import io.getstream.chat.android.client.extensions.getMediaType
import io.getstream.chat.android.client.utils.ProgressCallback
import io.getstream.chat.android.models.UploadedFile
import io.getstream.chat.android.network.models.FileUploadResponse
import io.getstream.result.Result
import io.getstream.result.flatMap
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File
Expand All @@ -44,7 +45,7 @@ internal class StreamFileUploader(
channelId = channelId,
file = file.asBodyPart(),
progressCallback = callback,
).execute().map(UploadFileResponse::toUploadedFile)
).execute().flatMap(FileUploadResponse::toUploadedFile)

override fun sendFile(
channelType: String,
Expand All @@ -56,7 +57,7 @@ internal class StreamFileUploader(
channelId = channelId,
file = file.asBodyPart(),
progressCallback = null,
).execute().map(UploadFileResponse::toUploadedFile)
).execute().flatMap(FileUploadResponse::toUploadedFile)

override fun sendImage(
channelType: String,
Expand All @@ -69,7 +70,7 @@ internal class StreamFileUploader(
channelId = channelId,
file = file.asBodyPart(),
progressCallback = callback,
).execute().map(UploadFileResponse::toUploadedFile)
).execute().flatMap(FileUploadResponse::toUploadedFile)

override fun sendImage(
channelType: String,
Expand All @@ -81,7 +82,7 @@ internal class StreamFileUploader(
channelId = channelId,
file = file.asBodyPart(),
progressCallback = null,
).execute().map(UploadFileResponse::toUploadedFile)
).execute().flatMap(FileUploadResponse::toUploadedFile)

override fun deleteFile(
channelType: String,
Expand Down Expand Up @@ -111,7 +112,7 @@ internal class StreamFileUploader(
): Result<UploadedFile> = retrofitCdnApi.uploadFile(
file = file.asBodyPart(),
progressCallback = progressCallback,
).execute().map(UploadFileResponse::toUploadedFile)
).execute().flatMap(FileUploadResponse::toUploadedFile)

override fun deleteFile(
url: String,
Expand All @@ -124,7 +125,7 @@ internal class StreamFileUploader(
): Result<UploadedFile> = retrofitCdnApi.uploadImage(
file = file.asBodyPart(),
progressCallback = progressCallback,
).execute().map(UploadFileResponse::toUploadedFile)
).execute().flatMap(FileUploadResponse::toUploadedFile)

override fun deleteImage(
url: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@
* limitations under the License.
*/

package io.getstream.chat.android.client.api.models
@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 FileUploadResponse(
@Json(name = "duration")
internal val duration: String,

import com.squareup.moshi.JsonClass
@Json(name = "file")
internal val file: String? = null,

@JsonClass(generateAdapter = true)
internal data class UploadFileResponse(
val file: String,
val thumb_url: String?,
@Json(name = "thumb_url")
internal val thumbUrl: String? = null,
)
Loading
Loading