From ff09fac327dd01dd50b7852b361f6317dafc105c Mon Sep 17 00:00:00 2001 From: Boris Safonov Date: Wed, 4 Dec 2024 12:46:45 +0200 Subject: [PATCH] feat: API v7 changes --- .../api/v0/authenticated/ConversationApiV0.kt | 2 +- .../api/v7/authenticated/ConversationApiV7.kt | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ConversationApiV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ConversationApiV0.kt index 145a833620f..600c6102788 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ConversationApiV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ConversationApiV0.kt @@ -306,7 +306,7 @@ internal open class ConversationApiV0 internal constructor( } } - private suspend fun handleServiceAddedResponse( + protected suspend fun handleServiceAddedResponse( httpResponse: HttpResponse ): NetworkResponse = when (httpResponse.status) { diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConversationApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConversationApiV7.kt index cd10ebd3b2f..5e0d237b95a 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConversationApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConversationApiV7.kt @@ -19,16 +19,23 @@ package com.wire.kalium.network.api.v7.authenticated import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.authenticated.conversation.AddServiceRequest import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV6 import com.wire.kalium.network.api.model.ApiModelMapper import com.wire.kalium.network.api.model.ApiModelMapperImpl +import com.wire.kalium.network.api.model.ConversationId +import com.wire.kalium.network.api.model.ServiceAddedResponse import com.wire.kalium.network.api.model.UserId import com.wire.kalium.network.api.v6.authenticated.ConversationApiV6 +import com.wire.kalium.network.exceptions.KaliumException import com.wire.kalium.network.utils.NetworkResponse import com.wire.kalium.network.utils.mapSuccess import com.wire.kalium.network.utils.wrapKaliumResponse import io.ktor.client.request.get +import io.ktor.client.request.post +import io.ktor.client.request.setBody +import okio.IOException internal open class ConversationApiV7 internal constructor( authenticatedNetworkClient: AuthenticatedNetworkClient, @@ -42,7 +49,21 @@ internal open class ConversationApiV7 internal constructor( apiModelMapper.fromApiV6(it) } + override suspend fun addService( + addServiceRequest: AddServiceRequest, + conversationId: ConversationId + ): NetworkResponse = try { + httpClient.post("$PATH_BOT/$PATH_CONVERSATIONS/${conversationId.value}") { + setBody(addServiceRequest) + }.let { response -> + handleServiceAddedResponse(response) + } + } catch (e: IOException) { + NetworkResponse.Error(KaliumException.GenericError(e)) + } + protected companion object { const val PATH_ONE_2_ONE_CONVERSATIONS = "one2one-conversations" + const val PATH_BOT = "bot" } }