From cabcc1d1d9f565a4ae3767896f49402b65825600 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 14:04:16 +0100 Subject: [PATCH 01/22] add v7 --- .../kalium/network/BackendMetaDataUtil.kt | 4 +- .../api/v6/authenticated/AccessTokenApiV6.kt | 2 +- .../api/v7/authenticated/AccessTokenApiV7.kt | 26 +++ .../api/v7/authenticated/AssetApiV7.kt | 28 ++++ .../network/api/v7/authenticated/CallApiV7.kt | 26 +++ .../api/v7/authenticated/ClientApiV7.kt | 26 +++ .../api/v7/authenticated/ConnectionApiV7.kt | 26 +++ .../api/v7/authenticated/ConversationApiV7.kt | 43 +++++ .../network/api/v7/authenticated/E2EIApiV7.kt | 25 +++ .../v7/authenticated/FeatureConfigApiV7.kt | 26 +++ .../api/v7/authenticated/KeyPackageApiV7.kt | 26 +++ .../api/v7/authenticated/LogoutApiV7.kt | 28 ++++ .../api/v7/authenticated/MLSMessageApiV7.kt | 26 +++ .../api/v7/authenticated/MLSPublicKeyApiV7.kt | 26 +++ .../api/v7/authenticated/MessageApiV7.kt | 28 ++++ .../api/v7/authenticated/NotificationApiV7.kt | 30 ++++ .../api/v7/authenticated/PreKeyApiV7.kt | 26 +++ .../api/v7/authenticated/PropertiesApiV7.kt | 26 +++ .../network/api/v7/authenticated/SelfApiV7.kt | 28 ++++ .../api/v7/authenticated/TeamsApiV7.kt | 26 +++ .../api/v7/authenticated/UserDetailsApiV7.kt | 26 +++ .../api/v7/authenticated/UserSearchApiV7.kt | 26 +++ .../AuthenticatedNetworkContainerV7.kt | 151 ++++++++++++++++++ .../v7/unauthenticated/DomainLookupApiV7.kt | 25 +++ .../api/v7/unauthenticated/LoginApiV7.kt | 26 +++ .../api/v7/unauthenticated/RegisterApiV7.kt | 26 +++ .../api/v7/unauthenticated/SSOLoginApiV7.kt | 26 +++ .../unauthenticated/VerificationCodeApiV7.kt | 25 +++ .../UnauthenticatedNetworkContainerV7.kt | 85 ++++++++++ .../AuthenticatedNetworkContainer.kt | 10 ++ .../UnauthenticatedNetworkContainer.kt | 17 +- 31 files changed, 937 insertions(+), 8 deletions(-) create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AssetApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/CallApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ClientApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConnectionApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConversationApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/FeatureConfigApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/LogoutApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MessageApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PreKeyApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PropertiesApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/SelfApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/TeamsApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserDetailsApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserSearchApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/DomainLookupApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/LoginApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/RegisterApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/SSOLoginApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/VerificationCodeApiV7.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/networkContainer/UnauthenticatedNetworkContainerV7.kt diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt index 1053fd2ecdc..36fc88b1e8a 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt @@ -16,8 +16,6 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -@file:Suppress("MagicNumber") - package com.wire.kalium.network import com.wire.kalium.network.api.unbound.configuration.ApiVersionDTO @@ -25,7 +23,7 @@ import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.unbound.versioning.VersionInfoDTO val SupportedApiVersions = setOf(0, 1, 2, 4, 5) -val DevelopmentApiVersions = setOf(6) +val DevelopmentApiVersions = setOf(6, 7) interface BackendMetaDataUtil { fun calculateApiVersion( diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt index a37f21cd1a8..5faf053b0c7 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt @@ -21,6 +21,6 @@ package com.wire.kalium.network.api.v6.authenticated import com.wire.kalium.network.api.v5.authenticated.AccessTokenApiV5 import io.ktor.client.HttpClient -internal class AccessTokenApiV6 internal constructor( +internal open class AccessTokenApiV6 internal constructor( private val httpClient: HttpClient ) : AccessTokenApiV5(httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt new file mode 100644 index 00000000000..a96429b4b2a --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.api.v6.authenticated.AccessTokenApiV6 +import io.ktor.client.HttpClient + +internal open class AccessTokenApiV7 internal constructor( + private val httpClient: HttpClient +) : AccessTokenApiV6(httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AssetApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AssetApiV7.kt new file mode 100644 index 00000000000..8777e69fdc1 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AssetApiV7.kt @@ -0,0 +1,28 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.model.UserId +import com.wire.kalium.network.api.v6.authenticated.AssetApiV6 + +internal open class AssetApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, + selfUserId: UserId +) : AssetApiV6(authenticatedNetworkClient, selfUserId) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/CallApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/CallApiV7.kt new file mode 100644 index 00000000000..09496e880a2 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/CallApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.CallApiV6 + +internal open class CallApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : CallApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ClientApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ClientApiV7.kt new file mode 100644 index 00000000000..2f3946f13ed --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ClientApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.ClientApiV6 + +internal open class ClientApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : ClientApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConnectionApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConnectionApiV7.kt new file mode 100644 index 00000000000..b3dbf8c4d26 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConnectionApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.ConnectionApiV6 + +internal open class ConnectionApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : ConnectionApiV6(authenticatedNetworkClient) 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 new file mode 100644 index 00000000000..ff8f4090a54 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConversationApiV7.kt @@ -0,0 +1,43 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +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.UserId +import com.wire.kalium.network.api.v6.authenticated.ConversationApiV6 +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 + +internal open class ConversationApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, + private val apiModelMapper: ApiModelMapper = ApiModelMapperImpl() +) : ConversationApiV6(authenticatedNetworkClient) { + override suspend fun fetchMlsOneToOneConversation(userId: UserId): NetworkResponse = + wrapKaliumResponse { + httpClient.get("$PATH_CONVERSATIONS/$PATH_ONE_TO_ONE/${userId.domain}/${userId.value}") + }.mapSuccess { + apiModelMapper.fromApiV6(it) + } +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt new file mode 100644 index 00000000000..80957a5b0c7 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt @@ -0,0 +1,25 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.E2EIApiV6 + +internal open class E2EIApiV7 internal constructor( + private val authenticatedNetworkClient: AuthenticatedNetworkClient +) : E2EIApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/FeatureConfigApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/FeatureConfigApiV7.kt new file mode 100644 index 00000000000..ab9ec0f62b4 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/FeatureConfigApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.FeatureConfigApiV6 + +internal open class FeatureConfigApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : FeatureConfigApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt new file mode 100644 index 00000000000..cfccf210f23 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.KeyPackageApiV6 + +internal open class KeyPackageApiV7 internal constructor( + private val authenticatedNetworkClient: AuthenticatedNetworkClient +) : KeyPackageApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/LogoutApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/LogoutApiV7.kt new file mode 100644 index 00000000000..731121e8acd --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/LogoutApiV7.kt @@ -0,0 +1,28 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.LogoutApiV6 +import com.wire.kalium.network.session.SessionManager + +internal open class LogoutApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, + sessionManager: SessionManager +) : LogoutApiV6(authenticatedNetworkClient, sessionManager) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt new file mode 100644 index 00000000000..2e501a59e1f --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.MLSMessageApiV6 + +internal open class MLSMessageApiV7 internal constructor( + private val authenticatedNetworkClient: AuthenticatedNetworkClient +) : MLSMessageApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt new file mode 100644 index 00000000000..0a7837842b7 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.MLSPublicKeyApiV6 + +internal open class MLSPublicKeyApiV7 internal constructor( + private val authenticatedNetworkClient: AuthenticatedNetworkClient +) : MLSPublicKeyApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MessageApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MessageApiV7.kt new file mode 100644 index 00000000000..c7f967be701 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MessageApiV7.kt @@ -0,0 +1,28 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.base.authenticated.message.EnvelopeProtoMapper +import com.wire.kalium.network.api.v6.authenticated.MessageApiV6 + +internal open class MessageApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, + envelopeProtoMapper: EnvelopeProtoMapper +) : MessageApiV6(authenticatedNetworkClient, envelopeProtoMapper) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt new file mode 100644 index 00000000000..d4f507a7096 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt @@ -0,0 +1,30 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.AuthenticatedWebSocketClient +import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO +import com.wire.kalium.network.api.v6.authenticated.NotificationApiV6 + +internal open class NotificationApiV7 internal constructor( + private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedWebSocketClient: AuthenticatedWebSocketClient, + serverLinks: ServerConfigDTO.Links +) : NotificationApiV6(authenticatedNetworkClient, authenticatedWebSocketClient, serverLinks) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PreKeyApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PreKeyApiV7.kt new file mode 100644 index 00000000000..c50ced3d815 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PreKeyApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.PreKeyApiV6 + +internal open class PreKeyApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : PreKeyApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PropertiesApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PropertiesApiV7.kt new file mode 100644 index 00000000000..7f35c7d8b17 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PropertiesApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.PropertiesApiV6 + +internal open class PropertiesApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : PropertiesApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/SelfApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/SelfApiV7.kt new file mode 100644 index 00000000000..354a6519c78 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/SelfApiV7.kt @@ -0,0 +1,28 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.SelfApiV6 +import com.wire.kalium.network.session.SessionManager + +internal open class SelfApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, + sessionManager: SessionManager +) : SelfApiV6(authenticatedNetworkClient, sessionManager) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/TeamsApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/TeamsApiV7.kt new file mode 100644 index 00000000000..4459a2ce9ef --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/TeamsApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.TeamsApiV6 + +internal open class TeamsApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : TeamsApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserDetailsApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserDetailsApiV7.kt new file mode 100644 index 00000000000..e335745290e --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserDetailsApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.UserDetailsApiV6 + +internal open class UserDetailsApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : UserDetailsApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserSearchApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserSearchApiV7.kt new file mode 100644 index 00000000000..debd4a9c985 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserSearchApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v6.authenticated.UserSearchApiV6 + +internal open class UserSearchApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient +) : UserSearchApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt new file mode 100644 index 00000000000..8f348f105eb --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt @@ -0,0 +1,151 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated.networkContainer + +import com.wire.kalium.logger.KaliumLogger +import com.wire.kalium.network.api.base.authenticated.AccessTokenApi +import com.wire.kalium.network.api.base.authenticated.CallApi +import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi +import com.wire.kalium.network.api.base.authenticated.asset.AssetApi +import com.wire.kalium.network.api.base.authenticated.client.ClientApi +import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi +import com.wire.kalium.network.api.base.authenticated.conversation.ConversationApi +import com.wire.kalium.network.api.base.authenticated.e2ei.E2EIApi +import com.wire.kalium.network.api.base.authenticated.featureConfigs.FeatureConfigApi +import com.wire.kalium.network.api.base.authenticated.keypackage.KeyPackageApi +import com.wire.kalium.network.api.base.authenticated.logout.LogoutApi +import com.wire.kalium.network.api.base.authenticated.message.EnvelopeProtoMapperImpl +import com.wire.kalium.network.api.base.authenticated.message.MLSMessageApi +import com.wire.kalium.network.api.base.authenticated.message.MessageApi +import com.wire.kalium.network.api.base.authenticated.notification.NotificationApi +import com.wire.kalium.network.api.base.authenticated.prekey.PreKeyApi +import com.wire.kalium.network.api.base.authenticated.properties.PropertiesApi +import com.wire.kalium.network.api.base.authenticated.search.UserSearchApi +import com.wire.kalium.network.api.base.authenticated.self.SelfApi +import com.wire.kalium.network.api.base.authenticated.serverpublickey.MLSPublicKeyApi +import com.wire.kalium.network.api.base.authenticated.userDetails.UserDetailsApi +import com.wire.kalium.network.api.model.UserId +import com.wire.kalium.network.api.v7.authenticated.AccessTokenApiV7 +import com.wire.kalium.network.api.v7.authenticated.AssetApiV7 +import com.wire.kalium.network.api.v7.authenticated.CallApiV7 +import com.wire.kalium.network.api.v7.authenticated.ClientApiV7 +import com.wire.kalium.network.api.v7.authenticated.ConnectionApiV7 +import com.wire.kalium.network.api.v7.authenticated.ConversationApiV7 +import com.wire.kalium.network.api.v7.authenticated.E2EIApiV7 +import com.wire.kalium.network.api.v7.authenticated.FeatureConfigApiV7 +import com.wire.kalium.network.api.v7.authenticated.KeyPackageApiV7 +import com.wire.kalium.network.api.v7.authenticated.LogoutApiV7 +import com.wire.kalium.network.api.v7.authenticated.MLSMessageApiV7 +import com.wire.kalium.network.api.v7.authenticated.MLSPublicKeyApiV7 +import com.wire.kalium.network.api.v7.authenticated.MessageApiV7 +import com.wire.kalium.network.api.v7.authenticated.NotificationApiV7 +import com.wire.kalium.network.api.v7.authenticated.PreKeyApiV7 +import com.wire.kalium.network.api.v7.authenticated.PropertiesApiV7 +import com.wire.kalium.network.api.v7.authenticated.SelfApiV7 +import com.wire.kalium.network.api.v7.authenticated.TeamsApiV7 +import com.wire.kalium.network.api.v7.authenticated.UserDetailsApiV7 +import com.wire.kalium.network.api.v7.authenticated.UserSearchApiV7 +import com.wire.kalium.network.api.vcommon.WildCardApiImpl +import com.wire.kalium.network.defaultHttpEngine +import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProvider +import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProviderImpl +import com.wire.kalium.network.networkContainer.AuthenticatedNetworkContainer +import com.wire.kalium.network.session.CertificatePinning +import com.wire.kalium.network.session.SessionManager +import io.ktor.client.engine.HttpClientEngine +import io.ktor.websocket.WebSocketSession + +@Suppress("LongParameterList") +internal class AuthenticatedNetworkContainerV7 internal constructor( + private val sessionManager: SessionManager, + private val selfUserId: UserId, + certificatePinning: CertificatePinning, + mockEngine: HttpClientEngine?, + mockWebSocketSession: WebSocketSession?, + kaliumLogger: KaliumLogger, + engine: HttpClientEngine = mockEngine ?: defaultHttpEngine( + serverConfigDTOApiProxy = sessionManager.serverConfig().links.apiProxy, + proxyCredentials = sessionManager.proxyCredentials(), + certificatePinning = certificatePinning + ) +) : AuthenticatedNetworkContainer, + AuthenticatedHttpClientProvider by AuthenticatedHttpClientProviderImpl( + sessionManager = sessionManager, + accessTokenApi = { httpClient -> AccessTokenApiV7(httpClient) }, + engine = engine, + kaliumLogger = kaliumLogger, + webSocketSessionProvider = if (mockWebSocketSession != null) { + { _, _ -> mockWebSocketSession } + } else { + null + } + ) { + + override val accessTokenApi: AccessTokenApi get() = AccessTokenApiV7(networkClient.httpClient) + + override val logoutApi: LogoutApi get() = LogoutApiV7(networkClient, sessionManager) + + override val clientApi: ClientApi get() = ClientApiV7(networkClient) + + override val messageApi: MessageApi + get() = MessageApiV7( + networkClient, + EnvelopeProtoMapperImpl() + ) + + override val mlsMessageApi: MLSMessageApi get() = MLSMessageApiV7(networkClient) + + override val e2eiApi: E2EIApi get() = E2EIApiV7(networkClient) + + override val conversationApi: ConversationApi get() = ConversationApiV7(networkClient) + + override val keyPackageApi: KeyPackageApi get() = KeyPackageApiV7(networkClient) + + override val preKeyApi: PreKeyApi get() = PreKeyApiV7(networkClient) + + override val assetApi: AssetApi get() = AssetApiV7(networkClientWithoutCompression, selfUserId) + + override val notificationApi: NotificationApi + get() = NotificationApiV7( + networkClient, + websocketClient, + backendConfig + ) + + override val teamsApi: TeamsApi get() = TeamsApiV7(networkClient) + + override val selfApi: SelfApi get() = SelfApiV7(networkClient, sessionManager) + + override val userDetailsApi: UserDetailsApi get() = UserDetailsApiV7(networkClient) + + override val userSearchApi: UserSearchApi get() = UserSearchApiV7(networkClient) + + override val callApi: CallApi get() = CallApiV7(networkClient) + + override val connectionApi: ConnectionApi get() = ConnectionApiV7(networkClient) + + override val featureConfigApi: FeatureConfigApi get() = FeatureConfigApiV7(networkClient) + + override val mlsPublicKeyApi: MLSPublicKeyApi get() = MLSPublicKeyApiV7(networkClient) + + override val propertiesApi: PropertiesApi get() = PropertiesApiV7(networkClient) + + override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/DomainLookupApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/DomainLookupApiV7.kt new file mode 100644 index 00000000000..7eb49e09941 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/DomainLookupApiV7.kt @@ -0,0 +1,25 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.v7.unauthenticated + +import com.wire.kalium.network.UnauthenticatedNetworkClient +import com.wire.kalium.network.api.v6.unauthenticated.DomainLookupApiV6 + +internal open class DomainLookupApiV7 internal constructor( + unauthenticatedNetworkClient: UnauthenticatedNetworkClient +) : DomainLookupApiV6(unauthenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/LoginApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/LoginApiV7.kt new file mode 100644 index 00000000000..47d3953e351 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/LoginApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.unauthenticated + +import com.wire.kalium.network.UnauthenticatedNetworkClient +import com.wire.kalium.network.api.v6.unauthenticated.LoginApiV6 + +internal open class LoginApiV7 internal constructor( + unauthenticatedNetworkClient: UnauthenticatedNetworkClient +) : LoginApiV6(unauthenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/RegisterApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/RegisterApiV7.kt new file mode 100644 index 00000000000..4f6b384955d --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/RegisterApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.unauthenticated + +import com.wire.kalium.network.UnauthenticatedNetworkClient +import com.wire.kalium.network.api.v6.unauthenticated.RegisterApiV6 + +internal open class RegisterApiV7 internal constructor( + unauthenticatedNetworkClient: UnauthenticatedNetworkClient +) : RegisterApiV6(unauthenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/SSOLoginApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/SSOLoginApiV7.kt new file mode 100644 index 00000000000..8ecc50ad97c --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/SSOLoginApiV7.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.unauthenticated + +import com.wire.kalium.network.UnauthenticatedNetworkClient +import com.wire.kalium.network.api.v6.unauthenticated.SSOLoginApiV6 + +internal open class SSOLoginApiV7 internal constructor( + unauthenticatedNetworkClient: UnauthenticatedNetworkClient +) : SSOLoginApiV6(unauthenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/VerificationCodeApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/VerificationCodeApiV7.kt new file mode 100644 index 00000000000..fde0fbb268d --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/VerificationCodeApiV7.kt @@ -0,0 +1,25 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.v7.unauthenticated + +import com.wire.kalium.network.UnauthenticatedNetworkClient +import com.wire.kalium.network.api.v6.unauthenticated.VerificationCodeApiV6 + +internal open class VerificationCodeApiV7 internal constructor( + unauthenticatedNetworkClient: UnauthenticatedNetworkClient +) : VerificationCodeApiV6(unauthenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/networkContainer/UnauthenticatedNetworkContainerV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/networkContainer/UnauthenticatedNetworkContainerV7.kt new file mode 100644 index 00000000000..3f3dd9a070f --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/networkContainer/UnauthenticatedNetworkContainerV7.kt @@ -0,0 +1,85 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.unauthenticated.networkContainer + +import com.wire.kalium.network.api.base.unauthenticated.appVersioning.AppVersioningApi +import com.wire.kalium.network.api.base.unauthenticated.appVersioning.AppVersioningApiImpl +import com.wire.kalium.network.api.base.unauthenticated.domainLookup.DomainLookupApi +import com.wire.kalium.network.api.base.unauthenticated.login.LoginApi +import com.wire.kalium.network.api.base.unauthenticated.register.RegisterApi +import com.wire.kalium.network.api.base.unauthenticated.sso.SSOLoginApi +import com.wire.kalium.network.api.base.unauthenticated.verification.VerificationCodeApi +import com.wire.kalium.network.api.base.unbound.configuration.ServerConfigApi +import com.wire.kalium.network.api.base.unbound.configuration.ServerConfigApiImpl +import com.wire.kalium.network.api.base.unbound.versioning.VersionApi +import com.wire.kalium.network.api.base.unbound.versioning.VersionApiImpl +import com.wire.kalium.network.api.model.ProxyCredentialsDTO +import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO +import com.wire.kalium.network.api.v7.unauthenticated.DomainLookupApiV7 +import com.wire.kalium.network.api.v7.unauthenticated.LoginApiV7 +import com.wire.kalium.network.api.v7.unauthenticated.RegisterApiV7 +import com.wire.kalium.network.api.v7.unauthenticated.SSOLoginApiV7 +import com.wire.kalium.network.api.v7.unauthenticated.VerificationCodeApiV7 +import com.wire.kalium.network.defaultHttpEngine +import com.wire.kalium.network.networkContainer.UnauthenticatedNetworkClientProvider +import com.wire.kalium.network.networkContainer.UnauthenticatedNetworkClientProviderImpl +import com.wire.kalium.network.networkContainer.UnauthenticatedNetworkContainer +import com.wire.kalium.network.session.CertificatePinning +import io.ktor.client.engine.HttpClientEngine + +@Suppress("LongParameterList") +class UnauthenticatedNetworkContainerV7 internal constructor( + backendLinks: ServerConfigDTO, + proxyCredentials: ProxyCredentialsDTO?, + certificatePinning: CertificatePinning, + mockEngine: HttpClientEngine?, + engine: HttpClientEngine = mockEngine ?: defaultHttpEngine( + serverConfigDTOApiProxy = backendLinks.links.apiProxy, + proxyCredentials = proxyCredentials, + certificatePinning = certificatePinning + ), + private val developmentApiEnabled: Boolean +) : UnauthenticatedNetworkContainer, + UnauthenticatedNetworkClientProvider by UnauthenticatedNetworkClientProviderImpl( + backendLinks, + engine + ) { + override val loginApi: LoginApi get() = LoginApiV7(unauthenticatedNetworkClient) + override val verificationCodeApi: VerificationCodeApi + get() = VerificationCodeApiV7( + unauthenticatedNetworkClient + ) + override val domainLookupApi: DomainLookupApi + get() = DomainLookupApiV7( + unauthenticatedNetworkClient + ) + override val remoteVersion: VersionApi + get() = VersionApiImpl( + unauthenticatedNetworkClient, + developmentApiEnabled = developmentApiEnabled + ) + override val serverConfigApi: ServerConfigApi + get() = ServerConfigApiImpl(unauthenticatedNetworkClient) + override val registerApi: RegisterApi get() = RegisterApiV7(unauthenticatedNetworkClient) + override val sso: SSOLoginApi get() = SSOLoginApiV7(unauthenticatedNetworkClient) + override val appVersioningApi: AppVersioningApi + get() = AppVersioningApiImpl( + unauthenticatedNetworkClient + ) +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index d46fe227c44..6eb175d3280 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -49,6 +49,7 @@ import com.wire.kalium.network.api.v2.authenticated.networkContainer.Authenticat import com.wire.kalium.network.api.v4.authenticated.networkContainer.AuthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.authenticated.networkContainer.AuthenticatedNetworkContainerV5 import com.wire.kalium.network.api.v6.authenticated.networkContainer.AuthenticatedNetworkContainerV6 +import com.wire.kalium.network.api.v7.authenticated.networkContainer.AuthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager import io.ktor.client.HttpClient @@ -188,6 +189,15 @@ interface AuthenticatedNetworkContainer { kaliumLogger ) + 7 -> AuthenticatedNetworkContainerV7( + sessionManager, + selfUserId, + certificatePinning, + mockEngine, + mockWebSocketSession, + kaliumLogger + ) + else -> error("Unsupported version: $version") } } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt index 54a0579d0db..194f9775d34 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt @@ -19,21 +19,22 @@ package com.wire.kalium.network.networkContainer import com.wire.kalium.network.UnauthenticatedNetworkClient -import com.wire.kalium.network.api.model.ProxyCredentialsDTO +import com.wire.kalium.network.api.base.unauthenticated.appVersioning.AppVersioningApi import com.wire.kalium.network.api.base.unauthenticated.domainLookup.DomainLookupApi import com.wire.kalium.network.api.base.unauthenticated.login.LoginApi +import com.wire.kalium.network.api.base.unauthenticated.register.RegisterApi import com.wire.kalium.network.api.base.unauthenticated.sso.SSOLoginApi import com.wire.kalium.network.api.base.unauthenticated.verification.VerificationCodeApi -import com.wire.kalium.network.api.base.unauthenticated.appVersioning.AppVersioningApi -import com.wire.kalium.network.api.base.unauthenticated.register.RegisterApi import com.wire.kalium.network.api.base.unbound.configuration.ServerConfigApi -import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.base.unbound.versioning.VersionApi +import com.wire.kalium.network.api.model.ProxyCredentialsDTO +import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.v0.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV0 import com.wire.kalium.network.api.v2.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV2 import com.wire.kalium.network.api.v4.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV5 import com.wire.kalium.network.api.v6.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV6 +import com.wire.kalium.network.api.v7.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import io.ktor.client.engine.HttpClientEngine @@ -120,6 +121,14 @@ interface UnauthenticatedNetworkContainer { developmentApiEnabled = developmentApiEnabled ) + 7 -> UnauthenticatedNetworkContainerV7( + backendLinks = serverConfigDTO, + proxyCredentials = proxyCredentials, + certificatePinning = certificatePinning, + mockEngine = mockEngine, + developmentApiEnabled = developmentApiEnabled + ) + else -> error("Unsupported version: ${serverConfigDTO.metaData.commonApiVersion.version}") } } From d824dba90397fc6ab4ae143c6266091aa647b866 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 14:04:36 +0100 Subject: [PATCH 02/22] capabilities update --- .../api/authenticated/client/ClientDTO.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt index 9d070bfa2bd..eb2420fe538 100644 --- a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt @@ -20,6 +20,12 @@ package com.wire.kalium.network.api.authenticated.client import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationException +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonTransformingSerializer @Serializable data class ClientDTO( @@ -30,11 +36,28 @@ data class ClientDTO( @SerialName("id") val clientId: String, @SerialName("type") val type: ClientTypeDTO, @SerialName("class") val deviceType: DeviceTypeDTO = DeviceTypeDTO.Unknown, - @SerialName("capabilities") val capabilities: Capabilities?, + @SerialName("capabilities") + @Serializable(with = CapabilitiesDeserializer::class) + val capabilities: List, @SerialName("label") val label: String?, @SerialName("mls_public_keys") val mlsPublicKeys: Map? ) +/** + * Sometimes the capabilities are wrapped in an object, sometimes they are just an array. + * See [documentation](https://wearezeta.atlassian.net/wiki/spaces/ENGINEERIN/pages/1309868033/API+changes+v6+v7) + */ +object CapabilitiesDeserializer : + JsonTransformingSerializer>(ListSerializer(ClientCapabilityDTO.serializer())) { + override fun transformDeserialize(element: JsonElement): JsonElement { + return when { + element is JsonObject && element.containsKey("capabilities") -> element["capabilities"]!! + element is JsonArray -> element + else -> throw SerializationException("Unexpected JSON format for capabilities") + } + } +} + @Serializable data class ClientsOfUsersResponse( @SerialName("qualified_user_map") val qualifiedMap: Map>> From 635143807e28de853a547d329ce042ec55d14fa9 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 14:51:58 +0100 Subject: [PATCH 03/22] remove too much copied code --- .../api/v7/authenticated/ConversationApiV7.kt | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) 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 ff8f4090a54..3adeb273b44 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,25 +19,8 @@ package com.wire.kalium.network.api.v7.authenticated import com.wire.kalium.network.AuthenticatedNetworkClient -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.UserId import com.wire.kalium.network.api.v6.authenticated.ConversationApiV6 -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 internal open class ConversationApiV7 internal constructor( authenticatedNetworkClient: AuthenticatedNetworkClient, - private val apiModelMapper: ApiModelMapper = ApiModelMapperImpl() -) : ConversationApiV6(authenticatedNetworkClient) { - override suspend fun fetchMlsOneToOneConversation(userId: UserId): NetworkResponse = - wrapKaliumResponse { - httpClient.get("$PATH_CONVERSATIONS/$PATH_ONE_TO_ONE/${userId.domain}/${userId.value}") - }.mapSuccess { - apiModelMapper.fromApiV6(it) - } -} +) : ConversationApiV6(authenticatedNetworkClient) From 98002e1b9fbda0fc0cfd174411ff24ef0a8caefa Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Tue, 12 Nov 2024 08:35:13 +0100 Subject: [PATCH 04/22] one2one paths change --- .../api/v7/authenticated/ConversationApiV7.kt | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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 3adeb273b44..7f36d57cd89 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,8 +19,43 @@ package com.wire.kalium.network.api.v7.authenticated import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse +import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV3 +import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV6 +import com.wire.kalium.network.api.authenticated.conversation.CreateConversationRequest +import com.wire.kalium.network.api.model.ApiModelMapper +import com.wire.kalium.network.api.model.ApiModelMapperImpl +import com.wire.kalium.network.api.model.UserId import com.wire.kalium.network.api.v6.authenticated.ConversationApiV6 +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 internal open class ConversationApiV7 internal constructor( authenticatedNetworkClient: AuthenticatedNetworkClient, -) : ConversationApiV6(authenticatedNetworkClient) + private val apiModelMapper: ApiModelMapper = ApiModelMapperImpl(), +) : ConversationApiV6(authenticatedNetworkClient) { + override suspend fun createOne2OneConversation( + createConversationRequest: CreateConversationRequest + ): NetworkResponse = wrapKaliumResponse { + httpClient.post(PATH_ONE_2_ONE_CONVERSATIONS) { + setBody(apiModelMapper.toApiV3(createConversationRequest)) + } + }.mapSuccess { + apiModelMapper.fromApiV3(it) + } + + override suspend fun fetchMlsOneToOneConversation(userId: UserId): NetworkResponse = + wrapKaliumResponse { + httpClient.get("$PATH_ONE_2_ONE_CONVERSATIONS/${userId.domain}/${userId.value}") + }.mapSuccess { + apiModelMapper.fromApiV6(it) + } + + protected companion object { + const val PATH_ONE_2_ONE_CONVERSATIONS = "one2one-conversations" + } +} From 4189e4c3cd60c93526e5c6a710c02564d48877df Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Tue, 12 Nov 2024 10:02:57 +0100 Subject: [PATCH 05/22] revert magic number Suppress --- .../kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt | 2 ++ .../kalium/network/api/v4/authenticated/NotificationApiV4.kt | 2 +- .../kalium/network/api/v5/authenticated/NotificationApiV5.kt | 2 +- .../kalium/network/api/v6/authenticated/NotificationApiV6.kt | 2 +- .../kalium/network/api/v7/authenticated/NotificationApiV7.kt | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt index 36fc88b1e8a..4ddf1328f87 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt @@ -16,6 +16,8 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ +@file:Suppress("MagicNumber") + package com.wire.kalium.network import com.wire.kalium.network.api.unbound.configuration.ApiVersionDTO diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/NotificationApiV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/NotificationApiV4.kt index 708ab68f776..11b383fbd2c 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/NotificationApiV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/NotificationApiV4.kt @@ -24,7 +24,7 @@ import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.v3.authenticated.NotificationApiV3 internal open class NotificationApiV4 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedNetworkClient: AuthenticatedNetworkClient, authenticatedWebSocketClient: AuthenticatedWebSocketClient, serverLinks: ServerConfigDTO.Links ) : NotificationApiV3(authenticatedNetworkClient, authenticatedWebSocketClient, serverLinks) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/NotificationApiV5.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/NotificationApiV5.kt index cb50ef1396a..52e0e02168b 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/NotificationApiV5.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/NotificationApiV5.kt @@ -24,7 +24,7 @@ import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.v4.authenticated.NotificationApiV4 internal open class NotificationApiV5 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedNetworkClient: AuthenticatedNetworkClient, authenticatedWebSocketClient: AuthenticatedWebSocketClient, serverLinks: ServerConfigDTO.Links ) : NotificationApiV4(authenticatedNetworkClient, authenticatedWebSocketClient, serverLinks) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/NotificationApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/NotificationApiV6.kt index efe6083f0a4..e5883353969 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/NotificationApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/NotificationApiV6.kt @@ -24,7 +24,7 @@ import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.v5.authenticated.NotificationApiV5 internal open class NotificationApiV6 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedNetworkClient: AuthenticatedNetworkClient, authenticatedWebSocketClient: AuthenticatedWebSocketClient, serverLinks: ServerConfigDTO.Links ) : NotificationApiV5(authenticatedNetworkClient, authenticatedWebSocketClient, serverLinks) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt index d4f507a7096..b47dd923243 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt @@ -24,7 +24,7 @@ import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.v6.authenticated.NotificationApiV6 internal open class NotificationApiV7 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedNetworkClient: AuthenticatedNetworkClient, authenticatedWebSocketClient: AuthenticatedWebSocketClient, serverLinks: ServerConfigDTO.Links ) : NotificationApiV6(authenticatedNetworkClient, authenticatedWebSocketClient, serverLinks) From e3927d89b3d73d193b3b7bbc953485707fae58c5 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Wed, 13 Nov 2024 12:24:02 +0100 Subject: [PATCH 06/22] tests and CR changes --- .../com/wire/kalium/logic/data/event/Event.kt | 4 +- .../kalium/logic/data/event/EventMapper.kt | 2 +- .../NewConversationEventHandler.kt | 38 ++-- .../kalium/mocks/mocks/client/ClientMocks.kt | 42 ----- .../mocks/responses/ClientResponseJson.kt | 42 ++++- .../responses/ListOfClientsResponseJson.kt | 5 +- .../NotificationEventsResponseJson.kt | 4 +- .../conversation/ConversationResponseJson.kt | 166 +++++++++++------- .../client/CapabilitiesDeserializer.kt | 40 +++++ .../api/authenticated/client/ClientDTO.kt | 21 --- .../conversation/ConversationResponse.kt | 3 + .../wire/kalium/network/KaliumHttpLogger.kt | 4 +- .../kalium/network/KaliumKtorCustomLogging.kt | 24 +-- .../conversation/ConversationApi.kt | 26 ++- .../notification/NotificationApi.kt | 4 +- .../api/v0/authenticated/ConversationApiV0.kt | 11 +- .../api/v2/authenticated/PreKeyApiV2.kt | 2 +- .../api/v2/authenticated/PropertiesApiV2.kt | 2 +- .../api/v3/authenticated/ConversationApiV3.kt | 10 -- .../api/v3/authenticated/PropertiesApiV3.kt | 2 +- .../api/v4/authenticated/AccessTokenApiV4.kt | 2 +- .../api/v4/authenticated/PropertiesApiV4.kt | 2 +- .../api/v5/authenticated/AccessTokenApiV5.kt | 2 +- .../api/v6/authenticated/AccessTokenApiV6.kt | 2 +- .../network/api/v6/authenticated/E2EIApiV6.kt | 2 +- .../api/v6/authenticated/KeyPackageApiV6.kt | 2 +- .../api/v6/authenticated/MLSMessageApiV6.kt | 2 +- .../api/v6/authenticated/MLSPublicKeyApiV6.kt | 2 +- .../api/v7/authenticated/AccessTokenApiV7.kt | 2 +- .../api/v7/authenticated/ConversationApiV7.kt | 13 -- .../network/api/v7/authenticated/E2EIApiV7.kt | 2 +- .../api/v7/authenticated/KeyPackageApiV7.kt | 2 +- .../api/v7/authenticated/MLSMessageApiV7.kt | 2 +- .../api/v7/authenticated/MLSPublicKeyApiV7.kt | 2 +- .../kalium/network/utils/ObfuscateUtil.kt | 1 - .../client/ClientDTOSerializationTest.kt | 41 +++++ .../kalium/api/v7/ConversationApiV7Test.kt | 64 +++++++ 37 files changed, 368 insertions(+), 229 deletions(-) delete mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt create mode 100644 network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/CapabilitiesDeserializer.kt create mode 100644 network/src/commonTest/kotlin/com/wire/kalium/api/authenticated/client/ClientDTOSerializationTest.kt create mode 100644 network/src/commonTest/kotlin/com/wire/kalium/api/v7/ConversationApiV7Test.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt index 8a580fd5514..ea2b0742ac4 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt @@ -45,7 +45,7 @@ import com.wire.kalium.logic.data.user.Connection import com.wire.kalium.logic.data.user.SupportedProtocol import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.sync.incremental.EventSource -import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse +import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV6 import com.wire.kalium.util.DateTimeUtil import com.wire.kalium.util.DateTimeUtil.toIsoDateTimeString import com.wire.kalium.util.serialization.toJsonElement @@ -182,7 +182,7 @@ sealed class Event(open val id: String) { override val conversationId: ConversationId, val senderUserId: UserId, val dateTime: Instant, - val conversation: ConversationResponse + val conversation: ConversationResponseV6 ) : Conversation(id, conversationId) { override fun toLogMap(): Map = mapOf( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt index ba1fb539fd8..54a9c614746 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt @@ -377,7 +377,7 @@ class EventMapper( eventContentDTO.qualifiedConversation.toModel(), eventContentDTO.qualifiedFrom.toModel(), eventContentDTO.time, - eventContentDTO.data + eventContentDTO.data.toV6() ) fun conversationMemberJoin( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt index b1db1765b00..b2e8565aefc 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt @@ -55,14 +55,21 @@ internal class NewConversationEventHandlerImpl( val eventLogger = kaliumLogger.createEventProcessingLogger(event) val selfUserTeamId = selfTeamIdProvider().getOrNull() conversationRepository - .persistConversation(event.conversation, selfUserTeamId?.value, true) + .persistConversation(event.conversation.conversation, selfUserTeamId?.value, true) .flatMap { isNewUnhandledConversation -> resolveConversationIfOneOnOne(selfUserTeamId, event) .flatMap { - conversationRepository.updateConversationModifiedDate(event.conversationId, DateTimeUtil.currentInstant()) + conversationRepository.updateConversationModifiedDate( + event.conversationId, + DateTimeUtil.currentInstant() + ) } .flatMap { - userRepository.fetchUsersIfUnknownByIds(event.conversation.members.otherMembers.map { it.id.toModel() }.toSet()) + userRepository.fetchUsersIfUnknownByIds( + event.conversation.conversation.members.otherMembers.map { + it.id.toModel() + }.toSet() + ) } .map { isNewUnhandledConversation } }.onSuccess { isNewUnhandledConversation -> @@ -73,9 +80,13 @@ internal class NewConversationEventHandlerImpl( } } - private suspend fun resolveConversationIfOneOnOne(selfUserTeamId: TeamId?, event: Event.Conversation.NewConversation) = - if (event.conversation.toConversationType(selfUserTeamId) == ConversationEntity.Type.ONE_ON_ONE) { - val otherUserId = event.conversation.members.otherMembers.first().id.toModel() + private suspend fun resolveConversationIfOneOnOne( + selfUserTeamId: TeamId?, + event: Event.Conversation.NewConversation + ) = + if (event.conversation.conversation.toConversationType(selfUserTeamId) == ConversationEntity.Type.ONE_ON_ONE) { + val otherUserId = + event.conversation.conversation.members.otherMembers.first().id.toModel() oneOnOneResolver.resolveOneOnOneConversationWithUserId( userId = otherUserId, invalidateCurrentKnownProtocols = true @@ -94,15 +105,22 @@ internal class NewConversationEventHandlerImpl( event: Event.Conversation.NewConversation ) { if (isNewUnhandledConversation) { - newGroupConversationSystemMessagesCreator.conversationStarted(event.senderUserId, event.conversation, event.dateTime) + newGroupConversationSystemMessagesCreator.conversationStarted( + event.senderUserId, + event.conversation.conversation, + event.dateTime + ) newGroupConversationSystemMessagesCreator.conversationResolvedMembersAdded( event.conversationId.toDao(), - event.conversation.members.otherMembers.map { it.id.toModel() }, + event.conversation.conversation.members.otherMembers.map { it.id.toModel() }, + event.dateTime + ) + newGroupConversationSystemMessagesCreator.conversationReadReceiptStatus( + event.conversation.conversation, event.dateTime ) - newGroupConversationSystemMessagesCreator.conversationReadReceiptStatus(event.conversation, event.dateTime) newGroupConversationSystemMessagesCreator.conversationStartedUnverifiedWarning( - event.conversation.id.toModel(), + event.conversation.conversation.id.toModel(), event.dateTime ) } diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt deleted file mode 100644 index 94c7f1fe86c..00000000000 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Wire - * Copyright (C) 2024 Wire Swiss GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - */ -package com.wire.kalium.mocks.mocks.client - -import com.wire.kalium.network.api.authenticated.client.Capabilities -import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO -import com.wire.kalium.network.api.authenticated.client.ClientDTO -import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO -import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO - -object ClientMocks { - - const val selfClientId = "defkrr8e7grgsoufhg8" - - val selfClient = ClientDTO( - clientId = selfClientId, - type = ClientTypeDTO.Permanent, - deviceType = DeviceTypeDTO.Phone, - registrationTime = "2021-05-12T10:52:02.671Z", - lastActive = "2021-05-12T10:52:02.671Z", - label = "label", - cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd", - capabilities = Capabilities(listOf(ClientCapabilityDTO.LegalHoldImplicitConsent)), - model = "model", - mlsPublicKeys = null - ) -} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ClientResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ClientResponseJson.kt index 6b5f180ec67..d3d7e0010e1 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ClientResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ClientResponseJson.kt @@ -18,7 +18,6 @@ package com.wire.kalium.mocks.responses -import com.wire.kalium.network.api.authenticated.client.Capabilities import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO import com.wire.kalium.network.api.authenticated.client.ClientDTO import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO @@ -26,6 +25,26 @@ import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO object ClientResponseJson { private val jsonProvider = { serializable: ClientDTO -> + """ + |{ + | "id": "${serializable.clientId}", + | "type": "${serializable.type}", + | "time": "${serializable.registrationTime}", + | "last_active": "${serializable.lastActive}", + | "class": "${serializable.deviceType}", + | "label": "${serializable.label}", + | "cookie": "${serializable.cookie}", + | "model": "${serializable.model}", + | "capabilities": [ + | "${serializable.capabilities[0]}" + | ], + | "mls_public_keys": ${serializable.mlsPublicKeys} + |} + """.trimMargin() + } + + // This is backwards compatible with the old format till v5 API get deprecated + private val jsonProviderCapabilitiesObject = { serializable: ClientDTO -> """ |{ | "id": "${serializable.clientId}", @@ -38,13 +57,30 @@ object ClientResponseJson { | "model": "${serializable.model}", | "capabilities": { | "capabilities": [ - | "${serializable.capabilities!!.capabilities[0]}" + | "${serializable.capabilities[0]}" | ] | } + | "mls_public_keys": ${serializable.mlsPublicKeys} |} """.trimMargin() } + val validCapabilitiesObject = ValidJsonProvider( + ClientDTO( + clientId = "defkrr8e7grgsoufhg8", + type = ClientTypeDTO.Permanent, + deviceType = DeviceTypeDTO.Phone, + registrationTime = "2021-05-12T10:52:02.671Z", + lastActive = "2021-05-12T10:52:02.671Z", + label = "label", + cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd", + capabilities = listOf(ClientCapabilityDTO.LegalHoldImplicitConsent), + model = "model", + mlsPublicKeys = null + ), + jsonProviderCapabilitiesObject + ) + val valid = ValidJsonProvider( ClientDTO( clientId = "defkrr8e7grgsoufhg8", @@ -54,7 +90,7 @@ object ClientResponseJson { lastActive = "2021-05-12T10:52:02.671Z", label = "label", cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd", - capabilities = Capabilities(listOf(ClientCapabilityDTO.LegalHoldImplicitConsent)), + capabilities = listOf(ClientCapabilityDTO.LegalHoldImplicitConsent), model = "model", mlsPublicKeys = null ), diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ListOfClientsResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ListOfClientsResponseJson.kt index 944d1a4506f..242ce69b754 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ListOfClientsResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ListOfClientsResponseJson.kt @@ -18,7 +18,6 @@ package com.wire.kalium.mocks.responses -import com.wire.kalium.network.api.authenticated.client.Capabilities import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO import com.wire.kalium.network.api.authenticated.client.ClientDTO import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO @@ -38,7 +37,7 @@ object ListOfClientsResponseJson { | "model": "${serializable.model}", | "capabilities": { | "capabilities": [ - | "${serializable.capabilities!!.capabilities[0]}" + | "${serializable.capabilities[0]}" | ] | } |}] @@ -54,7 +53,7 @@ object ListOfClientsResponseJson { lastActive = "2023-05-12T10:52:02.671Z", label = "label", cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd", - capabilities = Capabilities(listOf(ClientCapabilityDTO.LegalHoldImplicitConsent)), + capabilities = listOf(ClientCapabilityDTO.LegalHoldImplicitConsent), model = "model", mlsPublicKeys = null ), diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt index b80008137f6..2d57de3813f 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt @@ -77,7 +77,7 @@ object NotificationEventsResponseJson { type = ClientTypeDTO.Permanent, deviceType = DeviceTypeDTO.Desktop, label = "OS X 10.15 10.15", - capabilities = null, + capabilities = listOf(), mlsPublicKeys = mapOf(Pair("key_variant", "public_key")), ) ), @@ -157,7 +157,7 @@ object NotificationEventsResponseJson { | "id" : "${eventData.qualifiedFrom.value}", | "domain" : "${eventData.qualifiedFrom.domain}" | }, - | "data" : ${ConversationResponseJson.conversationResponseSerializer(eventData.data)}, + | "data" : ${ConversationResponseJson.conversationResponseSerializer(eventData.data.toV6())}, | "time" : "2022-04-12T13:57:02.414Z", | "type" : "conversation.create" |} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt index d8a59679053..cab77c6e97d 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt @@ -24,9 +24,11 @@ import com.wire.kalium.network.api.authenticated.conversation.ConvProtocol import com.wire.kalium.network.api.authenticated.conversation.ConversationMemberDTO import com.wire.kalium.network.api.authenticated.conversation.ConversationMembersResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse +import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV6 import com.wire.kalium.network.api.authenticated.conversation.MutedStatus import com.wire.kalium.network.api.authenticated.conversation.ReceiptMode import com.wire.kalium.network.api.authenticated.conversation.ServiceReferenceDTO +import com.wire.kalium.network.api.authenticated.serverpublickey.MLSPublicKeysDTO import com.wire.kalium.network.api.model.ConversationAccessDTO import com.wire.kalium.network.api.model.ConversationAccessRoleDTO import com.wire.kalium.network.api.model.QualifiedID @@ -41,95 +43,135 @@ import kotlinx.serialization.json.putJsonObject object ConversationResponseJson { - val conversationResponseSerializer = { it: ConversationResponse -> + val conversationResponseSerializer = { it: ConversationResponseV6 -> buildConversationResponse(it).toString() } + val conversationResponseSerializerV3 = { it: ConversationResponse -> + buildConversationResponseV3(it).toString() + } + val conversationResponseSerializerWithDeprecatedAccessRole = { it: ConversationResponse -> - buildConversationResponse(it, useDeprecatedAccessRole = true).toString() + buildConversationResponseV3(it, useDeprecatedAccessRole = true).toString() } - private val conversationResponse = ConversationResponse( - "fdf23116-42a5-472c-8316-e10655f5d11e", - ConversationMembersResponse( - ConversationMemberDTO.Self( - QualifiedIDSamples.one, - "wire_admin", - otrMutedRef = "2022-04-11T14:15:48.044Z", - otrMutedStatus = MutedStatus.fromOrdinal(0) + private val conversationResponse = ConversationResponseV6( + conversation = ConversationResponse( + "fdf23116-42a5-472c-8316-e10655f5d11e", + ConversationMembersResponse( + ConversationMemberDTO.Self( + QualifiedIDSamples.one, + "wire_admin", + otrMutedRef = "2022-04-11T14:15:48.044Z", + otrMutedStatus = MutedStatus.fromOrdinal(0) + ), + listOf( + ConversationMemberDTO.Other( + id = QualifiedIDSamples.two, + conversationRole = "wire_member" + ) + ) ), - listOf( -// ConversationMemberDTO.Other(id = QualifiedIDSamples.two, conversationRole = "wire_member") - ) - ), - "group name", - QualifiedIDSamples.one, - "groupID", - 0UL, - ConversationResponse.Type.GROUP, - null, - "teamID", - ConvProtocol.PROTEUS, - lastEventTime = "2022-03-30T15:36:00.000Z", - access = setOf(ConversationAccessDTO.INVITE, ConversationAccessDTO.CODE), - accessRole = setOf( - ConversationAccessRoleDTO.GUEST, - ConversationAccessRoleDTO.TEAM_MEMBER, - ConversationAccessRoleDTO.NON_TEAM_MEMBER - ), - mlsCipherSuiteTag = null, - receiptMode = ReceiptMode.DISABLED + "group name", + QualifiedIDSamples.one, + "groupID", + 0UL, + ConversationResponse.Type.GROUP, + null, + "teamID", + ConvProtocol.PROTEUS, + lastEventTime = "2022-03-30T15:36:00.000Z", + access = setOf(ConversationAccessDTO.INVITE, ConversationAccessDTO.CODE), + accessRole = setOf( + ConversationAccessRoleDTO.GUEST, + ConversationAccessRoleDTO.TEAM_MEMBER, + ConversationAccessRoleDTO.NON_TEAM_MEMBER + ), + mlsCipherSuiteTag = null, + receiptMode = ReceiptMode.DISABLED, + + ), + publicKeys = MLSPublicKeysDTO( + removal = mapOf("ecdsa_secp256r1_sha256" to "string", "ed25519" to "string") + ) ) - val v3 = ValidJsonProvider( + val v6 = ValidJsonProvider( conversationResponse, conversationResponseSerializer ) + val v3 = ValidJsonProvider( + conversationResponse.conversation, + conversationResponseSerializerV3 + ) + fun v0(accessRole: Set? = null) = ValidJsonProvider( - conversationResponse.copy( - accessRole = accessRole ?: conversationResponse.accessRole + conversationResponse.conversation.copy( + accessRole = accessRole ?: conversationResponse.conversation.accessRole ), conversationResponseSerializerWithDeprecatedAccessRole ) } fun buildConversationResponse( + conversationResponse: ConversationResponseV6, + useDeprecatedAccessRole: Boolean = false, +): JsonObject = buildJsonObject { + putJsonObject("conversation") { + putConversation(conversationResponse.conversation, useDeprecatedAccessRole) + } + putJsonObject("public_keys") { + conversationResponse.publicKeys.removal?.forEach { (key, value) -> + put(key, value) + } + } + +} + +fun buildConversationResponseV3( conversationResponse: ConversationResponse, useDeprecatedAccessRole: Boolean = false -): JsonObject = - buildJsonObject { - put("creator", conversationResponse.creator) - putQualifiedId(conversationResponse.id) - conversationResponse.groupId?.let { put("group_id", it) } - putJsonObject("members") { - putSelfMember(conversationResponse.members.self) - putJsonArray("others") { - conversationResponse.members.otherMembers.forEach { otherMember -> - addJsonObject { - putOtherMember(otherMember) - } +): JsonObject = buildJsonObject { + putConversation(conversationResponse, useDeprecatedAccessRole) +} + +private fun JsonObjectBuilder.putConversation( + conversationResponse: ConversationResponse, + useDeprecatedAccessRole: Boolean +) { + put("creator", conversationResponse.creator) + putQualifiedId(conversationResponse.id) + conversationResponse.groupId?.let { put("group_id", it) } + putJsonObject("members") { + putSelfMember(conversationResponse.members.self) + putJsonArray("others") { + conversationResponse.members.otherMembers.forEach { otherMember -> + addJsonObject { + putOtherMember(otherMember) } } } - put("type", conversationResponse.type.ordinal) - put("protocol", conversationResponse.protocol.toString()) - put("last_event_time", conversationResponse.lastEventTime) - putAccessSet(conversationResponse.access) - if (useDeprecatedAccessRole) { - conversationResponse.accessRole?.let { putDeprecatedAccessRoleSet(it) } - } else { - conversationResponse.accessRole?.let { putAccessRoleSet(it) } - } - conversationResponse.messageTimer?.let { put("message_timer", it) } - conversationResponse.name?.let { put("name", it) } - conversationResponse.teamId?.let { put("team", it) } - conversationResponse.mlsCipherSuiteTag?.let { put("cipher_suite", it) } } - -fun JsonObjectBuilder.putAccessRoleSet(accessRole: Set) = putJsonArray("access_role") { - accessRole.forEach { add(it.toString()) } + put("type", conversationResponse.type.ordinal) + put("protocol", conversationResponse.protocol.toString()) + put("last_event_time", conversationResponse.lastEventTime) + putAccessSet(conversationResponse.access) + if (useDeprecatedAccessRole) { + conversationResponse.accessRole?.let { putDeprecatedAccessRoleSet(it) } + } else { + conversationResponse.accessRole?.let { putAccessRoleSet(it) } + } + conversationResponse.messageTimer?.let { put("message_timer", it) } + conversationResponse.name?.let { put("name", it) } + conversationResponse.teamId?.let { put("team", it) } + conversationResponse.mlsCipherSuiteTag?.let { put("cipher_suite", it) } } +fun JsonObjectBuilder.putAccessRoleSet(accessRole: Set) = + putJsonArray("access_role") { + accessRole.forEach { add(it.toString()) } + } + fun JsonObjectBuilder.putDeprecatedAccessRoleSet(accessRole: Set) = putJsonArray("access_role_v2") { accessRole.forEach { add(it.toString()) } diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/CapabilitiesDeserializer.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/CapabilitiesDeserializer.kt new file mode 100644 index 00000000000..165eb7c1b0c --- /dev/null +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/CapabilitiesDeserializer.kt @@ -0,0 +1,40 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.authenticated.client + +import kotlinx.serialization.SerializationException +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonTransformingSerializer + +/** + * Sometimes the capabilities are wrapped in an object, sometimes they are just an array. + * See [documentation](https://wearezeta.atlassian.net/wiki/spaces/ENGINEERIN/pages/1309868033/API+changes+v6+v7) + */ +object CapabilitiesDeserializer : + JsonTransformingSerializer>(ListSerializer(ClientCapabilityDTO.serializer())) { + override fun transformDeserialize(element: JsonElement): JsonElement { + return when { + element is JsonObject && element.containsKey("capabilities") -> element["capabilities"]!! + element is JsonArray -> element + else -> throw SerializationException("Unexpected JSON format for capabilities") + } + } +} diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt index eb2420fe538..c8253498b87 100644 --- a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt @@ -20,12 +20,6 @@ package com.wire.kalium.network.api.authenticated.client import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.SerializationException -import kotlinx.serialization.builtins.ListSerializer -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonTransformingSerializer @Serializable data class ClientDTO( @@ -43,21 +37,6 @@ data class ClientDTO( @SerialName("mls_public_keys") val mlsPublicKeys: Map? ) -/** - * Sometimes the capabilities are wrapped in an object, sometimes they are just an array. - * See [documentation](https://wearezeta.atlassian.net/wiki/spaces/ENGINEERIN/pages/1309868033/API+changes+v6+v7) - */ -object CapabilitiesDeserializer : - JsonTransformingSerializer>(ListSerializer(ClientCapabilityDTO.serializer())) { - override fun transformDeserialize(element: JsonElement): JsonElement { - return when { - element is JsonObject && element.containsKey("capabilities") -> element["capabilities"]!! - element is JsonArray -> element - else -> throw SerializationException("Unexpected JSON format for capabilities") - } - } -} - @Serializable data class ClientsOfUsersResponse( @SerialName("qualified_user_map") val qualifiedMap: Map>> diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/conversation/ConversationResponse.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/conversation/ConversationResponse.kt index 1b017ee34cf..71452d4f8b8 100644 --- a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/conversation/ConversationResponse.kt +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/conversation/ConversationResponse.kt @@ -106,6 +106,9 @@ data class ConversationResponse( fun fromId(id: Int): Type = values().first { type -> type.id == id } } } + + fun toV6(): ConversationResponseV6 = + ConversationResponseV6(this, publicKeys ?: MLSPublicKeysDTO(null)) } @Serializable diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt index e4593409cf7..e42ee3431d5 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt @@ -24,7 +24,6 @@ import com.wire.kalium.network.utils.obfuscatePath import com.wire.kalium.network.utils.obfuscatedJsonMessage import com.wire.kalium.util.serialization.toJsonElement import io.ktor.client.plugins.logging.LogLevel -import io.ktor.client.plugins.logging.Logger import io.ktor.client.request.HttpRequest import io.ktor.client.request.HttpRequestBuilder import io.ktor.client.statement.HttpResponse @@ -41,7 +40,6 @@ import kotlinx.coroutines.Job internal class KaliumHttpLogger( private val level: LogLevel, - private val logger: Logger, private val kaliumLogger: KaliumLogger, ) { private val requestLog = mutableMapOf() @@ -134,7 +132,7 @@ internal class KaliumHttpLogger( } } - suspend fun logResponseBody(contentType: ContentType?, content: ByteReadChannel): Unit = with(logger) { + suspend fun logResponseBody(contentType: ContentType?, content: ByteReadChannel) { responseHeaderMonitor.join() val text = content.tryReadText(contentType?.charset() ?: Charsets.UTF_8) ?: "\"response body omitted\"" diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt index 30a88e2b376..36681582bca 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt @@ -49,17 +49,17 @@ private val DisableLogging = AttributeKey("DisableLogging") * A client's logging plugin. */ @Suppress("TooGenericExceptionCaught", "EmptyFinallyBlock") -public class KaliumKtorCustomLogging private constructor( - public val logger: Logger, - public val kaliumLogger: KaliumLogger, - public var level: LogLevel, - public var filters: List<(HttpRequestBuilder) -> Boolean> = emptyList() +class KaliumKtorCustomLogging private constructor( + val logger: Logger, + val kaliumLogger: KaliumLogger, + var level: LogLevel, + var filters: List<(HttpRequestBuilder) -> Boolean> = emptyList() ) { /** * [Logging] plugin configuration */ - public class Config { + class Config { /** * filters */ @@ -70,7 +70,7 @@ public class KaliumKtorCustomLogging private constructor( /** * [Logger] instance to use */ - public var logger: Logger + var logger: Logger get() = _logger ?: Logger.DEFAULT set(value) { _logger = value @@ -79,7 +79,7 @@ public class KaliumKtorCustomLogging private constructor( /** * log [LogLevel] */ - public var level: LogLevel = LogLevel.HEADERS + var level: LogLevel = LogLevel.HEADERS /** * [KaliumLogger] instance to use @@ -89,7 +89,7 @@ public class KaliumKtorCustomLogging private constructor( /** * Log messages for calls matching a [predicate] */ - public fun filter(predicate: (HttpRequestBuilder) -> Boolean) { + fun filter(predicate: (HttpRequestBuilder) -> Boolean) { filters.add(predicate) } } @@ -171,7 +171,7 @@ public class KaliumKtorCustomLogging private constructor( } private fun logRequest(request: HttpRequestBuilder): OutgoingContent? { - val logger = KaliumHttpLogger(level, logger, kaliumLogger) + val logger = KaliumHttpLogger(level, kaliumLogger) request.attributes.put(KaliumHttpCustomLogger, logger) logger.logRequest(request) @@ -181,7 +181,7 @@ public class KaliumKtorCustomLogging private constructor( return null } - public companion object : HttpClientPlugin { + companion object : HttpClientPlugin { override val key: AttributeKey = AttributeKey("ClientLogging") override fun prepare(block: Config.() -> Unit): KaliumKtorCustomLogging { @@ -214,7 +214,7 @@ public class KaliumKtorCustomLogging private constructor( * Configure and install [Logging] in [HttpClient]. */ @Suppress("FunctionNaming") -public fun HttpClientConfig<*>.Logging(block: Logging.Config.() -> Unit = {}) { +fun HttpClientConfig<*>.Logging(block: Logging.Config.() -> Unit = {}) { install(Logging, block) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/conversation/ConversationApi.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/conversation/ConversationApi.kt index 28fd67cb099..22bc70f3a0d 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/conversation/ConversationApi.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/conversation/ConversationApi.kt @@ -18,23 +18,12 @@ package com.wire.kalium.network.api.base.authenticated.conversation -import com.wire.kalium.network.api.base.authenticated.BaseApi import com.wire.kalium.network.api.authenticated.conversation.AddConversationMembersRequest -import com.wire.kalium.network.api.authenticated.conversation.guestroomlink.ConversationInviteLinkResponse -import com.wire.kalium.network.api.authenticated.conversation.model.ConversationCodeInfo -import com.wire.kalium.network.api.authenticated.conversation.model.ConversationMemberRoleDTO -import com.wire.kalium.network.api.authenticated.conversation.model.ConversationReceiptModeDTO -import com.wire.kalium.network.api.authenticated.notification.EventContentDTO -import com.wire.kalium.network.api.model.ConversationId -import com.wire.kalium.network.api.model.QualifiedID -import com.wire.kalium.network.api.model.ServiceAddedResponse import com.wire.kalium.network.api.authenticated.conversation.AddServiceRequest import com.wire.kalium.network.api.authenticated.conversation.ConvProtocol import com.wire.kalium.network.api.authenticated.conversation.ConversationMemberAddedResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationMemberRemovedResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationPagingResponse -import com.wire.kalium.network.api.model.SubconversationId -import com.wire.kalium.network.api.model.UserId import com.wire.kalium.network.api.authenticated.conversation.ConversationRenameResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseDTO @@ -47,6 +36,17 @@ import com.wire.kalium.network.api.authenticated.conversation.UpdateConversation import com.wire.kalium.network.api.authenticated.conversation.UpdateConversationAccessResponse import com.wire.kalium.network.api.authenticated.conversation.UpdateConversationProtocolResponse import com.wire.kalium.network.api.authenticated.conversation.UpdateConversationReceiptModeResponse +import com.wire.kalium.network.api.authenticated.conversation.guestroomlink.ConversationInviteLinkResponse +import com.wire.kalium.network.api.authenticated.conversation.model.ConversationCodeInfo +import com.wire.kalium.network.api.authenticated.conversation.model.ConversationMemberRoleDTO +import com.wire.kalium.network.api.authenticated.conversation.model.ConversationReceiptModeDTO +import com.wire.kalium.network.api.authenticated.notification.EventContentDTO +import com.wire.kalium.network.api.base.authenticated.BaseApi +import com.wire.kalium.network.api.model.ConversationId +import com.wire.kalium.network.api.model.QualifiedID +import com.wire.kalium.network.api.model.ServiceAddedResponse +import com.wire.kalium.network.api.model.SubconversationId +import com.wire.kalium.network.api.model.UserId import com.wire.kalium.network.exceptions.APINotSupported import com.wire.kalium.network.utils.NetworkResponse @@ -75,10 +75,6 @@ interface ConversationApi : BaseApi { createConversationRequest: CreateConversationRequest ): NetworkResponse - suspend fun createOne2OneConversation( - createConversationRequest: CreateConversationRequest - ): NetworkResponse - suspend fun addMember( addParticipantRequest: AddConversationMembersRequest, conversationId: ConversationId diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/NotificationApi.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/NotificationApi.kt index 999f8abf99f..35586b6ab6c 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/NotificationApi.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/NotificationApi.kt @@ -35,9 +35,7 @@ sealed class WebSocketEvent { other as NonBinaryPayloadReceived<*> - if (!payload.contentEquals(other.payload)) return false - - return true + return payload.contentEquals(other.payload) } override fun hashCode(): Int { 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 5d2f3963694..145a833620f 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 @@ -22,7 +22,6 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.authenticated.conversation.AddConversationMembersRequest import com.wire.kalium.network.api.authenticated.conversation.AddServiceRequest import com.wire.kalium.network.api.authenticated.conversation.ConvProtocol -import com.wire.kalium.network.api.base.authenticated.conversation.ConversationApi import com.wire.kalium.network.api.authenticated.conversation.ConversationMemberAddedResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationMemberRemovedResponse import com.wire.kalium.network.api.authenticated.conversation.ConversationPagingResponse @@ -46,6 +45,7 @@ import com.wire.kalium.network.api.authenticated.conversation.model.Conversation import com.wire.kalium.network.api.authenticated.conversation.model.ConversationMemberRoleDTO import com.wire.kalium.network.api.authenticated.conversation.model.ConversationReceiptModeDTO import com.wire.kalium.network.api.authenticated.notification.EventContentDTO +import com.wire.kalium.network.api.base.authenticated.conversation.ConversationApi import com.wire.kalium.network.api.model.AddServiceResponse import com.wire.kalium.network.api.model.ConversationId import com.wire.kalium.network.api.model.JoinConversationRequestV0 @@ -115,14 +115,6 @@ internal open class ConversationApiV0 internal constructor( } } - override suspend fun createOne2OneConversation( - createConversationRequest: CreateConversationRequest - ): NetworkResponse = wrapKaliumResponse { - httpClient.post("$PATH_CONVERSATIONS/$PATH_ONE_2_ONE") { - setBody(createConversationRequest) - } - } - /** * returns 200 conversation created or 204 conversation unchanged */ @@ -407,7 +399,6 @@ internal open class ConversationApiV0 internal constructor( const val PATH_CONVERSATIONS = "conversations" const val PATH_SELF = "self" const val PATH_MEMBERS = "members" - const val PATH_ONE_2_ONE = "one2one" const val PATH_V2 = "v2" const val PATH_CONVERSATIONS_LIST = "list" const val PATH_LIST_IDS = "list-ids" diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PreKeyApiV2.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PreKeyApiV2.kt index e643102c839..a1d8b277740 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PreKeyApiV2.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PreKeyApiV2.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v0.authenticated.PreKeyApiV0 internal open class PreKeyApiV2 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : PreKeyApiV0(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PropertiesApiV2.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PropertiesApiV2.kt index 9abc1d89dbb..107d524c138 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PropertiesApiV2.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PropertiesApiV2.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v0.authenticated.PropertiesApiV0 internal open class PropertiesApiV2 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedNetworkClient: AuthenticatedNetworkClient, ) : PropertiesApiV0(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/ConversationApiV3.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/ConversationApiV3.kt index f70aed1e7a2..1e2c7052f33 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/ConversationApiV3.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/ConversationApiV3.kt @@ -77,16 +77,6 @@ internal open class ConversationApiV3 internal constructor( apiModelMapper.fromApiV3(it) } - override suspend fun createOne2OneConversation( - createConversationRequest: CreateConversationRequest - ): NetworkResponse = wrapKaliumResponse { - httpClient.post("$PATH_CONVERSATIONS/$PATH_ONE_2_ONE") { - setBody(apiModelMapper.toApiV3(createConversationRequest)) - } - }.mapSuccess { - apiModelMapper.fromApiV3(it) - } - override suspend fun updateAccess( conversationId: ConversationId, updateConversationAccessRequest: UpdateConversationAccessRequest diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/PropertiesApiV3.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/PropertiesApiV3.kt index ebf2fbe0489..b77b93f3767 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/PropertiesApiV3.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/PropertiesApiV3.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v2.authenticated.PropertiesApiV2 internal open class PropertiesApiV3 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedNetworkClient: AuthenticatedNetworkClient, ) : PropertiesApiV2(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/AccessTokenApiV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/AccessTokenApiV4.kt index d600fb6f3fb..f72a7fc0c28 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/AccessTokenApiV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/AccessTokenApiV4.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.api.v3.authenticated.AccessTokenApiV3 import io.ktor.client.HttpClient internal open class AccessTokenApiV4 internal constructor( - private val httpClient: HttpClient + httpClient: HttpClient ) : AccessTokenApiV3(httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/PropertiesApiV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/PropertiesApiV4.kt index 2bfa3a5fa7c..9333d602a4f 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/PropertiesApiV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/PropertiesApiV4.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v3.authenticated.PropertiesApiV3 internal open class PropertiesApiV4 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient, + authenticatedNetworkClient: AuthenticatedNetworkClient, ) : PropertiesApiV3(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/AccessTokenApiV5.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/AccessTokenApiV5.kt index 6dc480fd107..927a1919dc1 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/AccessTokenApiV5.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/AccessTokenApiV5.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.api.v4.authenticated.AccessTokenApiV4 import io.ktor.client.HttpClient internal open class AccessTokenApiV5 internal constructor( - private val httpClient: HttpClient + httpClient: HttpClient ) : AccessTokenApiV4(httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt index 5faf053b0c7..6818f2f8384 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.api.v5.authenticated.AccessTokenApiV5 import io.ktor.client.HttpClient internal open class AccessTokenApiV6 internal constructor( - private val httpClient: HttpClient + httpClient: HttpClient ) : AccessTokenApiV5(httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/E2EIApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/E2EIApiV6.kt index 62c439c72c8..b11c94f0729 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/E2EIApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/E2EIApiV6.kt @@ -21,5 +21,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v5.authenticated.E2EIApiV5 internal open class E2EIApiV6 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : E2EIApiV5(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/KeyPackageApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/KeyPackageApiV6.kt index f4c82848c04..57405a23ff6 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/KeyPackageApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/KeyPackageApiV6.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v5.authenticated.KeyPackageApiV5 internal open class KeyPackageApiV6 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : KeyPackageApiV5(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSMessageApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSMessageApiV6.kt index 00a28b82330..11aaa5924a0 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSMessageApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSMessageApiV6.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v5.authenticated.MLSMessageApiV5 internal open class MLSMessageApiV6 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : MLSMessageApiV5(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSPublicKeyApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSPublicKeyApiV6.kt index 2657848f35d..2f4978f8d53 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSPublicKeyApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSPublicKeyApiV6.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v5.authenticated.MLSPublicKeyApiV5 internal open class MLSPublicKeyApiV6 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : MLSPublicKeyApiV5(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt index a96429b4b2a..cd092f4574e 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.api.v6.authenticated.AccessTokenApiV6 import io.ktor.client.HttpClient internal open class AccessTokenApiV7 internal constructor( - private val httpClient: HttpClient + httpClient: HttpClient ) : AccessTokenApiV6(httpClient) 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 7f36d57cd89..cd10ebd3b2f 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 @@ -20,9 +20,7 @@ package com.wire.kalium.network.api.v7.authenticated import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse -import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV3 import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV6 -import com.wire.kalium.network.api.authenticated.conversation.CreateConversationRequest import com.wire.kalium.network.api.model.ApiModelMapper import com.wire.kalium.network.api.model.ApiModelMapperImpl import com.wire.kalium.network.api.model.UserId @@ -31,22 +29,11 @@ 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 internal open class ConversationApiV7 internal constructor( authenticatedNetworkClient: AuthenticatedNetworkClient, private val apiModelMapper: ApiModelMapper = ApiModelMapperImpl(), ) : ConversationApiV6(authenticatedNetworkClient) { - override suspend fun createOne2OneConversation( - createConversationRequest: CreateConversationRequest - ): NetworkResponse = wrapKaliumResponse { - httpClient.post(PATH_ONE_2_ONE_CONVERSATIONS) { - setBody(apiModelMapper.toApiV3(createConversationRequest)) - } - }.mapSuccess { - apiModelMapper.fromApiV3(it) - } override suspend fun fetchMlsOneToOneConversation(userId: UserId): NetworkResponse = wrapKaliumResponse { diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt index 80957a5b0c7..c645339d015 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt @@ -21,5 +21,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v6.authenticated.E2EIApiV6 internal open class E2EIApiV7 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : E2EIApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt index cfccf210f23..ae9ab0f5cc7 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v6.authenticated.KeyPackageApiV6 internal open class KeyPackageApiV7 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : KeyPackageApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt index 2e501a59e1f..74757410650 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v6.authenticated.MLSMessageApiV6 internal open class MLSMessageApiV7 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : MLSMessageApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt index 0a7837842b7..371e72a5500 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt @@ -22,5 +22,5 @@ import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.api.v6.authenticated.MLSPublicKeyApiV6 internal open class MLSPublicKeyApiV7 internal constructor( - private val authenticatedNetworkClient: AuthenticatedNetworkClient + authenticatedNetworkClient: AuthenticatedNetworkClient ) : MLSPublicKeyApiV6(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/utils/ObfuscateUtil.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/utils/ObfuscateUtil.kt index 225d622fcca..881b0ccb6cb 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/utils/ObfuscateUtil.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/utils/ObfuscateUtil.kt @@ -25,7 +25,6 @@ import com.wire.kalium.logger.obfuscateId import com.wire.kalium.logger.obfuscateUrlPath import com.wire.kalium.util.serialization.toJsonElement import io.ktor.http.Url -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonElement diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/authenticated/client/ClientDTOSerializationTest.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/authenticated/client/ClientDTOSerializationTest.kt new file mode 100644 index 00000000000..5d8c238d963 --- /dev/null +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/authenticated/client/ClientDTOSerializationTest.kt @@ -0,0 +1,41 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.api.authenticated.client + +import com.wire.kalium.mocks.responses.ClientResponseJson +import com.wire.kalium.network.api.authenticated.client.ClientDTO +import kotlinx.serialization.json.Json +import kotlin.test.Test +import kotlin.test.assertTrue + + +class ClientDTOSerializationTest { + @Test + fun givenJsonWithCapabilitiesList_whenDeserialize_thenReturnCapabilities() { + val jsonString = ClientResponseJson.valid.rawJson + val deserializedClient = Json.decodeFromString(jsonString) + assertTrue(deserializedClient.capabilities.isNotEmpty()) + } + + @Test + fun givenJsonWithCapabilitiesObjectWrapperList_whenDeserialize_thenReturnCapabilities() { + val jsonString = ClientResponseJson.validCapabilitiesObject.rawJson + val deserializedClient = Json.decodeFromString(jsonString) + assertTrue(deserializedClient.capabilities.isNotEmpty()) + } +} \ No newline at end of file diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v7/ConversationApiV7Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v7/ConversationApiV7Test.kt new file mode 100644 index 00000000000..a9b2946f9c1 --- /dev/null +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v7/ConversationApiV7Test.kt @@ -0,0 +1,64 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.api.v7 + +import com.wire.kalium.api.ApiTest +import com.wire.kalium.mocks.responses.conversation.ConversationResponseJson +import com.wire.kalium.network.api.model.UserId +import com.wire.kalium.network.api.v7.authenticated.ConversationApiV7 +import com.wire.kalium.network.utils.isSuccessful +import io.ktor.http.HttpStatusCode +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertTrue + +internal class ConversationApiV7Test : ApiTest() { + + @Test + fun whenCallingFetchMlsOneToOneConversation_thenTheRequestShouldBeConfiguredOK() = runTest { + val networkClient = mockAuthenticatedNetworkClient( + FETCH_CONVERSATION_RESPONSE, + statusCode = HttpStatusCode.OK, + assertion = { + assertGet() + assertPathEqual("/one2one-conversations/${USER_ID.domain}/${USER_ID.value}") + } + ) + val conversationApi = ConversationApiV7(networkClient) + conversationApi.fetchMlsOneToOneConversation(USER_ID) + } + + @Test + fun given200Response_whenCallingFetchMlsOneToOneConversation_thenResponseIsParsedCorrectly() = + runTest { + val networkClient = mockAuthenticatedNetworkClient( + FETCH_CONVERSATION_RESPONSE, + statusCode = HttpStatusCode.OK + ) + val conversationApi = ConversationApiV7(networkClient) + + val fetchMlsOneToOneConversation = conversationApi.fetchMlsOneToOneConversation(USER_ID) + assertTrue(fetchMlsOneToOneConversation.isSuccessful()) + } + + companion object { + val USER_ID = UserId("id", "domain") + val FETCH_CONVERSATION_RESPONSE = ConversationResponseJson.v6.rawJson + } +} From 31265e6bf26c79079f224a0fb251eed688cb7e5b Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Wed, 13 Nov 2024 14:55:38 +0100 Subject: [PATCH 07/22] feature: connect to upgrade-personal-to-team API #WPB-11992 --- .../kalium/logic/data/user/UserRepository.kt | 287 ++++++++++++------ .../kalium/logic/feature/UserSessionScope.kt | 26 +- .../MigrateFromPersonalToTeamUseCase.kt | 49 +++ .../authenticated/UpgradePersonalToTeamDTO.kt | 27 ++ .../authenticated/UpgradePersonalToTeamApi.kt | 30 ++ .../UpgradePersonalToTeamApiV0.kt | 33 ++ .../AuthenticatedNetworkContainerV0.kt | 7 + .../UpgradePersonalToTeamApiV2.kt | 26 ++ .../AuthenticatedNetworkContainerV2.kt | 7 + .../UpgradePersonalToTeamApiV3.kt | 26 ++ .../AuthenticatedNetworkContainerV3.kt | 7 + .../UpgradePersonalToTeamApiV4.kt | 26 ++ .../AuthenticatedNetworkContainerV4.kt | 7 + .../UpgradePersonalToTeamApiV5.kt | 26 ++ .../AuthenticatedNetworkContainerV5.kt | 7 + .../UpgradePersonalToTeamApiV6.kt | 26 ++ .../AuthenticatedNetworkContainerV6.kt | 8 + .../UpgradePersonalToTeamApiV7.kt | 54 ++++ .../AuthenticatedNetworkContainerV7.kt | 7 + .../AuthenticatedNetworkContainer.kt | 17 +- 20 files changed, 594 insertions(+), 109 deletions(-) create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt create mode 100644 network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/UpgradePersonalToTeamDTO.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/UpgradePersonalToTeamApiV2.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/UpgradePersonalToTeamApiV3.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/UpgradePersonalToTeamApiV5.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/UpgradePersonalToTeamApiV6.kt create mode 100644 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt index 9609079b094..48fa74dc7bd 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt @@ -58,12 +58,14 @@ import com.wire.kalium.logic.kaliumLogger import com.wire.kalium.logic.sync.receiver.handler.legalhold.LegalHoldHandler import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.logic.wrapStorageRequest +import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberIdList import com.wire.kalium.network.api.authenticated.userDetails.ListUserRequest import com.wire.kalium.network.api.authenticated.userDetails.ListUsersDTO import com.wire.kalium.network.api.authenticated.userDetails.qualifiedIds import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.self.SelfApi import com.wire.kalium.network.api.base.authenticated.userDetails.UserDetailsApi import com.wire.kalium.network.api.model.LegalHoldStatusDTO @@ -103,7 +105,12 @@ interface UserRepository { suspend fun fetchUsersIfUnknownByIds(ids: Set): Either suspend fun observeSelfUser(): Flow suspend fun observeSelfUserWithTeam(): Flow> - suspend fun updateSelfUser(newName: String? = null, newAccent: Int? = null, newAssetId: String? = null): Either + suspend fun updateSelfUser( + newName: String? = null, + newAccent: Int? = null, + newAssetId: String? = null + ): Either + suspend fun getSelfUser(): SelfUser? suspend fun observeAllKnownUsers(): Flow>> suspend fun getKnownUser(userId: UserId): Flow @@ -151,11 +158,20 @@ interface UserRepository { suspend fun updateSupportedProtocols(protocols: Set): Either - suspend fun updateActiveOneOnOneConversation(userId: UserId, conversationId: ConversationId): Either + suspend fun updateActiveOneOnOneConversation( + userId: UserId, + conversationId: ConversationId + ): Either - suspend fun updateActiveOneOnOneConversationIfNotSet(userId: UserId, conversationId: ConversationId): Either + suspend fun updateActiveOneOnOneConversationIfNotSet( + userId: UserId, + conversationId: ConversationId + ): Either - suspend fun isAtLeastOneUserATeamMember(userId: List, teamId: TeamId): Either + suspend fun isAtLeastOneUserATeamMember( + userId: List, + teamId: TeamId + ): Either suspend fun insertOrIgnoreIncompleteUsers(userIds: List): Either @@ -164,6 +180,7 @@ interface UserRepository { suspend fun getOneOnOnConversationId(userId: QualifiedID): Either suspend fun getUsersMinimizedByQualifiedIDs(userIds: List): Either> suspend fun getNameAndHandle(userId: UserId): Either + suspend fun migrateUserToTeam(teamName: String): Either } @Suppress("LongParameterList", "TooManyFunctions") @@ -173,6 +190,7 @@ internal class UserDataSource internal constructor( private val clientDAO: ClientDAO, private val selfApi: SelfApi, private val userDetailsApi: UserDetailsApi, + private val upgradePersonalToTeamApi: UpgradePersonalToTeamApi, private val teamsApi: TeamsApi, private val sessionRepository: SessionRepository, private val selfUserId: UserId, @@ -194,36 +212,49 @@ internal class UserDataSource internal constructor( */ private val userDetailsRefreshInstantCache = ConcurrentMutableMap() - override suspend fun fetchSelfUser(): Either = wrapApiRequest { selfApi.getSelfInfo() } - .flatMap { selfUserDTO -> - selfUserDTO.teamId.let { selfUserTeamId -> - if (selfUserTeamId.isNullOrEmpty()) Either.Right(null) - else wrapApiRequest { teamsApi.getTeamMember(selfUserTeamId, selfUserId.value) } - }.map { selfUserDTO to it } - } - .flatMap { (userDTO, teamMemberDTO) -> - if (userDTO.deleted == true) { - Either.Left(SelfUserDeleted) - } else { - updateSelfUserProviderAccountInfo(userDTO) - .map { - userMapper.fromSelfUserDtoToUserEntity( - userDTO = userDTO, - connectionState = ConnectionEntity.State.ACCEPTED, - userTypeEntity = userTypeEntityMapper.teamRoleCodeToUserType(teamMemberDTO?.permissions?.own) - ) - } - .flatMap { userEntity -> - wrapStorageRequest { userDAO.upsertUser(userEntity) } - .flatMap { - wrapStorageRequest { metadataDAO.insertValue(Json.encodeToString(userEntity.id), SELF_USER_ID_KEY) } - } - } + override suspend fun fetchSelfUser(): Either = + wrapApiRequest { selfApi.getSelfInfo() } + .flatMap { selfUserDTO -> + selfUserDTO.teamId.let { selfUserTeamId -> + if (selfUserTeamId.isNullOrEmpty()) Either.Right(null) + else wrapApiRequest { teamsApi.getTeamMember(selfUserTeamId, selfUserId.value) } + }.map { selfUserDTO to it } + } + .flatMap { (userDTO, teamMemberDTO) -> + if (userDTO.deleted == true) { + Either.Left(SelfUserDeleted) + } else { + updateSelfUserProviderAccountInfo(userDTO) + .map { + userMapper.fromSelfUserDtoToUserEntity( + userDTO = userDTO, + connectionState = ConnectionEntity.State.ACCEPTED, + userTypeEntity = userTypeEntityMapper.teamRoleCodeToUserType( + teamMemberDTO?.permissions?.own + ) + ) + } + .flatMap { userEntity -> + wrapStorageRequest { userDAO.upsertUser(userEntity) } + .flatMap { + wrapStorageRequest { + metadataDAO.insertValue( + Json.encodeToString( + userEntity.id + ), SELF_USER_ID_KEY + ) + } + } + } + } } - } private suspend fun updateSelfUserProviderAccountInfo(userDTO: SelfUserDTO): Either = - sessionRepository.updateSsoIdAndScimInfo(userDTO.id.toModel(), idMapper.toSsoId(userDTO.ssoID), userDTO.managedByDTO) + sessionRepository.updateSsoIdAndScimInfo( + userDTO.id.toModel(), + idMapper.toSsoId(userDTO.ssoID), + userDTO.managedByDTO + ) override suspend fun getKnownUser(userId: UserId): Flow = userDAO.observeUserDetailsByQualifiedID(qualifiedID = userId.toDao()) @@ -248,7 +279,8 @@ internal class UserDataSource internal constructor( */ private suspend fun refreshUserDetailsIfNeeded(userId: UserId): Either { val now = DateTimeUtil.currentInstant() - val wasFetchedRecently = userDetailsRefreshInstantCache[userId]?.let { now < it + USER_DETAILS_MAX_AGE } ?: false + val wasFetchedRecently = + userDetailsRefreshInstantCache[userId]?.let { now < it + USER_DETAILS_MAX_AGE } ?: false return if (!wasFetchedRecently) { when (userId) { selfUserId -> fetchSelfUser() @@ -330,7 +362,9 @@ internal class UserDataSource internal constructor( private suspend fun fetchTeamMembersByIds(userProfileList: List): Either> { val selfUserDomain = selfUserId.domain val selfUserTeamId = selfTeamIdProvider().getOrNull() - val teamMemberIds = userProfileList.filter { it.isTeamMember(selfUserTeamId?.value, selfUserDomain) }.map { it.id.value } + val teamMemberIds = + userProfileList.filter { it.isTeamMember(selfUserTeamId?.value, selfUserDomain) } + .map { it.id.value } return if (selfUserTeamId == null || teamMemberIds.isEmpty()) Either.Right(emptyList()) else teamMemberIds .chunked(BATCH_SIZE) @@ -345,9 +379,10 @@ internal class UserDataSource internal constructor( } } - private suspend fun persistIncompleteUsers(usersFailed: List) = wrapStorageRequest { - userDAO.insertOrIgnoreUsers(usersFailed.map { userMapper.fromFailedUserToEntity(it) }) - } + private suspend fun persistIncompleteUsers(usersFailed: List) = + wrapStorageRequest { + userDAO.insertOrIgnoreUsers(usersFailed.map { userMapper.fromFailedUserToEntity(it) }) + } private suspend fun persistUsers( listUserProfileDTO: List, @@ -383,7 +418,10 @@ internal class UserDataSource internal constructor( } return listUserProfileDTO .map { - legalHoldHandler.handleUserFetch(it.id.toModel(), it.legalHoldStatus == LegalHoldStatusDTO.ENABLED) + legalHoldHandler.handleUserFetch( + it.id.toModel(), + it.legalHoldStatus == LegalHoldStatusDTO.ENABLED + ) } .foldToEitherWhileRight(Unit) { value, _ -> value } .flatMap { @@ -399,16 +437,17 @@ internal class UserDataSource internal constructor( } } - override suspend fun fetchUsersIfUnknownByIds(ids: Set): Either = wrapStorageRequest { - val qualifiedIDList = ids.map { it.toDao() } - val knownUsers = userDAO.getUsersDetailsByQualifiedIDList(ids.map { it.toDao() }) - // TODO we should differentiate users with incomplete data not by checking if name isNullOrBlank - // TODO but add separate property (when federated backend is down) - qualifiedIDList.filterNot { knownUsers.any { userEntity -> userEntity.id == it && !userEntity.name.isNullOrBlank() } } - }.flatMap { missingIds -> - if (missingIds.isEmpty()) Either.Right(Unit) - else fetchUsersByIds(missingIds.map { it.toModel() }.toSet()) - } + override suspend fun fetchUsersIfUnknownByIds(ids: Set): Either = + wrapStorageRequest { + val qualifiedIDList = ids.map { it.toDao() } + val knownUsers = userDAO.getUsersDetailsByQualifiedIDList(ids.map { it.toDao() }) + // TODO we should differentiate users with incomplete data not by checking if name isNullOrBlank + // TODO but add separate property (when federated backend is down) + qualifiedIDList.filterNot { knownUsers.any { userEntity -> userEntity.id == it && !userEntity.name.isNullOrBlank() } } + }.flatMap { missingIds -> + if (missingIds.isEmpty()) Either.Right(Unit) + else fetchUsersByIds(missingIds.map { it.toModel() }.toSet()) + } @OptIn(ExperimentalCoroutinesApi::class) override suspend fun observeSelfUser(): Flow { @@ -436,14 +475,19 @@ internal class UserDataSource internal constructor( @OptIn(ExperimentalCoroutinesApi::class) override suspend fun observeSelfUserWithTeam(): Flow> { - return metadataDAO.valueByKeyFlow(SELF_USER_ID_KEY).filterNotNull().flatMapMerge { encodedValue -> - val selfUserID: QualifiedIDEntity = Json.decodeFromString(encodedValue) - userDAO.getUserDetailsWithTeamByQualifiedID(selfUserID) - .filterNotNull() - .map { (user, team) -> - userMapper.fromUserDetailsEntityToSelfUser(user) to team?.let { teamMapper.fromDaoModelToTeam(it) } - } - } + return metadataDAO.valueByKeyFlow(SELF_USER_ID_KEY).filterNotNull() + .flatMapMerge { encodedValue -> + val selfUserID: QualifiedIDEntity = Json.decodeFromString(encodedValue) + userDAO.getUserDetailsWithTeamByQualifiedID(selfUserID) + .filterNotNull() + .map { (user, team) -> + userMapper.fromUserDetailsEntityToSelfUser(user) to team?.let { + teamMapper.fromDaoModelToTeam( + it + ) + } + } + } } @Deprecated( @@ -451,7 +495,11 @@ internal class UserDataSource internal constructor( replaceWith = ReplaceWith("eg: updateSelfDisplayName(displayName: String)") ) // FIXME(refactor): create a dedicated function to update avatar, as this is the only usage of this function. - override suspend fun updateSelfUser(newName: String?, newAccent: Int?, newAssetId: String?): Either { + override suspend fun updateSelfUser( + newName: String?, + newAccent: Int?, + newAssetId: String? + ): Either { val updateRequest = userMapper.fromModelToUpdateApiModel(newName, newAccent, newAssetId) return wrapApiRequest { selfApi.updateSelf(updateRequest) } .map { userMapper.fromUpdateRequestToPartialUserEntity(updateRequest, selfUserId) } @@ -485,11 +533,12 @@ internal class UserDataSource internal constructor( } } - override suspend fun getUsersMinimizedByQualifiedIDs(userIds: List) = wrapStorageRequest { - userDAO.getUsersMinimizedByQualifiedIDs( - qualifiedIDs = userIds.map { it.toDao() } - ).map(userMapper::fromUserEntityToOtherUserMinimized) - } + override suspend fun getUsersMinimizedByQualifiedIDs(userIds: List) = + wrapStorageRequest { + userDAO.getUsersMinimizedByQualifiedIDs( + qualifiedIDs = userIds.map { it.toDao() } + ).map(userMapper::fromUserEntityToOtherUserMinimized) + } override suspend fun observeUser(userId: UserId): Flow = userDAO.observeUserDetailsByQualifiedID(qualifiedID = userId.toDao()) @@ -508,21 +557,38 @@ internal class UserDataSource internal constructor( } } - override suspend fun updateOtherUserAvailabilityStatus(userId: UserId, status: UserAvailabilityStatus) { - userDAO.updateUserAvailabilityStatus(userId.toDao(), availabilityStatusMapper.fromModelAvailabilityStatusToDao(status)) + override suspend fun updateOtherUserAvailabilityStatus( + userId: UserId, + status: UserAvailabilityStatus + ) { + userDAO.updateUserAvailabilityStatus( + userId.toDao(), + availabilityStatusMapper.fromModelAvailabilityStatusToDao(status) + ) } override suspend fun updateSupportedProtocols(protocols: Set): Either { return wrapApiRequest { selfApi.updateSupportedProtocols(protocols.map { it.toApi() }) } .flatMap { wrapStorageRequest { - userDAO.updateUserSupportedProtocols(selfUserId.toDao(), protocols.map { it.toDao() }.toSet()) + userDAO.updateUserSupportedProtocols( + selfUserId.toDao(), + protocols.map { it.toDao() }.toSet() + ) } } } - override suspend fun updateActiveOneOnOneConversation(userId: UserId, conversationId: ConversationId): Either = - wrapStorageRequest { userDAO.updateActiveOneOnOneConversation(userId.toDao(), conversationId.toDao()) } + override suspend fun updateActiveOneOnOneConversation( + userId: UserId, + conversationId: ConversationId + ): Either = + wrapStorageRequest { + userDAO.updateActiveOneOnOneConversation( + userId.toDao(), + conversationId.toDao() + ) + } override suspend fun updateActiveOneOnOneConversationIfNotSet( userId: UserId, @@ -531,13 +597,15 @@ internal class UserDataSource internal constructor( userDAO.updateActiveOneOnOneConversationIfNotSet(userId.toDao(), conversationId.toDao()) } - override suspend fun isAtLeastOneUserATeamMember(userId: List, teamId: TeamId) = wrapStorageRequest { - userDAO.isAtLeastOneUserATeamMember(userId.map { it.toDao() }, teamId.value) - } + override suspend fun isAtLeastOneUserATeamMember(userId: List, teamId: TeamId) = + wrapStorageRequest { + userDAO.isAtLeastOneUserATeamMember(userId.map { it.toDao() }, teamId.value) + } - override suspend fun insertOrIgnoreIncompleteUsers(userIds: List) = wrapStorageRequest { - userDAO.insertOrIgnoreIncompleteUsers(userIds.map { it.toDao() }) - } + override suspend fun insertOrIgnoreIncompleteUsers(userIds: List) = + wrapStorageRequest { + userDAO.insertOrIgnoreIncompleteUsers(userIds.map { it.toDao() }) + } override suspend fun fetchUsersLegalHoldConsent(userIds: Set): Either = fetchUsersByIdsReturningListUsersDTO(userIds).map { listUsersDTO -> @@ -545,7 +613,13 @@ internal class UserDataSource internal constructor( .partition { it.legalHoldStatus != LegalHoldStatusDTO.NO_CONSENT } .let { (usersWithConsent, usersWithoutConsent) -> ListUsersLegalHoldConsent( - usersWithConsent = usersWithConsent.map { it.id.toModel() to it.teamId?.let { TeamId(it) } }, + usersWithConsent = usersWithConsent.map { + it.id.toModel() to it.teamId?.let { + TeamId( + it + ) + } + }, usersWithoutConsent = usersWithoutConsent.map { it.id.toModel() }, usersFailed = listUsersDTO.usersFailed.map { it.toModel() } ) @@ -567,7 +641,9 @@ internal class UserDataSource internal constructor( override suspend fun getAllRecipients(): Either, List>> = selfTeamIdProvider().flatMap { teamId -> val teamMateIds = teamId?.value?.let { selfTeamId -> - wrapStorageRequest { userDAO.getAllUsersDetailsByTeam(selfTeamId).map { it.id.toModel() } } + wrapStorageRequest { + userDAO.getAllUsersDetailsByTeam(selfTeamId).map { it.id.toModel() } + } }?.getOrNull() ?: listOf() wrapStorageRequest { @@ -583,13 +659,14 @@ internal class UserDataSource internal constructor( } } - override suspend fun updateUserFromEvent(event: Event.User.Update): Either = wrapStorageRequest { - userDAO.updateUser(userMapper.fromUserUpdateEventToPartialUserEntity(event)) - }.onFailure { - Either.Left(StorageFailure.DataNotFound) - }.onSuccess { - Either.Right(Unit) - } + override suspend fun updateUserFromEvent(event: Event.User.Update): Either = + wrapStorageRequest { + userDAO.updateUser(userMapper.fromUserUpdateEventToPartialUserEntity(event)) + }.onFailure { + Either.Left(StorageFailure.DataNotFound) + }.onSuccess { + Either.Right(Unit) + } override suspend fun markUserAsDeletedAndRemoveFromGroupConversations( userId: UserId @@ -598,9 +675,10 @@ internal class UserDataSource internal constructor( userDAO.markUserAsDeletedAndRemoveFromGroupConv(userId.toDao()) }.map { it.map(ConversationIDEntity::toModel) } - override suspend fun markAsDeleted(userId: List): Either = wrapStorageRequest { - userDAO.markAsDeleted(userId.map { it.toDao() }) - } + override suspend fun markAsDeleted(userId: List): Either = + wrapStorageRequest { + userDAO.markAsDeleted(userId.map { it.toDao() }) + } override suspend fun defederateUser(userId: UserId): Either { return wrapStorageRequest { @@ -620,13 +698,14 @@ internal class UserDataSource internal constructor( ) } - override suspend fun syncUsersWithoutMetadata(): Either = wrapStorageRequest { - userDAO.getUsersDetailsWithoutMetadata() - }.flatMap { usersWithoutMetadata -> - kaliumLogger.d("Numbers of users to refresh: ${usersWithoutMetadata.size}") - val userIds = usersWithoutMetadata.map { it.id.toModel() }.toSet() - fetchUsersByIds(userIds) - } + override suspend fun syncUsersWithoutMetadata(): Either = + wrapStorageRequest { + userDAO.getUsersDetailsWithoutMetadata() + }.flatMap { usersWithoutMetadata -> + kaliumLogger.d("Numbers of users to refresh: ${usersWithoutMetadata.size}") + val userIds = usersWithoutMetadata.map { it.id.toModel() }.toSet() + fetchUsersByIds(userIds) + } override suspend fun removeUserBrokenAsset(qualifiedID: QualifiedID) = wrapStorageRequest { userDAO.removeUserAsset(qualifiedID.toDao()) @@ -639,13 +718,27 @@ internal class UserDataSource internal constructor( } } - override suspend fun getOneOnOnConversationId(userId: QualifiedID): Either = wrapStorageRequest { - userDAO.getOneOnOnConversationId(userId.toDao())?.toModel() - } + override suspend fun getOneOnOnConversationId(userId: QualifiedID): Either = + wrapStorageRequest { + userDAO.getOneOnOnConversationId(userId.toDao())?.toModel() + } - override suspend fun getNameAndHandle(userId: UserId): Either = wrapStorageRequest { - userDAO.getNameAndHandle(userId.toDao()) - }.map { NameAndHandle.fromEntity(it) } + override suspend fun getNameAndHandle(userId: UserId): Either = + wrapStorageRequest { + userDAO.getNameAndHandle(userId.toDao()) + }.map { NameAndHandle.fromEntity(it) } + + override suspend fun migrateUserToTeam(teamName: String): Either { + return wrapApiRequest { upgradePersonalToTeamApi.migrateToTeam(teamName) } + .onSuccess { + kaliumLogger.d("Migrated user to team") + fetchSelfUser() + // TODO Invalidate team id in memory so UserSessionScope.selfTeamId got updated data + } + .onFailure { failure -> + kaliumLogger.e("Failed to migrate user to team: $failure") + } + } companion object { internal const val SELF_USER_ID_KEY = "selfUserID" diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 7351839496c..6956991e385 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -298,6 +298,8 @@ import com.wire.kalium.logic.feature.session.token.AccessTokenRefresherImpl import com.wire.kalium.logic.feature.team.SyncSelfTeamUseCase import com.wire.kalium.logic.feature.team.SyncSelfTeamUseCaseImpl import com.wire.kalium.logic.feature.team.TeamScope +import com.wire.kalium.logic.feature.team.migration.MigrateFromPersonalToTeamUseCase +import com.wire.kalium.logic.feature.team.migration.MigrateFromPersonalToTeamUseCaseImpl import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCaseImpl import com.wire.kalium.logic.feature.user.IsE2EIEnabledUseCase @@ -782,16 +784,17 @@ class UserSessionScope internal constructor( ) private val userRepository: UserRepository = UserDataSource( - userStorage.database.userDAO, - userStorage.database.metadataDAO, - userStorage.database.clientDAO, - authenticatedNetworkContainer.selfApi, - authenticatedNetworkContainer.userDetailsApi, - authenticatedNetworkContainer.teamsApi, - globalScope.sessionRepository, - userId, - selfTeamId, - legalHoldHandler + userDAO = userStorage.database.userDAO, + metadataDAO = userStorage.database.metadataDAO, + clientDAO = userStorage.database.clientDAO, + selfApi = authenticatedNetworkContainer.selfApi, + userDetailsApi = authenticatedNetworkContainer.userDetailsApi, + upgradePersonalToTeamApi = authenticatedNetworkContainer.upgradePersonalToTeamApi, + teamsApi = authenticatedNetworkContainer.teamsApi, + sessionRepository = globalScope.sessionRepository, + selfUserId = userId, + selfTeamIdProvider = selfTeamId, + legalHoldHandler = legalHoldHandler, ) private val accountRepository: AccountRepository @@ -2074,6 +2077,9 @@ class UserSessionScope internal constructor( userScopedLogger ) + val migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase + get() = MigrateFromPersonalToTeamUseCaseImpl(userRepository) + internal val getProxyCredentials: GetProxyCredentialsUseCase get() = GetProxyCredentialsUseCaseImpl(sessionManager) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt new file mode 100644 index 00000000000..ddb3e2b7ec4 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt @@ -0,0 +1,49 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.team.migration + +import com.wire.kalium.logic.CoreFailure +import com.wire.kalium.logic.data.user.UserRepository +import com.wire.kalium.logic.functional.fold + +interface MigrateFromPersonalToTeamUseCase { + suspend operator fun invoke(teamName: String): MigrateFromPersonalToTeamResult +} + +sealed class MigrateFromPersonalToTeamResult { + data class Success(val teamId: String, val teamName: String) : MigrateFromPersonalToTeamResult() + data class Error(val failure: CoreFailure) : MigrateFromPersonalToTeamResult() +} + +internal class MigrateFromPersonalToTeamUseCaseImpl internal constructor( + private val userRepository: UserRepository, +) : MigrateFromPersonalToTeamUseCase { + override suspend operator fun invoke( + teamName: String, + ): MigrateFromPersonalToTeamResult { + return userRepository.migrateUserToTeam(teamName) + .fold( + { error -> return MigrateFromPersonalToTeamResult.Error(error) }, + { success -> + MigrateFromPersonalToTeamResult.Success( + teamId = success.teamId, + teamName = success.teamName, + ) + }) + } +} \ No newline at end of file diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/UpgradePersonalToTeamDTO.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/UpgradePersonalToTeamDTO.kt new file mode 100644 index 00000000000..558f2085106 --- /dev/null +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/UpgradePersonalToTeamDTO.kt @@ -0,0 +1,27 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.authenticated + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class CreateUserTeamDTO( + @SerialName("team_id") val teamId: String, + @SerialName("team_name") val teamName: String, +) \ No newline at end of file diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt new file mode 100644 index 00000000000..07f02064828 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt @@ -0,0 +1,30 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.base.authenticated + +import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.utils.NetworkResponse + +interface UpgradePersonalToTeamApi : BaseApi { + + suspend fun migrateToTeam(teamName: String): NetworkResponse + + companion object { + const val MIN_API_VERSION = 7 + } +} \ No newline at end of file diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt new file mode 100644 index 00000000000..8585dfb71cf --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt @@ -0,0 +1,33 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v0.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi +import com.wire.kalium.network.utils.NetworkResponse + +internal open class UpgradePersonalToTeamApiV0 internal constructor( + private val authenticatedNetworkClient: AuthenticatedNetworkClient, +) : UpgradePersonalToTeamApi { + + internal val httpClient get() = authenticatedNetworkClient.httpClient + override suspend fun migrateToTeam(teamName: String): NetworkResponse = + getApiNotSupportedError(::migrateToTeam.name, UpgradePersonalToTeamApi.MIN_API_VERSION) +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt index 682e57c52b7..a122fb77b92 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -59,6 +60,7 @@ import com.wire.kalium.network.api.v0.authenticated.PreKeyApiV0 import com.wire.kalium.network.api.v0.authenticated.PropertiesApiV0 import com.wire.kalium.network.api.v0.authenticated.SelfApiV0 import com.wire.kalium.network.api.v0.authenticated.TeamsApiV0 +import com.wire.kalium.network.api.v0.authenticated.UpgradePersonalToTeamApiV0 import com.wire.kalium.network.api.v0.authenticated.UserDetailsApiV0 import com.wire.kalium.network.api.v0.authenticated.UserSearchApiV0 import com.wire.kalium.network.api.vcommon.WildCardApiImpl @@ -136,4 +138,9 @@ internal class AuthenticatedNetworkContainerV0 internal constructor( override val propertiesApi: PropertiesApi get() = PropertiesApiV0(networkClient) override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) + + override val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + get() = UpgradePersonalToTeamApiV0( + networkClient + ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/UpgradePersonalToTeamApiV2.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/UpgradePersonalToTeamApiV2.kt new file mode 100644 index 00000000000..40d87735978 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/UpgradePersonalToTeamApiV2.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v2.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v0.authenticated.UpgradePersonalToTeamApiV0 + +internal open class UpgradePersonalToTeamApiV2 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, +) : UpgradePersonalToTeamApiV0(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt index aafbf72caef..e5878c1ebfa 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -60,6 +61,7 @@ import com.wire.kalium.network.api.v2.authenticated.PreKeyApiV2 import com.wire.kalium.network.api.v2.authenticated.PropertiesApiV2 import com.wire.kalium.network.api.v2.authenticated.SelfApiV2 import com.wire.kalium.network.api.v2.authenticated.TeamsApiV2 +import com.wire.kalium.network.api.v2.authenticated.UpgradePersonalToTeamApiV2 import com.wire.kalium.network.api.v2.authenticated.UserDetailsApiV2 import com.wire.kalium.network.api.v2.authenticated.UserSearchApiV2 import com.wire.kalium.network.api.vcommon.WildCardApiImpl @@ -139,4 +141,9 @@ internal class AuthenticatedNetworkContainerV2 internal constructor( override val propertiesApi: PropertiesApi get() = PropertiesApiV2(networkClient) override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) + + override val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + get() = UpgradePersonalToTeamApiV2( + networkClient + ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/UpgradePersonalToTeamApiV3.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/UpgradePersonalToTeamApiV3.kt new file mode 100644 index 00000000000..a2502fea5a8 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/UpgradePersonalToTeamApiV3.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v3.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v2.authenticated.UpgradePersonalToTeamApiV2 + +internal open class UpgradePersonalToTeamApiV3 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, +) : UpgradePersonalToTeamApiV2(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt index 9afa50d676f..55278eb3477 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -61,6 +62,7 @@ import com.wire.kalium.network.api.v3.authenticated.PreKeyApiV3 import com.wire.kalium.network.api.v3.authenticated.PropertiesApiV3 import com.wire.kalium.network.api.v3.authenticated.SelfApiV3 import com.wire.kalium.network.api.v3.authenticated.TeamsApiV3 +import com.wire.kalium.network.api.v3.authenticated.UpgradePersonalToTeamApiV3 import com.wire.kalium.network.api.v3.authenticated.UserDetailsApiV3 import com.wire.kalium.network.api.v3.authenticated.UserSearchApiV3 import com.wire.kalium.network.api.vcommon.WildCardApiImpl @@ -140,4 +142,9 @@ internal class AuthenticatedNetworkContainerV3 internal constructor( override val propertiesApi: PropertiesApi get() = PropertiesApiV3(networkClient) override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) + + override val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + get() = UpgradePersonalToTeamApiV3( + networkClient + ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt new file mode 100644 index 00000000000..58801259fcd --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v4.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v2.authenticated.UpgradePersonalToTeamApiV2 + +internal open class UpgradePersonalToTeamApiV4 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, +) : UpgradePersonalToTeamApiV2(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt index fda8298f30b..0bdf244f595 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -60,6 +61,7 @@ import com.wire.kalium.network.api.v4.authenticated.PreKeyApiV4 import com.wire.kalium.network.api.v4.authenticated.PropertiesApiV4 import com.wire.kalium.network.api.v4.authenticated.SelfApiV4 import com.wire.kalium.network.api.v4.authenticated.TeamsApiV4 +import com.wire.kalium.network.api.v4.authenticated.UpgradePersonalToTeamApiV4 import com.wire.kalium.network.api.v4.authenticated.UserDetailsApiV4 import com.wire.kalium.network.api.v4.authenticated.UserSearchApiV4 import com.wire.kalium.network.api.vcommon.WildCardApiImpl @@ -139,4 +141,9 @@ internal class AuthenticatedNetworkContainerV4 internal constructor( override val propertiesApi: PropertiesApi get() = PropertiesApiV4(networkClient) override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) + + override val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + get() = UpgradePersonalToTeamApiV4( + networkClient + ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/UpgradePersonalToTeamApiV5.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/UpgradePersonalToTeamApiV5.kt new file mode 100644 index 00000000000..98428ed0f45 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/UpgradePersonalToTeamApiV5.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v5.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v4.authenticated.UpgradePersonalToTeamApiV4 + +internal open class UpgradePersonalToTeamApiV5 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, +) : UpgradePersonalToTeamApiV4(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt index 4bd93b1eb39..d010a486f99 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -60,6 +61,7 @@ import com.wire.kalium.network.api.v5.authenticated.PreKeyApiV5 import com.wire.kalium.network.api.v5.authenticated.PropertiesApiV5 import com.wire.kalium.network.api.v5.authenticated.SelfApiV5 import com.wire.kalium.network.api.v5.authenticated.TeamsApiV5 +import com.wire.kalium.network.api.v5.authenticated.UpgradePersonalToTeamApiV5 import com.wire.kalium.network.api.v5.authenticated.UserDetailsApiV5 import com.wire.kalium.network.api.v5.authenticated.UserSearchApiV5 import com.wire.kalium.network.api.vcommon.WildCardApiImpl @@ -139,4 +141,9 @@ internal class AuthenticatedNetworkContainerV5 internal constructor( override val propertiesApi: PropertiesApi get() = PropertiesApiV5(networkClient) override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) + + override val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + get() = UpgradePersonalToTeamApiV5( + networkClient + ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/UpgradePersonalToTeamApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/UpgradePersonalToTeamApiV6.kt new file mode 100644 index 00000000000..f53025a78b4 --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/UpgradePersonalToTeamApiV6.kt @@ -0,0 +1,26 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v6.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.v5.authenticated.UpgradePersonalToTeamApiV5 + +internal open class UpgradePersonalToTeamApiV6 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, +) : UpgradePersonalToTeamApiV5(authenticatedNetworkClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt index 1499d064c38..22d83fe86ec 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -60,6 +61,7 @@ import com.wire.kalium.network.api.v6.authenticated.PreKeyApiV6 import com.wire.kalium.network.api.v6.authenticated.PropertiesApiV6 import com.wire.kalium.network.api.v6.authenticated.SelfApiV6 import com.wire.kalium.network.api.v6.authenticated.TeamsApiV6 +import com.wire.kalium.network.api.v6.authenticated.UpgradePersonalToTeamApiV6 import com.wire.kalium.network.api.v6.authenticated.UserDetailsApiV6 import com.wire.kalium.network.api.v6.authenticated.UserSearchApiV6 import com.wire.kalium.network.api.vcommon.WildCardApiImpl @@ -139,4 +141,10 @@ internal class AuthenticatedNetworkContainerV6 internal constructor( override val propertiesApi: PropertiesApi get() = PropertiesApiV6(networkClient) override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) + + override val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + get() = UpgradePersonalToTeamApiV6( + networkClient + ) + } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt new file mode 100644 index 00000000000..fb4d322802c --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt @@ -0,0 +1,54 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.network.api.v7.authenticated + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.unauthenticated.register.NewBindingTeamDTO +import com.wire.kalium.network.api.v6.authenticated.UpgradePersonalToTeamApiV6 +import com.wire.kalium.network.utils.NetworkResponse +import com.wire.kalium.network.utils.wrapKaliumResponse +import io.ktor.client.request.post +import io.ktor.client.request.setBody + +internal open class UpgradePersonalToTeamApiV7 internal constructor( + authenticatedNetworkClient: AuthenticatedNetworkClient, +) : UpgradePersonalToTeamApiV6(authenticatedNetworkClient) { + + override suspend fun migrateToTeam(teamName: String): NetworkResponse { + return wrapKaliumResponse { + + httpClient.post(PATH_MIGRATE_TO_TEAM) { + // We do not ask user for icon at this point, so we use hardcoded values from the backend + setBody( + NewBindingTeamDTO( + name = teamName, + iconAssetId = "default", + iconKey = "abc", + currency = null,//TODO is this ok? + ) + ) + } + } + } + + companion object { + const val PATH_MIGRATE_TO_TEAM = "upgrade-personal-to-team" + } +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt index 8f348f105eb..5f283abaa7d 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -60,6 +61,7 @@ import com.wire.kalium.network.api.v7.authenticated.PreKeyApiV7 import com.wire.kalium.network.api.v7.authenticated.PropertiesApiV7 import com.wire.kalium.network.api.v7.authenticated.SelfApiV7 import com.wire.kalium.network.api.v7.authenticated.TeamsApiV7 +import com.wire.kalium.network.api.v7.authenticated.UpgradePersonalToTeamApiV7 import com.wire.kalium.network.api.v7.authenticated.UserDetailsApiV7 import com.wire.kalium.network.api.v7.authenticated.UserSearchApiV7 import com.wire.kalium.network.api.vcommon.WildCardApiImpl @@ -148,4 +150,9 @@ internal class AuthenticatedNetworkContainerV7 internal constructor( override val propertiesApi: PropertiesApi get() = PropertiesApiV7(networkClient) override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) + + override val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + get() = UpgradePersonalToTeamApiV7( + networkClient + ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index 6eb175d3280..1561d2ec5c0 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -24,6 +24,7 @@ import com.wire.kalium.network.AuthenticatedWebSocketClient import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi @@ -48,7 +49,6 @@ import com.wire.kalium.network.api.v0.authenticated.networkContainer.Authenticat import com.wire.kalium.network.api.v2.authenticated.networkContainer.AuthenticatedNetworkContainerV2 import com.wire.kalium.network.api.v4.authenticated.networkContainer.AuthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.authenticated.networkContainer.AuthenticatedNetworkContainerV5 -import com.wire.kalium.network.api.v6.authenticated.networkContainer.AuthenticatedNetworkContainerV6 import com.wire.kalium.network.api.v7.authenticated.networkContainer.AuthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager @@ -110,6 +110,8 @@ interface AuthenticatedNetworkContainer { val wildCardApi: WildCardApi + val upgradePersonalToTeamApi: UpgradePersonalToTeamApi + companion object { @Suppress("LongParameterList", "LongMethod") @@ -180,7 +182,18 @@ interface AuthenticatedNetworkContainer { kaliumLogger ) - 6 -> AuthenticatedNetworkContainerV6( + + //TODO revert object to v6 + 6 -> AuthenticatedNetworkContainerV7( + sessionManager, + selfUserId, + certificatePinning, + mockEngine, + mockWebSocketSession, + kaliumLogger + ) + + 7 -> AuthenticatedNetworkContainerV7( sessionManager, selfUserId, certificatePinning, From f60103a0c57a269263c5335146f7896e83bd8046 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Wed, 13 Nov 2024 16:33:36 +0100 Subject: [PATCH 08/22] self review --- .../kotlin/com/wire/kalium/logic/data/user/UserRepository.kt | 2 +- .../kalium/network/api/v0/authenticated/ConversationApiV0.kt | 1 + .../api/v7/authenticated/UpgradePersonalToTeamApiV7.kt | 2 +- .../networkContainer/AuthenticatedNetworkContainer.kt | 5 ++--- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt index 48fa74dc7bd..51cca2f5ba9 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt @@ -733,7 +733,7 @@ internal class UserDataSource internal constructor( .onSuccess { kaliumLogger.d("Migrated user to team") fetchSelfUser() - // TODO Invalidate team id in memory so UserSessionScope.selfTeamId got updated data + // TODO Invalidate team id in memory so UserSessionScope.selfTeamId got updated data WPB-12187 } .onFailure { failure -> kaliumLogger.e("Failed to migrate user to team: $failure") 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..579fd16af11 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 @@ -395,6 +395,7 @@ internal open class ConversationApiV0 internal constructor( httpClient.get("$PATH_CONVERSATIONS/${conversationId.value}/$PATH_CODE") } + protected companion object { const val PATH_CONVERSATIONS = "conversations" const val PATH_SELF = "self" diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt index fb4d322802c..dbc382e06af 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt @@ -41,7 +41,7 @@ internal open class UpgradePersonalToTeamApiV7 internal constructor( name = teamName, iconAssetId = "default", iconKey = "abc", - currency = null,//TODO is this ok? + currency = null, ) ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index 1561d2ec5c0..72ca1ba0ed6 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -49,6 +49,7 @@ import com.wire.kalium.network.api.v0.authenticated.networkContainer.Authenticat import com.wire.kalium.network.api.v2.authenticated.networkContainer.AuthenticatedNetworkContainerV2 import com.wire.kalium.network.api.v4.authenticated.networkContainer.AuthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.authenticated.networkContainer.AuthenticatedNetworkContainerV5 +import com.wire.kalium.network.api.v6.authenticated.networkContainer.AuthenticatedNetworkContainerV6 import com.wire.kalium.network.api.v7.authenticated.networkContainer.AuthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager @@ -182,9 +183,7 @@ interface AuthenticatedNetworkContainer { kaliumLogger ) - - //TODO revert object to v6 - 6 -> AuthenticatedNetworkContainerV7( + 6 -> AuthenticatedNetworkContainerV6( sessionManager, selfUserId, certificatePinning, From de4bc40a68c11e41ca41ac6de556f4bd160b079a Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Wed, 13 Nov 2024 16:52:01 +0100 Subject: [PATCH 09/22] detekt --- .../kalium/logic/data/user/UserRepository.kt | 5 +-- .../MigrateFromPersonalToTeamUseCase.kt | 9 ++++- ...sonalToTeamDTO.kt => CreateUserTeamDTO.kt} | 2 +- .../authenticated/UpgradePersonalToTeamApi.kt | 2 +- .../api/v0/authenticated/ConversationApiV0.kt | 39 ++++++++++++++----- 5 files changed, 41 insertions(+), 16 deletions(-) rename network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/{UpgradePersonalToTeamDTO.kt => CreateUserTeamDTO.kt} (99%) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt index 51cca2f5ba9..e58a1801807 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt @@ -239,9 +239,8 @@ internal class UserDataSource internal constructor( .flatMap { wrapStorageRequest { metadataDAO.insertValue( - Json.encodeToString( - userEntity.id - ), SELF_USER_ID_KEY + Json.encodeToString(userEntity.id), + SELF_USER_ID_KEY ) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt index ddb3e2b7ec4..57821846fd2 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt @@ -21,6 +21,10 @@ import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.data.user.UserRepository import com.wire.kalium.logic.functional.fold +/** + * Use case to migrate user personal account to team account. + * This needs at least API V7 to work. + */ interface MigrateFromPersonalToTeamUseCase { suspend operator fun invoke(teamName: String): MigrateFromPersonalToTeamResult } @@ -44,6 +48,7 @@ internal class MigrateFromPersonalToTeamUseCaseImpl internal constructor( teamId = success.teamId, teamName = success.teamName, ) - }) + } + ) } -} \ No newline at end of file +} diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/UpgradePersonalToTeamDTO.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/CreateUserTeamDTO.kt similarity index 99% rename from network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/UpgradePersonalToTeamDTO.kt rename to network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/CreateUserTeamDTO.kt index 558f2085106..7c1f1be24ee 100644 --- a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/UpgradePersonalToTeamDTO.kt +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/CreateUserTeamDTO.kt @@ -24,4 +24,4 @@ import kotlinx.serialization.Serializable data class CreateUserTeamDTO( @SerialName("team_id") val teamId: String, @SerialName("team_name") val teamName: String, -) \ No newline at end of file +) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt index 07f02064828..a0b5d910909 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt @@ -27,4 +27,4 @@ interface UpgradePersonalToTeamApi : BaseApi { companion object { const val MIN_API_VERSION = 7 } -} \ No newline at end of file +} 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 579fd16af11..593ab859487 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 @@ -82,7 +82,12 @@ internal open class ConversationApiV0 internal constructor( ): NetworkResponse = wrapKaliumResponse { httpClient.post("$PATH_CONVERSATIONS/$PATH_LIST_IDS") { - setBody(PaginationRequest(pagingState = pagingState, size = MAX_CONVERSATION_DETAILS_COUNT)) + setBody( + PaginationRequest( + pagingState = pagingState, + size = MAX_CONVERSATION_DETAILS_COUNT + ) + ) } } @@ -158,7 +163,11 @@ internal open class ConversationApiV0 internal constructor( HttpStatusCode.OK -> wrapKaliumResponse { response } .mapSuccess { ConversationMemberRemovedResponse.Changed(it) } - HttpStatusCode.NoContent -> NetworkResponse.Success(ConversationMemberRemovedResponse.Unchanged, response) + HttpStatusCode.NoContent -> NetworkResponse.Success( + ConversationMemberRemovedResponse.Unchanged, + response + ) + else -> wrapKaliumResponse { response } } } @@ -185,7 +194,11 @@ internal open class ConversationApiV0 internal constructor( setBody(updateConversationAccessRequest) }.let { httpResponse -> when (httpResponse.status) { - HttpStatusCode.NoContent -> NetworkResponse.Success(UpdateConversationAccessResponse.AccessUnchanged, httpResponse) + HttpStatusCode.NoContent -> NetworkResponse.Success( + UpdateConversationAccessResponse.AccessUnchanged, + httpResponse + ) + else -> wrapKaliumResponse { httpResponse } .mapSuccess { UpdateConversationAccessResponse.AccessUpdated(it) @@ -221,7 +234,11 @@ internal open class ConversationApiV0 internal constructor( HttpStatusCode.OK -> wrapKaliumResponse { response } .mapSuccess { ConversationRenameResponse.Changed(it) } - HttpStatusCode.NoContent -> NetworkResponse.Success(ConversationRenameResponse.Unchanged, response) + HttpStatusCode.NoContent -> NetworkResponse.Success( + ConversationRenameResponse.Unchanged, + response + ) + else -> wrapKaliumResponse { response } } } @@ -252,7 +269,10 @@ internal open class ConversationApiV0 internal constructor( } } - override suspend fun fetchLimitedInformationViaCode(code: String, key: String): NetworkResponse = + override suspend fun fetchLimitedInformationViaCode( + code: String, + key: String + ): NetworkResponse = wrapKaliumResponse { httpClient.get("$PATH_CONVERSATIONS/$PATH_JOIN") { parameter(QUERY_KEY_CODE, code) @@ -361,9 +381,10 @@ internal open class ConversationApiV0 internal constructor( } } - override suspend fun revokeGuestRoomLink(conversationId: ConversationId): NetworkResponse = wrapKaliumResponse { - httpClient.delete("$PATH_CONVERSATIONS/${conversationId.value}/$PATH_CODE") - } + override suspend fun revokeGuestRoomLink(conversationId: ConversationId): NetworkResponse = + wrapKaliumResponse { + httpClient.delete("$PATH_CONVERSATIONS/${conversationId.value}/$PATH_CODE") + } override suspend fun updateMessageTimer( conversationId: ConversationId, @@ -384,6 +405,7 @@ internal open class ConversationApiV0 internal constructor( setBody(typingIndicatorMode) } } + override suspend fun updateProtocol( conversationId: ConversationId, protocol: ConvProtocol @@ -395,7 +417,6 @@ internal open class ConversationApiV0 internal constructor( httpClient.get("$PATH_CONVERSATIONS/${conversationId.value}/$PATH_CODE") } - protected companion object { const val PATH_CONVERSATIONS = "conversations" const val PATH_SELF = "self" From c1729c1d15f90d04eb6de4c1956f937b630d581b Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Thu, 14 Nov 2024 12:51:54 +0100 Subject: [PATCH 10/22] fix ConversationResponse versions usage for notifications --- .../com/wire/kalium/logic/data/event/Event.kt | 10 ++++++---- .../wire/kalium/logic/data/event/EventMapper.kt | 2 +- .../conversation/NewConversationEventHandler.kt | 16 ++++++++-------- .../responses/NotificationEventsResponseJson.kt | 2 +- .../conversation/ConversationResponseJson.kt | 16 ++++++++-------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt index ea2b0742ac4..a97e8d89511 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt @@ -45,7 +45,7 @@ import com.wire.kalium.logic.data.user.Connection import com.wire.kalium.logic.data.user.SupportedProtocol import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.sync.incremental.EventSource -import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseV6 +import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse import com.wire.kalium.util.DateTimeUtil import com.wire.kalium.util.DateTimeUtil.toIsoDateTimeString import com.wire.kalium.util.serialization.toJsonElement @@ -182,7 +182,7 @@ sealed class Event(open val id: String) { override val conversationId: ConversationId, val senderUserId: UserId, val dateTime: Instant, - val conversation: ConversationResponseV6 + val conversation: ConversationResponse ) : Conversation(id, conversationId) { override fun toLogMap(): Map = mapOf( @@ -390,14 +390,16 @@ sealed class Event(open val id: String) { val uri: String?, val isPasswordProtected: Boolean, ) : Conversation(id, conversationId) { - override fun toLogMap(): Map = mapOf(typeKey to "Conversation.CodeUpdated") + override fun toLogMap(): Map = + mapOf(typeKey to "Conversation.CodeUpdated") } data class CodeDeleted( override val id: String, override val conversationId: ConversationId, ) : Conversation(id, conversationId) { - override fun toLogMap(): Map = mapOf(typeKey to "Conversation.CodeDeleted") + override fun toLogMap(): Map = + mapOf(typeKey to "Conversation.CodeDeleted") } data class TypingIndicator( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt index 54a9c614746..ba1fb539fd8 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt @@ -377,7 +377,7 @@ class EventMapper( eventContentDTO.qualifiedConversation.toModel(), eventContentDTO.qualifiedFrom.toModel(), eventContentDTO.time, - eventContentDTO.data.toV6() + eventContentDTO.data ) fun conversationMemberJoin( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt index b2e8565aefc..fea1b061e74 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt @@ -55,7 +55,7 @@ internal class NewConversationEventHandlerImpl( val eventLogger = kaliumLogger.createEventProcessingLogger(event) val selfUserTeamId = selfTeamIdProvider().getOrNull() conversationRepository - .persistConversation(event.conversation.conversation, selfUserTeamId?.value, true) + .persistConversation(event.conversation, selfUserTeamId?.value, true) .flatMap { isNewUnhandledConversation -> resolveConversationIfOneOnOne(selfUserTeamId, event) .flatMap { @@ -66,7 +66,7 @@ internal class NewConversationEventHandlerImpl( } .flatMap { userRepository.fetchUsersIfUnknownByIds( - event.conversation.conversation.members.otherMembers.map { + event.conversation.members.otherMembers.map { it.id.toModel() }.toSet() ) @@ -84,9 +84,9 @@ internal class NewConversationEventHandlerImpl( selfUserTeamId: TeamId?, event: Event.Conversation.NewConversation ) = - if (event.conversation.conversation.toConversationType(selfUserTeamId) == ConversationEntity.Type.ONE_ON_ONE) { + if (event.conversation.toConversationType(selfUserTeamId) == ConversationEntity.Type.ONE_ON_ONE) { val otherUserId = - event.conversation.conversation.members.otherMembers.first().id.toModel() + event.conversation.members.otherMembers.first().id.toModel() oneOnOneResolver.resolveOneOnOneConversationWithUserId( userId = otherUserId, invalidateCurrentKnownProtocols = true @@ -107,20 +107,20 @@ internal class NewConversationEventHandlerImpl( if (isNewUnhandledConversation) { newGroupConversationSystemMessagesCreator.conversationStarted( event.senderUserId, - event.conversation.conversation, + event.conversation, event.dateTime ) newGroupConversationSystemMessagesCreator.conversationResolvedMembersAdded( event.conversationId.toDao(), - event.conversation.conversation.members.otherMembers.map { it.id.toModel() }, + event.conversation.members.otherMembers.map { it.id.toModel() }, event.dateTime ) newGroupConversationSystemMessagesCreator.conversationReadReceiptStatus( - event.conversation.conversation, + event.conversation, event.dateTime ) newGroupConversationSystemMessagesCreator.conversationStartedUnverifiedWarning( - event.conversation.conversation.id.toModel(), + event.conversation.id.toModel(), event.dateTime ) } diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt index 2d57de3813f..2d5458837f0 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt @@ -157,7 +157,7 @@ object NotificationEventsResponseJson { | "id" : "${eventData.qualifiedFrom.value}", | "domain" : "${eventData.qualifiedFrom.domain}" | }, - | "data" : ${ConversationResponseJson.conversationResponseSerializer(eventData.data.toV6())}, + | "data" : ${ConversationResponseJson.conversationResponseSerializerV3(eventData.data)}, | "time" : "2022-04-12T13:57:02.414Z", | "type" : "conversation.create" |} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt index cab77c6e97d..9a049a1ecba 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt @@ -43,8 +43,8 @@ import kotlinx.serialization.json.putJsonObject object ConversationResponseJson { - val conversationResponseSerializer = { it: ConversationResponseV6 -> - buildConversationResponse(it).toString() + val conversationResponseSerializerV6 = { it: ConversationResponseV6 -> + buildConversationResponseV6(it).toString() } val conversationResponseSerializerV3 = { it: ConversationResponse -> @@ -55,7 +55,7 @@ object ConversationResponseJson { buildConversationResponseV3(it, useDeprecatedAccessRole = true).toString() } - private val conversationResponse = ConversationResponseV6( + private val conversationResponseV6 = ConversationResponseV6( conversation = ConversationResponse( "fdf23116-42a5-472c-8316-e10655f5d11e", ConversationMembersResponse( @@ -97,23 +97,23 @@ object ConversationResponseJson { ) val v6 = ValidJsonProvider( - conversationResponse, conversationResponseSerializer + conversationResponseV6, conversationResponseSerializerV6 ) val v3 = ValidJsonProvider( - conversationResponse.conversation, + conversationResponseV6.conversation, conversationResponseSerializerV3 ) fun v0(accessRole: Set? = null) = ValidJsonProvider( - conversationResponse.conversation.copy( - accessRole = accessRole ?: conversationResponse.conversation.accessRole + conversationResponseV6.conversation.copy( + accessRole = accessRole ?: conversationResponseV6.conversation.accessRole ), conversationResponseSerializerWithDeprecatedAccessRole ) } -fun buildConversationResponse( +fun buildConversationResponseV6( conversationResponse: ConversationResponseV6, useDeprecatedAccessRole: Boolean = false, ): JsonObject = buildJsonObject { From f520d2600b2e73740d822ed1d5c0dee11cd4eab3 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Thu, 14 Nov 2024 12:57:05 +0100 Subject: [PATCH 11/22] detekt --- .../mocks/responses/conversation/ConversationResponseJson.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt index 9a049a1ecba..8fbd78dff25 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt @@ -97,7 +97,8 @@ object ConversationResponseJson { ) val v6 = ValidJsonProvider( - conversationResponseV6, conversationResponseSerializerV6 + conversationResponseV6, + conversationResponseSerializerV6 ) val v3 = ValidJsonProvider( From 2c383ac02af8edfdff30ece7e86b6f40ffa1d196 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Thu, 14 Nov 2024 13:07:49 +0100 Subject: [PATCH 12/22] fix test --- .../wire/kalium/logic/data/client/ClientRepositoryTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/client/ClientRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/client/ClientRepositoryTest.kt index 8263608edf6..4999236394a 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/client/ClientRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/client/ClientRepositoryTest.kt @@ -36,11 +36,11 @@ import com.wire.kalium.logic.framework.TestEvent import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.util.shouldFail import com.wire.kalium.logic.util.shouldSucceed -import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.authenticated.client.ClientDTO import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO import com.wire.kalium.network.api.authenticated.client.SimpleClientResponse +import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.model.ErrorResponse import com.wire.kalium.network.exceptions.KaliumException import com.wire.kalium.network.utils.NetworkResponse @@ -257,7 +257,7 @@ class ClientRepositoryTest { deviceType = DeviceTypeDTO.Desktop, label = null, model = "Mac ox", - capabilities = null, + capabilities = listOf(), mlsPublicKeys = null, cookie = null ), @@ -269,7 +269,7 @@ class ClientRepositoryTest { deviceType = DeviceTypeDTO.Phone, label = null, model = "iphone 15", - capabilities = null, + capabilities = listOf(), mlsPublicKeys = null, cookie = null ) From 55fa044b7cafc694c7f0eab50ad2f74910dbced7 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Thu, 14 Nov 2024 13:37:01 +0100 Subject: [PATCH 13/22] test fix --- .../logic/data/user/UserRepositoryTest.kt | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt index 64b822fe429..301d440940c 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt @@ -44,15 +44,16 @@ import com.wire.kalium.logic.test_util.TestNetworkException.generic import com.wire.kalium.logic.test_util.TestNetworkResponseError import com.wire.kalium.logic.util.shouldFail import com.wire.kalium.logic.util.shouldSucceed -import com.wire.kalium.network.api.base.authenticated.TeamsApi -import com.wire.kalium.network.api.base.authenticated.self.SelfApi import com.wire.kalium.network.api.authenticated.teams.TeamMemberDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberListNonPaginated import com.wire.kalium.network.api.authenticated.userDetails.ListUserRequest import com.wire.kalium.network.api.authenticated.userDetails.ListUsersDTO import com.wire.kalium.network.api.authenticated.userDetails.QualifiedUserIdListRequest -import com.wire.kalium.network.api.base.authenticated.userDetails.UserDetailsApi import com.wire.kalium.network.api.authenticated.userDetails.qualifiedIds +import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi +import com.wire.kalium.network.api.base.authenticated.self.SelfApi +import com.wire.kalium.network.api.base.authenticated.userDetails.UserDetailsApi import com.wire.kalium.network.api.model.LegalHoldStatusDTO import com.wire.kalium.network.api.model.UserProfileDTO import com.wire.kalium.network.utils.NetworkResponse @@ -829,20 +830,25 @@ class UserRepositoryTest { @Mock val legalHoldHandler: LegalHoldHandler = mock(LegalHoldHandler::class) + @Mock + val upgradePersonalToTeamApi: UpgradePersonalToTeamApi = + mock(UpgradePersonalToTeamApi::class) + val selfUserId = TestUser.SELF.id val userRepository: UserRepository by lazy { UserDataSource( - userDAO, - metadataDAO, - clientDAO, - selfApi, - userDetailsApi, - teamsApi, - sessionRepository, - selfUserId, - selfTeamIdProvider, - legalHoldHandler + userDAO = userDAO, + metadataDAO = metadataDAO, + clientDAO = clientDAO, + selfApi = selfApi, + userDetailsApi = userDetailsApi, + teamsApi = teamsApi, + sessionRepository = sessionRepository, + selfUserId = selfUserId, + selfTeamIdProvider = selfTeamIdProvider, + legalHoldHandler = legalHoldHandler, + upgradePersonalToTeamApi = upgradePersonalToTeamApi, ) } From 87b0a2542183f1db88f518ac2225e3265961db62 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Sat, 16 Nov 2024 15:46:00 +0100 Subject: [PATCH 14/22] added tests --- .../kalium/logic/feature/UserSessionScope.kt | 4 +- .../MigrateFromPersonalToTeamUseCase.kt | 2 +- .../logic/data/user/UserRepositoryTest.kt | 49 ++++++ .../MigrateFromPersonalToTeamUseCaseTest.kt | 153 ++++++++++++++++++ .../MigrationUserToTeamResponseJson.kt | 68 ++++++++ .../AuthenticatedNetworkContainer.kt | 9 -- .../api/v7/UpgradePersonalToTeamApiV7Test.kt | 97 +++++++++++ 7 files changed, 370 insertions(+), 12 deletions(-) rename logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/{team => user}/migration/MigrateFromPersonalToTeamUseCase.kt (97%) create mode 100644 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt create mode 100644 network/src/commonTest/kotlin/com/wire/kalium/api/v7/UpgradePersonalToTeamApiV7Test.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 6956991e385..f7ed3ebf220 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -298,8 +298,6 @@ import com.wire.kalium.logic.feature.session.token.AccessTokenRefresherImpl import com.wire.kalium.logic.feature.team.SyncSelfTeamUseCase import com.wire.kalium.logic.feature.team.SyncSelfTeamUseCaseImpl import com.wire.kalium.logic.feature.team.TeamScope -import com.wire.kalium.logic.feature.team.migration.MigrateFromPersonalToTeamUseCase -import com.wire.kalium.logic.feature.team.migration.MigrateFromPersonalToTeamUseCaseImpl import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCaseImpl import com.wire.kalium.logic.feature.user.IsE2EIEnabledUseCase @@ -334,6 +332,8 @@ import com.wire.kalium.logic.feature.user.guestroomlink.MarkGuestLinkFeatureFlag import com.wire.kalium.logic.feature.user.guestroomlink.MarkGuestLinkFeatureFlagAsNotChangedUseCaseImpl import com.wire.kalium.logic.feature.user.guestroomlink.ObserveGuestRoomLinkFeatureFlagUseCase import com.wire.kalium.logic.feature.user.guestroomlink.ObserveGuestRoomLinkFeatureFlagUseCaseImpl +import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamUseCase +import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamUseCaseImpl import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigUseCase import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigUseCaseImpl import com.wire.kalium.logic.feature.user.screenshotCensoring.PersistScreenshotCensoringConfigUseCase diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt similarity index 97% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt rename to logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt index 57821846fd2..60ea0987ac5 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ -package com.wire.kalium.logic.feature.team.migration +package com.wire.kalium.logic.feature.user.migration import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.data.user.UserRepository diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt index 301d440940c..c401bd3be6e 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt @@ -44,6 +44,7 @@ import com.wire.kalium.logic.test_util.TestNetworkException.generic import com.wire.kalium.logic.test_util.TestNetworkResponseError import com.wire.kalium.logic.util.shouldFail import com.wire.kalium.logic.util.shouldSucceed +import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberListNonPaginated import com.wire.kalium.network.api.authenticated.userDetails.ListUserRequest @@ -802,6 +803,36 @@ class UserRepositoryTest { }.wasInvoked(exactly = once) } + @Test + fun givenApiRequestSucceeds_whenPersonalUserUpgradesToTeam_thenShouldSucceed() = runTest { + // given + val (arrangement, userRepository) = Arrangement() + .withMigrateUserToTeamSuccess() + .arrange() + // when + val result = userRepository.migrateUserToTeam("teamName") + // then + result.shouldSucceed() + coVerify { + arrangement.upgradePersonalToTeamApi.migrateToTeam(any()) + }.wasInvoked(exactly = once) + } + + @Test + fun givenApiRequestFails_whenPersonalUserUpgradesToTeam_thenShouldPropagateError() = runTest { + // given + val (arrangement, userRepository) = Arrangement() + .withMigrateUserToTeamFailure() + .arrange() + // when + val result = userRepository.migrateUserToTeam("teamName") + // then + result.shouldFail() + coVerify { + arrangement.upgradePersonalToTeamApi.migrateToTeam(any()) + }.wasInvoked(exactly = once) + } + private class Arrangement { @Mock val userDAO = mock(UserDAO::class) @@ -1035,6 +1066,24 @@ class UserRepositoryTest { }.returns(NetworkResponse.Success(result, mapOf(), 200)) } + suspend fun withMigrateUserToTeamSuccess() = apply { + coEvery { + upgradePersonalToTeamApi.migrateToTeam(any()) + }.returns( + NetworkResponse.Success( + CreateUserTeamDTO("teamId", "teamName"), + mapOf(), + 200 + ) + ) + } + + suspend fun withMigrateUserToTeamFailure() = apply { + coEvery { + upgradePersonalToTeamApi.migrateToTeam(any()) + }.returns(NetworkResponse.Error(generic)) + } + suspend inline fun arrange(block: (Arrangement.() -> Unit) = { }): Pair { withSelfUserIdFlowMetadataReturning(flowOf(TestUser.JSON_QUALIFIED_ID)) coEvery { diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt new file mode 100644 index 00000000000..ba775a8ed21 --- /dev/null +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt @@ -0,0 +1,153 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.logic.feature.user.migration + +import com.wire.kalium.logic.CoreFailure +import com.wire.kalium.logic.NetworkFailure +import com.wire.kalium.logic.data.user.UserRepository +import com.wire.kalium.logic.functional.Either +import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.model.ErrorResponse +import com.wire.kalium.network.exceptions.KaliumException +import io.ktor.http.HttpStatusCode +import io.mockative.Mock +import io.mockative.any +import io.mockative.coEvery +import io.mockative.mock +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertIs + +class MigrateFromPersonalToTeamUseCaseTest { + + @Test + fun givenRepositorySucceeds_whenMigratingUserToTeam_thenShouldPropagateSuccess() = runTest { + val (_, useCase) = Arrangement().withSuccessRepository().arrange() + + val result = useCase(teamName = "teamName") + + assertIs(result) + } + + @Test + fun givenRepositoryFailsWithNoNetworkConnection_whenMigratingUserToTeam_thenShouldPropagateFailure() = + runTest { + val coreFailure = NetworkFailure.NoNetworkConnection(null) + val (_, useCase) = Arrangement().withRepositoryReturning(Either.Left(coreFailure)) + .arrange() + + val result = useCase(teamName = "teamName") + + assertIs(result) + assertIs(result.failure) + } + + @Test + fun givenRepositoryFailsWithUserAlreadyInTeam_whenMigratingUserToTeam_thenShouldPropagateFailure() = + runTest { + val (_, useCase) = Arrangement().withUserAlreadyInTeamRepository().arrange() + + val result = useCase(teamName = "teamName") + + assertIs(result) + assertIs(result.failure) + val serverMiscommunication = result.failure as NetworkFailure.ServerMiscommunication + val invalidRequestError = + serverMiscommunication.kaliumException as KaliumException.InvalidRequestError + val errorLabel = invalidRequestError.errorResponse.label + + assertEquals("user-already-in-a-team", errorLabel) + } + + @Test + fun givenRepositoryFailsWithNotFound_whenMigratingUserToTeam_thenShouldPropagateFailure() = + runTest { + val (_, useCase) = Arrangement().withNotFoundRepository().arrange() + + val result = useCase(teamName = "teamName") + + assertIs(result) + assertIs(result.failure) + val serverMiscommunication = result.failure as NetworkFailure.ServerMiscommunication + val invalidRequestError = + serverMiscommunication.kaliumException as KaliumException.InvalidRequestError + val errorLabel = invalidRequestError.errorResponse.label + + assertEquals("not-found", errorLabel) + } + + + private class Arrangement { + @Mock + val userRepository: UserRepository = mock(UserRepository::class) + + suspend fun withSuccessRepository() = apply { + coEvery { userRepository.migrateUserToTeam(any()) }.returns( + Either.Right( + CreateUserTeamDTO( + "teamId", "teamName" + ) + ) + ) + } + + suspend fun withUserAlreadyInTeamRepository() = apply { + coEvery { userRepository.migrateUserToTeam(any()) }.returns( + Either.Left( + NetworkFailure.ServerMiscommunication( + KaliumException.InvalidRequestError( + ErrorResponse( + HttpStatusCode.Forbidden.value, + message = "Switching teams is not allowed", + label = "user-already-in-a-team", + ) + ) + ) + ) + ) + } + + suspend fun withNotFoundRepository() = apply { + coEvery { userRepository.migrateUserToTeam(any()) }.returns( + Either.Left( + NetworkFailure.ServerMiscommunication( + KaliumException.InvalidRequestError( + ErrorResponse( + HttpStatusCode.NotFound.value, + message = "User not found", + label = "not-found", + ) + ) + ) + ) + ) + } + + suspend fun withRepositoryReturning(result: Either) = + apply { + coEvery { userRepository.migrateUserToTeam(any()) }.returns(result) + } + + fun arrange() = this to MigrateFromPersonalToTeamUseCaseImpl( + userRepository = userRepository + ) + } + +} \ No newline at end of file diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt new file mode 100644 index 00000000000..6cef7c21f1f --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt @@ -0,0 +1,68 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.mocks.responses + +import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.model.ErrorResponse +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put + +object MigrationUserToTeamResponseJson { + val success = ValidJsonProvider( + serializableData = CreateUserTeamDTO( + teamId = "teamId", + teamName = "teamName" + ), + jsonProvider = { serializable -> + buildJsonObject { + put("team_id", serializable.teamId) + put("team_name", serializable.teamName) + }.toString() + } + ) + + val failedUserInTeam = ValidJsonProvider( + serializableData = ErrorResponse( + code = 403, + label = "user-already-in-a-team", + message = "Switching teams is not allowed" + ), + jsonProvider = { serializable -> + buildJsonObject { + put("code", serializable.code) + put("label", serializable.label) + put("message", serializable.message) + }.toString() + } + ) + + val failedUserNotFound = ValidJsonProvider( + serializableData = ErrorResponse( + code = 404, + label = "not-found", + message = "User not found" + ), + jsonProvider = { serializable -> + buildJsonObject { + put("code", serializable.code) + put("label", serializable.label) + put("message", serializable.message) + }.toString() + } + ) +} \ No newline at end of file diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index 72ca1ba0ed6..4dc23385f92 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -201,15 +201,6 @@ interface AuthenticatedNetworkContainer { kaliumLogger ) - 7 -> AuthenticatedNetworkContainerV7( - sessionManager, - selfUserId, - certificatePinning, - mockEngine, - mockWebSocketSession, - kaliumLogger - ) - else -> error("Unsupported version: $version") } } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v7/UpgradePersonalToTeamApiV7Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v7/UpgradePersonalToTeamApiV7Test.kt new file mode 100644 index 00000000000..d4b852bed55 --- /dev/null +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v7/UpgradePersonalToTeamApiV7Test.kt @@ -0,0 +1,97 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.api.v7 + +import com.wire.kalium.api.ApiTest +import com.wire.kalium.mocks.responses.MigrationUserToTeamResponseJson +import com.wire.kalium.network.api.v7.authenticated.UpgradePersonalToTeamApiV7 +import com.wire.kalium.network.utils.isSuccessful +import io.ktor.http.HttpStatusCode +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + + +internal class UpgradePersonalToTeamApiV7Test : ApiTest() { + + @Test + fun whenCallingUpgradePersonalToTeam_thenTheRequestShouldBeConfiguredOK() = runTest { + val networkClient = mockAuthenticatedNetworkClient( + SUCCESS_RESPONSE, + statusCode = HttpStatusCode.OK, + assertion = { + assertPost() + assertPathEqual("upgrade-personal-to-team") + } + ) + val upgradePersonalToTeamApi = UpgradePersonalToTeamApiV7(networkClient) + upgradePersonalToTeamApi.migrateToTeam(SUCCESS_RESPONSE) + } + + @Test + fun given200Response_whenCallingUpgradePersonalToTeam_thenResponseIsParsedCorrectly() = + runTest { + val networkClient = mockAuthenticatedNetworkClient( + SUCCESS_RESPONSE, + statusCode = HttpStatusCode.OK + ) + val upgradePersonalToTeamApi = UpgradePersonalToTeamApiV7(networkClient) + + val upgradePersonalToTeam = upgradePersonalToTeamApi.migrateToTeam(TEAM_NAME) + assertTrue(upgradePersonalToTeam.isSuccessful()) + } + + @Test + fun givenUserInTeamResponse_whenCallingUpgradePersonalToTeam_thenResponseIsParsedCorrectly() = + runTest { + val networkClient = mockAuthenticatedNetworkClient( + FAILED_USER_IN_TEAM_RESPONSE, + statusCode = HttpStatusCode.Forbidden + ) + val upgradePersonalToTeamApi = UpgradePersonalToTeamApiV7(networkClient) + + val upgradePersonalToTeam = upgradePersonalToTeamApi.migrateToTeam(TEAM_NAME) + assertFalse(upgradePersonalToTeam.isSuccessful()) + } + + @Test + fun givenUserNotFoundResponse_whenCallingUpgradePersonalToTeam_thenResponseIsParsedCorrectly() = + runTest { + val networkClient = mockAuthenticatedNetworkClient( + FAILED_USER_NOT_FOUND_RESPONSE, + statusCode = HttpStatusCode.NotFound + ) + val upgradePersonalToTeamApi = UpgradePersonalToTeamApiV7(networkClient) + + val upgradePersonalToTeam = upgradePersonalToTeamApi.migrateToTeam(TEAM_NAME) + assertFalse(upgradePersonalToTeam.isSuccessful()) + } + + companion object { + val SUCCESS_RESPONSE = + MigrationUserToTeamResponseJson.success.rawJson + val TEAM_NAME = + MigrationUserToTeamResponseJson.success.serializableData.teamName + val FAILED_USER_IN_TEAM_RESPONSE = + MigrationUserToTeamResponseJson.failedUserInTeam.rawJson + val FAILED_USER_NOT_FOUND_RESPONSE = + MigrationUserToTeamResponseJson.failedUserNotFound.rawJson + } +} \ No newline at end of file From 3249de2e91f72d881722802413c0210cb7cc7b28 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Sat, 16 Nov 2024 15:46:49 +0100 Subject: [PATCH 15/22] detekt --- .../kalium/mocks/responses/MigrationUserToTeamResponseJson.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt index 6cef7c21f1f..5d0839732af 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt @@ -65,4 +65,4 @@ object MigrationUserToTeamResponseJson { }.toString() } ) -} \ No newline at end of file +} From 90af7926e7e27f2882b36978af916e4ec553b13d Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Mon, 18 Nov 2024 08:03:44 +0100 Subject: [PATCH 16/22] revert code formatting --- .../kalium/logic/data/user/UserRepository.kt | 270 +++++++----------- 1 file changed, 97 insertions(+), 173 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt index e58a1801807..eea0a3d5998 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt @@ -105,12 +105,7 @@ interface UserRepository { suspend fun fetchUsersIfUnknownByIds(ids: Set): Either suspend fun observeSelfUser(): Flow suspend fun observeSelfUserWithTeam(): Flow> - suspend fun updateSelfUser( - newName: String? = null, - newAccent: Int? = null, - newAssetId: String? = null - ): Either - + suspend fun updateSelfUser(newName: String? = null, newAccent: Int? = null, newAssetId: String? = null): Either suspend fun getSelfUser(): SelfUser? suspend fun observeAllKnownUsers(): Flow>> suspend fun getKnownUser(userId: UserId): Flow @@ -158,20 +153,11 @@ interface UserRepository { suspend fun updateSupportedProtocols(protocols: Set): Either - suspend fun updateActiveOneOnOneConversation( - userId: UserId, - conversationId: ConversationId - ): Either + suspend fun updateActiveOneOnOneConversation(userId: UserId, conversationId: ConversationId): Either - suspend fun updateActiveOneOnOneConversationIfNotSet( - userId: UserId, - conversationId: ConversationId - ): Either + suspend fun updateActiveOneOnOneConversationIfNotSet(userId: UserId, conversationId: ConversationId): Either - suspend fun isAtLeastOneUserATeamMember( - userId: List, - teamId: TeamId - ): Either + suspend fun isAtLeastOneUserATeamMember(userId: List, teamId: TeamId): Either suspend fun insertOrIgnoreIncompleteUsers(userIds: List): Either @@ -212,48 +198,36 @@ internal class UserDataSource internal constructor( */ private val userDetailsRefreshInstantCache = ConcurrentMutableMap() - override suspend fun fetchSelfUser(): Either = - wrapApiRequest { selfApi.getSelfInfo() } - .flatMap { selfUserDTO -> - selfUserDTO.teamId.let { selfUserTeamId -> - if (selfUserTeamId.isNullOrEmpty()) Either.Right(null) - else wrapApiRequest { teamsApi.getTeamMember(selfUserTeamId, selfUserId.value) } - }.map { selfUserDTO to it } - } - .flatMap { (userDTO, teamMemberDTO) -> - if (userDTO.deleted == true) { - Either.Left(SelfUserDeleted) - } else { - updateSelfUserProviderAccountInfo(userDTO) - .map { - userMapper.fromSelfUserDtoToUserEntity( - userDTO = userDTO, - connectionState = ConnectionEntity.State.ACCEPTED, - userTypeEntity = userTypeEntityMapper.teamRoleCodeToUserType( - teamMemberDTO?.permissions?.own - ) - ) - } - .flatMap { userEntity -> - wrapStorageRequest { userDAO.upsertUser(userEntity) } - .flatMap { - wrapStorageRequest { - metadataDAO.insertValue( - Json.encodeToString(userEntity.id), - SELF_USER_ID_KEY - ) - } - } - } - } + override suspend fun fetchSelfUser(): Either = wrapApiRequest { selfApi.getSelfInfo() } + .flatMap { selfUserDTO -> + selfUserDTO.teamId.let { selfUserTeamId -> + if (selfUserTeamId.isNullOrEmpty()) Either.Right(null) + else wrapApiRequest { teamsApi.getTeamMember(selfUserTeamId, selfUserId.value) } + }.map { selfUserDTO to it } + } + .flatMap { (userDTO, teamMemberDTO) -> + if (userDTO.deleted == true) { + Either.Left(SelfUserDeleted) + } else { + updateSelfUserProviderAccountInfo(userDTO) + .map { + userMapper.fromSelfUserDtoToUserEntity( + userDTO = userDTO, + connectionState = ConnectionEntity.State.ACCEPTED, + userTypeEntity = userTypeEntityMapper.teamRoleCodeToUserType(teamMemberDTO?.permissions?.own) + ) + } + .flatMap { userEntity -> + wrapStorageRequest { userDAO.upsertUser(userEntity) } + .flatMap { + wrapStorageRequest { metadataDAO.insertValue(Json.encodeToString(userEntity.id), SELF_USER_ID_KEY) } + } + } } + } private suspend fun updateSelfUserProviderAccountInfo(userDTO: SelfUserDTO): Either = - sessionRepository.updateSsoIdAndScimInfo( - userDTO.id.toModel(), - idMapper.toSsoId(userDTO.ssoID), - userDTO.managedByDTO - ) + sessionRepository.updateSsoIdAndScimInfo(userDTO.id.toModel(), idMapper.toSsoId(userDTO.ssoID), userDTO.managedByDTO) override suspend fun getKnownUser(userId: UserId): Flow = userDAO.observeUserDetailsByQualifiedID(qualifiedID = userId.toDao()) @@ -278,8 +252,7 @@ internal class UserDataSource internal constructor( */ private suspend fun refreshUserDetailsIfNeeded(userId: UserId): Either { val now = DateTimeUtil.currentInstant() - val wasFetchedRecently = - userDetailsRefreshInstantCache[userId]?.let { now < it + USER_DETAILS_MAX_AGE } ?: false + val wasFetchedRecently = userDetailsRefreshInstantCache[userId]?.let { now < it + USER_DETAILS_MAX_AGE } ?: false return if (!wasFetchedRecently) { when (userId) { selfUserId -> fetchSelfUser() @@ -361,9 +334,7 @@ internal class UserDataSource internal constructor( private suspend fun fetchTeamMembersByIds(userProfileList: List): Either> { val selfUserDomain = selfUserId.domain val selfUserTeamId = selfTeamIdProvider().getOrNull() - val teamMemberIds = - userProfileList.filter { it.isTeamMember(selfUserTeamId?.value, selfUserDomain) } - .map { it.id.value } + val teamMemberIds = userProfileList.filter { it.isTeamMember(selfUserTeamId?.value, selfUserDomain) }.map { it.id.value } return if (selfUserTeamId == null || teamMemberIds.isEmpty()) Either.Right(emptyList()) else teamMemberIds .chunked(BATCH_SIZE) @@ -378,10 +349,9 @@ internal class UserDataSource internal constructor( } } - private suspend fun persistIncompleteUsers(usersFailed: List) = - wrapStorageRequest { - userDAO.insertOrIgnoreUsers(usersFailed.map { userMapper.fromFailedUserToEntity(it) }) - } + private suspend fun persistIncompleteUsers(usersFailed: List) = wrapStorageRequest { + userDAO.insertOrIgnoreUsers(usersFailed.map { userMapper.fromFailedUserToEntity(it) }) + } private suspend fun persistUsers( listUserProfileDTO: List, @@ -417,10 +387,7 @@ internal class UserDataSource internal constructor( } return listUserProfileDTO .map { - legalHoldHandler.handleUserFetch( - it.id.toModel(), - it.legalHoldStatus == LegalHoldStatusDTO.ENABLED - ) + legalHoldHandler.handleUserFetch(it.id.toModel(), it.legalHoldStatus == LegalHoldStatusDTO.ENABLED) } .foldToEitherWhileRight(Unit) { value, _ -> value } .flatMap { @@ -436,17 +403,16 @@ internal class UserDataSource internal constructor( } } - override suspend fun fetchUsersIfUnknownByIds(ids: Set): Either = - wrapStorageRequest { - val qualifiedIDList = ids.map { it.toDao() } - val knownUsers = userDAO.getUsersDetailsByQualifiedIDList(ids.map { it.toDao() }) - // TODO we should differentiate users with incomplete data not by checking if name isNullOrBlank - // TODO but add separate property (when federated backend is down) - qualifiedIDList.filterNot { knownUsers.any { userEntity -> userEntity.id == it && !userEntity.name.isNullOrBlank() } } - }.flatMap { missingIds -> - if (missingIds.isEmpty()) Either.Right(Unit) - else fetchUsersByIds(missingIds.map { it.toModel() }.toSet()) - } + override suspend fun fetchUsersIfUnknownByIds(ids: Set): Either = wrapStorageRequest { + val qualifiedIDList = ids.map { it.toDao() } + val knownUsers = userDAO.getUsersDetailsByQualifiedIDList(ids.map { it.toDao() }) + // TODO we should differentiate users with incomplete data not by checking if name isNullOrBlank + // TODO but add separate property (when federated backend is down) + qualifiedIDList.filterNot { knownUsers.any { userEntity -> userEntity.id == it && !userEntity.name.isNullOrBlank() } } + }.flatMap { missingIds -> + if (missingIds.isEmpty()) Either.Right(Unit) + else fetchUsersByIds(missingIds.map { it.toModel() }.toSet()) + } @OptIn(ExperimentalCoroutinesApi::class) override suspend fun observeSelfUser(): Flow { @@ -474,19 +440,14 @@ internal class UserDataSource internal constructor( @OptIn(ExperimentalCoroutinesApi::class) override suspend fun observeSelfUserWithTeam(): Flow> { - return metadataDAO.valueByKeyFlow(SELF_USER_ID_KEY).filterNotNull() - .flatMapMerge { encodedValue -> - val selfUserID: QualifiedIDEntity = Json.decodeFromString(encodedValue) - userDAO.getUserDetailsWithTeamByQualifiedID(selfUserID) - .filterNotNull() - .map { (user, team) -> - userMapper.fromUserDetailsEntityToSelfUser(user) to team?.let { - teamMapper.fromDaoModelToTeam( - it - ) - } - } - } + return metadataDAO.valueByKeyFlow(SELF_USER_ID_KEY).filterNotNull().flatMapMerge { encodedValue -> + val selfUserID: QualifiedIDEntity = Json.decodeFromString(encodedValue) + userDAO.getUserDetailsWithTeamByQualifiedID(selfUserID) + .filterNotNull() + .map { (user, team) -> + userMapper.fromUserDetailsEntityToSelfUser(user) to team?.let { teamMapper.fromDaoModelToTeam(it) } + } + } } @Deprecated( @@ -494,11 +455,7 @@ internal class UserDataSource internal constructor( replaceWith = ReplaceWith("eg: updateSelfDisplayName(displayName: String)") ) // FIXME(refactor): create a dedicated function to update avatar, as this is the only usage of this function. - override suspend fun updateSelfUser( - newName: String?, - newAccent: Int?, - newAssetId: String? - ): Either { + override suspend fun updateSelfUser(newName: String?, newAccent: Int?, newAssetId: String?): Either { val updateRequest = userMapper.fromModelToUpdateApiModel(newName, newAccent, newAssetId) return wrapApiRequest { selfApi.updateSelf(updateRequest) } .map { userMapper.fromUpdateRequestToPartialUserEntity(updateRequest, selfUserId) } @@ -532,12 +489,11 @@ internal class UserDataSource internal constructor( } } - override suspend fun getUsersMinimizedByQualifiedIDs(userIds: List) = - wrapStorageRequest { - userDAO.getUsersMinimizedByQualifiedIDs( - qualifiedIDs = userIds.map { it.toDao() } - ).map(userMapper::fromUserEntityToOtherUserMinimized) - } + override suspend fun getUsersMinimizedByQualifiedIDs(userIds: List) = wrapStorageRequest { + userDAO.getUsersMinimizedByQualifiedIDs( + qualifiedIDs = userIds.map { it.toDao() } + ).map(userMapper::fromUserEntityToOtherUserMinimized) + } override suspend fun observeUser(userId: UserId): Flow = userDAO.observeUserDetailsByQualifiedID(qualifiedID = userId.toDao()) @@ -556,38 +512,21 @@ internal class UserDataSource internal constructor( } } - override suspend fun updateOtherUserAvailabilityStatus( - userId: UserId, - status: UserAvailabilityStatus - ) { - userDAO.updateUserAvailabilityStatus( - userId.toDao(), - availabilityStatusMapper.fromModelAvailabilityStatusToDao(status) - ) + override suspend fun updateOtherUserAvailabilityStatus(userId: UserId, status: UserAvailabilityStatus) { + userDAO.updateUserAvailabilityStatus(userId.toDao(), availabilityStatusMapper.fromModelAvailabilityStatusToDao(status)) } override suspend fun updateSupportedProtocols(protocols: Set): Either { return wrapApiRequest { selfApi.updateSupportedProtocols(protocols.map { it.toApi() }) } .flatMap { wrapStorageRequest { - userDAO.updateUserSupportedProtocols( - selfUserId.toDao(), - protocols.map { it.toDao() }.toSet() - ) + userDAO.updateUserSupportedProtocols(selfUserId.toDao(), protocols.map { it.toDao() }.toSet()) } } } - override suspend fun updateActiveOneOnOneConversation( - userId: UserId, - conversationId: ConversationId - ): Either = - wrapStorageRequest { - userDAO.updateActiveOneOnOneConversation( - userId.toDao(), - conversationId.toDao() - ) - } + override suspend fun updateActiveOneOnOneConversation(userId: UserId, conversationId: ConversationId): Either = + wrapStorageRequest { userDAO.updateActiveOneOnOneConversation(userId.toDao(), conversationId.toDao()) } override suspend fun updateActiveOneOnOneConversationIfNotSet( userId: UserId, @@ -596,15 +535,13 @@ internal class UserDataSource internal constructor( userDAO.updateActiveOneOnOneConversationIfNotSet(userId.toDao(), conversationId.toDao()) } - override suspend fun isAtLeastOneUserATeamMember(userId: List, teamId: TeamId) = - wrapStorageRequest { - userDAO.isAtLeastOneUserATeamMember(userId.map { it.toDao() }, teamId.value) - } + override suspend fun isAtLeastOneUserATeamMember(userId: List, teamId: TeamId) = wrapStorageRequest { + userDAO.isAtLeastOneUserATeamMember(userId.map { it.toDao() }, teamId.value) + } - override suspend fun insertOrIgnoreIncompleteUsers(userIds: List) = - wrapStorageRequest { - userDAO.insertOrIgnoreIncompleteUsers(userIds.map { it.toDao() }) - } + override suspend fun insertOrIgnoreIncompleteUsers(userIds: List) = wrapStorageRequest { + userDAO.insertOrIgnoreIncompleteUsers(userIds.map { it.toDao() }) + } override suspend fun fetchUsersLegalHoldConsent(userIds: Set): Either = fetchUsersByIdsReturningListUsersDTO(userIds).map { listUsersDTO -> @@ -612,13 +549,7 @@ internal class UserDataSource internal constructor( .partition { it.legalHoldStatus != LegalHoldStatusDTO.NO_CONSENT } .let { (usersWithConsent, usersWithoutConsent) -> ListUsersLegalHoldConsent( - usersWithConsent = usersWithConsent.map { - it.id.toModel() to it.teamId?.let { - TeamId( - it - ) - } - }, + usersWithConsent = usersWithConsent.map { it.id.toModel() to it.teamId?.let { TeamId(it) } }, usersWithoutConsent = usersWithoutConsent.map { it.id.toModel() }, usersFailed = listUsersDTO.usersFailed.map { it.toModel() } ) @@ -640,9 +571,7 @@ internal class UserDataSource internal constructor( override suspend fun getAllRecipients(): Either, List>> = selfTeamIdProvider().flatMap { teamId -> val teamMateIds = teamId?.value?.let { selfTeamId -> - wrapStorageRequest { - userDAO.getAllUsersDetailsByTeam(selfTeamId).map { it.id.toModel() } - } + wrapStorageRequest { userDAO.getAllUsersDetailsByTeam(selfTeamId).map { it.id.toModel() } } }?.getOrNull() ?: listOf() wrapStorageRequest { @@ -658,14 +587,13 @@ internal class UserDataSource internal constructor( } } - override suspend fun updateUserFromEvent(event: Event.User.Update): Either = - wrapStorageRequest { - userDAO.updateUser(userMapper.fromUserUpdateEventToPartialUserEntity(event)) - }.onFailure { - Either.Left(StorageFailure.DataNotFound) - }.onSuccess { - Either.Right(Unit) - } + override suspend fun updateUserFromEvent(event: Event.User.Update): Either = wrapStorageRequest { + userDAO.updateUser(userMapper.fromUserUpdateEventToPartialUserEntity(event)) + }.onFailure { + Either.Left(StorageFailure.DataNotFound) + }.onSuccess { + Either.Right(Unit) + } override suspend fun markUserAsDeletedAndRemoveFromGroupConversations( userId: UserId @@ -674,10 +602,9 @@ internal class UserDataSource internal constructor( userDAO.markUserAsDeletedAndRemoveFromGroupConv(userId.toDao()) }.map { it.map(ConversationIDEntity::toModel) } - override suspend fun markAsDeleted(userId: List): Either = - wrapStorageRequest { - userDAO.markAsDeleted(userId.map { it.toDao() }) - } + override suspend fun markAsDeleted(userId: List): Either = wrapStorageRequest { + userDAO.markAsDeleted(userId.map { it.toDao() }) + } override suspend fun defederateUser(userId: UserId): Either { return wrapStorageRequest { @@ -697,14 +624,13 @@ internal class UserDataSource internal constructor( ) } - override suspend fun syncUsersWithoutMetadata(): Either = - wrapStorageRequest { - userDAO.getUsersDetailsWithoutMetadata() - }.flatMap { usersWithoutMetadata -> - kaliumLogger.d("Numbers of users to refresh: ${usersWithoutMetadata.size}") - val userIds = usersWithoutMetadata.map { it.id.toModel() }.toSet() - fetchUsersByIds(userIds) - } + override suspend fun syncUsersWithoutMetadata(): Either = wrapStorageRequest { + userDAO.getUsersDetailsWithoutMetadata() + }.flatMap { usersWithoutMetadata -> + kaliumLogger.d("Numbers of users to refresh: ${usersWithoutMetadata.size}") + val userIds = usersWithoutMetadata.map { it.id.toModel() }.toSet() + fetchUsersByIds(userIds) + } override suspend fun removeUserBrokenAsset(qualifiedID: QualifiedID) = wrapStorageRequest { userDAO.removeUserAsset(qualifiedID.toDao()) @@ -717,15 +643,13 @@ internal class UserDataSource internal constructor( } } - override suspend fun getOneOnOnConversationId(userId: QualifiedID): Either = - wrapStorageRequest { - userDAO.getOneOnOnConversationId(userId.toDao())?.toModel() - } + override suspend fun getOneOnOnConversationId(userId: QualifiedID): Either = wrapStorageRequest { + userDAO.getOneOnOnConversationId(userId.toDao())?.toModel() + } - override suspend fun getNameAndHandle(userId: UserId): Either = - wrapStorageRequest { - userDAO.getNameAndHandle(userId.toDao()) - }.map { NameAndHandle.fromEntity(it) } + override suspend fun getNameAndHandle(userId: UserId): Either = wrapStorageRequest { + userDAO.getNameAndHandle(userId.toDao()) + }.map { NameAndHandle.fromEntity(it) } override suspend fun migrateUserToTeam(teamName: String): Either { return wrapApiRequest { upgradePersonalToTeamApi.migrateToTeam(teamName) } From efffa6e109d54e08399e41658f00242f6f24ff74 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Mon, 18 Nov 2024 08:09:54 +0100 Subject: [PATCH 17/22] revert code formatting --- .../api/v0/authenticated/ConversationApiV0.kt | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) 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 593ab859487..145a833620f 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 @@ -82,12 +82,7 @@ internal open class ConversationApiV0 internal constructor( ): NetworkResponse = wrapKaliumResponse { httpClient.post("$PATH_CONVERSATIONS/$PATH_LIST_IDS") { - setBody( - PaginationRequest( - pagingState = pagingState, - size = MAX_CONVERSATION_DETAILS_COUNT - ) - ) + setBody(PaginationRequest(pagingState = pagingState, size = MAX_CONVERSATION_DETAILS_COUNT)) } } @@ -163,11 +158,7 @@ internal open class ConversationApiV0 internal constructor( HttpStatusCode.OK -> wrapKaliumResponse { response } .mapSuccess { ConversationMemberRemovedResponse.Changed(it) } - HttpStatusCode.NoContent -> NetworkResponse.Success( - ConversationMemberRemovedResponse.Unchanged, - response - ) - + HttpStatusCode.NoContent -> NetworkResponse.Success(ConversationMemberRemovedResponse.Unchanged, response) else -> wrapKaliumResponse { response } } } @@ -194,11 +185,7 @@ internal open class ConversationApiV0 internal constructor( setBody(updateConversationAccessRequest) }.let { httpResponse -> when (httpResponse.status) { - HttpStatusCode.NoContent -> NetworkResponse.Success( - UpdateConversationAccessResponse.AccessUnchanged, - httpResponse - ) - + HttpStatusCode.NoContent -> NetworkResponse.Success(UpdateConversationAccessResponse.AccessUnchanged, httpResponse) else -> wrapKaliumResponse { httpResponse } .mapSuccess { UpdateConversationAccessResponse.AccessUpdated(it) @@ -234,11 +221,7 @@ internal open class ConversationApiV0 internal constructor( HttpStatusCode.OK -> wrapKaliumResponse { response } .mapSuccess { ConversationRenameResponse.Changed(it) } - HttpStatusCode.NoContent -> NetworkResponse.Success( - ConversationRenameResponse.Unchanged, - response - ) - + HttpStatusCode.NoContent -> NetworkResponse.Success(ConversationRenameResponse.Unchanged, response) else -> wrapKaliumResponse { response } } } @@ -269,10 +252,7 @@ internal open class ConversationApiV0 internal constructor( } } - override suspend fun fetchLimitedInformationViaCode( - code: String, - key: String - ): NetworkResponse = + override suspend fun fetchLimitedInformationViaCode(code: String, key: String): NetworkResponse = wrapKaliumResponse { httpClient.get("$PATH_CONVERSATIONS/$PATH_JOIN") { parameter(QUERY_KEY_CODE, code) @@ -381,10 +361,9 @@ internal open class ConversationApiV0 internal constructor( } } - override suspend fun revokeGuestRoomLink(conversationId: ConversationId): NetworkResponse = - wrapKaliumResponse { - httpClient.delete("$PATH_CONVERSATIONS/${conversationId.value}/$PATH_CODE") - } + override suspend fun revokeGuestRoomLink(conversationId: ConversationId): NetworkResponse = wrapKaliumResponse { + httpClient.delete("$PATH_CONVERSATIONS/${conversationId.value}/$PATH_CODE") + } override suspend fun updateMessageTimer( conversationId: ConversationId, @@ -405,7 +384,6 @@ internal open class ConversationApiV0 internal constructor( setBody(typingIndicatorMode) } } - override suspend fun updateProtocol( conversationId: ConversationId, protocol: ConvProtocol From b2e0cf4fcd11e237b80824607c74ba9283de28aa Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Mon, 18 Nov 2024 09:06:18 +0100 Subject: [PATCH 18/22] test fix --- .../kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt index c401bd3be6e..3af8638fdc9 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt @@ -807,6 +807,7 @@ class UserRepositoryTest { fun givenApiRequestSucceeds_whenPersonalUserUpgradesToTeam_thenShouldSucceed() = runTest { // given val (arrangement, userRepository) = Arrangement() + .withRemoteGetSelfReturningDeletedUser() .withMigrateUserToTeamSuccess() .arrange() // when From 2db6c6e785ca3703d77480c566669690d69ab722 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek <76782439+damian-kaczmarek@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:42:41 +0100 Subject: [PATCH 19/22] wrong extended class Co-authored-by: Oussama Hassine --- .../network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt index 58801259fcd..e1c1b5e5813 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt @@ -23,4 +23,4 @@ import com.wire.kalium.network.api.v2.authenticated.UpgradePersonalToTeamApiV2 internal open class UpgradePersonalToTeamApiV4 internal constructor( authenticatedNetworkClient: AuthenticatedNetworkClient, -) : UpgradePersonalToTeamApiV2(authenticatedNetworkClient) +) : UpgradePersonalToTeamApiV3(authenticatedNetworkClient) From 57110225f9cf0145866fcec806db5af5df490cc6 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Tue, 19 Nov 2024 15:04:25 +0100 Subject: [PATCH 20/22] CR changes --- .../com/wire/kalium/logic/data/user/CreateUserTeam.kt | 3 +++ .../com/wire/kalium/logic/data/user/UserRepository.kt | 10 +++++----- .../user/migration/MigrateFromPersonalToTeamUseCase.kt | 8 +++----- .../wire/kalium/logic/data/user/UserRepositoryTest.kt | 2 +- .../migration/MigrateFromPersonalToTeamUseCaseTest.kt | 8 +++----- .../mocks/responses/MigrationUserToTeamResponseJson.kt | 2 +- .../api/authenticated/{ => user}/CreateUserTeamDTO.kt | 2 +- .../api/base/authenticated/UpgradePersonalToTeamApi.kt | 2 +- .../api/v0/authenticated/UpgradePersonalToTeamApiV0.kt | 2 +- .../api/v7/authenticated/UpgradePersonalToTeamApiV7.kt | 2 +- 10 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt rename network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/{ => user}/CreateUserTeamDTO.kt (94%) diff --git a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt new file mode 100644 index 00000000000..907413be576 --- /dev/null +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt @@ -0,0 +1,3 @@ +package com.wire.kalium.logic.data.user + +data class CreateUserTeam(val teamName: String) \ No newline at end of file diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt index eea0a3d5998..35360a5aaa8 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt @@ -58,7 +58,6 @@ import com.wire.kalium.logic.kaliumLogger import com.wire.kalium.logic.sync.receiver.handler.legalhold.LegalHoldHandler import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.logic.wrapStorageRequest -import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberIdList import com.wire.kalium.network.api.authenticated.userDetails.ListUserRequest @@ -166,7 +165,7 @@ interface UserRepository { suspend fun getOneOnOnConversationId(userId: QualifiedID): Either suspend fun getUsersMinimizedByQualifiedIDs(userIds: List): Either> suspend fun getNameAndHandle(userId: UserId): Either - suspend fun migrateUserToTeam(teamName: String): Either + suspend fun migrateUserToTeam(teamName: String): Either } @Suppress("LongParameterList", "TooManyFunctions") @@ -651,12 +650,13 @@ internal class UserDataSource internal constructor( userDAO.getNameAndHandle(userId.toDao()) }.map { NameAndHandle.fromEntity(it) } - override suspend fun migrateUserToTeam(teamName: String): Either { - return wrapApiRequest { upgradePersonalToTeamApi.migrateToTeam(teamName) } + override suspend fun migrateUserToTeam(teamName: String): Either { + return wrapApiRequest { upgradePersonalToTeamApi.migrateToTeam(teamName) }.map { dto -> + CreateUserTeam(dto.teamName) + } .onSuccess { kaliumLogger.d("Migrated user to team") fetchSelfUser() - // TODO Invalidate team id in memory so UserSessionScope.selfTeamId got updated data WPB-12187 } .onFailure { failure -> kaliumLogger.e("Failed to migrate user to team: $failure") diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt index 60ea0987ac5..8d3e841940e 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt @@ -30,7 +30,7 @@ interface MigrateFromPersonalToTeamUseCase { } sealed class MigrateFromPersonalToTeamResult { - data class Success(val teamId: String, val teamName: String) : MigrateFromPersonalToTeamResult() + data class Success(val teamName: String) : MigrateFromPersonalToTeamResult() data class Error(val failure: CoreFailure) : MigrateFromPersonalToTeamResult() } @@ -44,10 +44,8 @@ internal class MigrateFromPersonalToTeamUseCaseImpl internal constructor( .fold( { error -> return MigrateFromPersonalToTeamResult.Error(error) }, { success -> - MigrateFromPersonalToTeamResult.Success( - teamId = success.teamId, - teamName = success.teamName, - ) + // TODO Invalidate team id in memory so UserSessionScope.selfTeamId got updated data WPB-12187 + MigrateFromPersonalToTeamResult.Success(teamName = success.teamName) } ) } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt index 3af8638fdc9..eb7cf4dab64 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserRepositoryTest.kt @@ -44,9 +44,9 @@ import com.wire.kalium.logic.test_util.TestNetworkException.generic import com.wire.kalium.logic.test_util.TestNetworkResponseError import com.wire.kalium.logic.util.shouldFail import com.wire.kalium.logic.util.shouldSucceed -import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberDTO import com.wire.kalium.network.api.authenticated.teams.TeamMemberListNonPaginated +import com.wire.kalium.network.api.authenticated.user.CreateUserTeamDTO import com.wire.kalium.network.api.authenticated.userDetails.ListUserRequest import com.wire.kalium.network.api.authenticated.userDetails.ListUsersDTO import com.wire.kalium.network.api.authenticated.userDetails.QualifiedUserIdListRequest diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt index ba775a8ed21..425af5a8d1e 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt @@ -20,9 +20,9 @@ package com.wire.kalium.logic.feature.user.migration import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.NetworkFailure +import com.wire.kalium.logic.data.user.CreateUserTeam import com.wire.kalium.logic.data.user.UserRepository import com.wire.kalium.logic.functional.Either -import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO import com.wire.kalium.network.api.model.ErrorResponse import com.wire.kalium.network.exceptions.KaliumException import io.ktor.http.HttpStatusCode @@ -101,9 +101,7 @@ class MigrateFromPersonalToTeamUseCaseTest { suspend fun withSuccessRepository() = apply { coEvery { userRepository.migrateUserToTeam(any()) }.returns( Either.Right( - CreateUserTeamDTO( - "teamId", "teamName" - ) + CreateUserTeam("teamName") ) ) } @@ -140,7 +138,7 @@ class MigrateFromPersonalToTeamUseCaseTest { ) } - suspend fun withRepositoryReturning(result: Either) = + suspend fun withRepositoryReturning(result: Either) = apply { coEvery { userRepository.migrateUserToTeam(any()) }.returns(result) } diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt index 5d0839732af..69fa04e4399 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/MigrationUserToTeamResponseJson.kt @@ -17,7 +17,7 @@ */ package com.wire.kalium.mocks.responses -import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.authenticated.user.CreateUserTeamDTO import com.wire.kalium.network.api.model.ErrorResponse import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/CreateUserTeamDTO.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/user/CreateUserTeamDTO.kt similarity index 94% rename from network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/CreateUserTeamDTO.kt rename to network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/user/CreateUserTeamDTO.kt index 7c1f1be24ee..9a0cf6cad12 100644 --- a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/CreateUserTeamDTO.kt +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/user/CreateUserTeamDTO.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ -package com.wire.kalium.network.api.authenticated +package com.wire.kalium.network.api.authenticated.user import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt index a0b5d910909..611e6efe256 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt @@ -17,7 +17,7 @@ */ package com.wire.kalium.network.api.base.authenticated -import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.authenticated.user.CreateUserTeamDTO import com.wire.kalium.network.utils.NetworkResponse interface UpgradePersonalToTeamApi : BaseApi { diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt index 8585dfb71cf..93a28c77bfe 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt @@ -19,7 +19,7 @@ package com.wire.kalium.network.api.v0.authenticated import com.wire.kalium.network.AuthenticatedNetworkClient -import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.authenticated.user.CreateUserTeamDTO import com.wire.kalium.network.api.base.authenticated.UpgradePersonalToTeamApi import com.wire.kalium.network.utils.NetworkResponse diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt index dbc382e06af..b1c07ff5418 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt @@ -19,7 +19,7 @@ package com.wire.kalium.network.api.v7.authenticated import com.wire.kalium.network.AuthenticatedNetworkClient -import com.wire.kalium.network.api.authenticated.CreateUserTeamDTO +import com.wire.kalium.network.api.authenticated.user.CreateUserTeamDTO import com.wire.kalium.network.api.unauthenticated.register.NewBindingTeamDTO import com.wire.kalium.network.api.v6.authenticated.UpgradePersonalToTeamApiV6 import com.wire.kalium.network.utils.NetworkResponse From 01da6acba07516918f143a050b0e4e3b0ce14695 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Tue, 19 Nov 2024 15:51:44 +0100 Subject: [PATCH 21/22] CR --- .../network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt index e1c1b5e5813..6bff4efb352 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt @@ -19,7 +19,7 @@ package com.wire.kalium.network.api.v4.authenticated import com.wire.kalium.network.AuthenticatedNetworkClient -import com.wire.kalium.network.api.v2.authenticated.UpgradePersonalToTeamApiV2 +import com.wire.kalium.network.api.v3.authenticated.UpgradePersonalToTeamApiV3 internal open class UpgradePersonalToTeamApiV4 internal constructor( authenticatedNetworkClient: AuthenticatedNetworkClient, From e8b74771abc563104f041ea240f119bbf3cd2c08 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Wed, 20 Nov 2024 08:59:25 +0100 Subject: [PATCH 22/22] detekt --- .../kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt index 907413be576..f5e78793d5d 100644 --- a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/user/CreateUserTeam.kt @@ -1,3 +1,3 @@ package com.wire.kalium.logic.data.user -data class CreateUserTeam(val teamName: String) \ No newline at end of file +data class CreateUserTeam(val teamName: String)