From dbe12d1456898e16025e316736340d01c7bc88ff Mon Sep 17 00:00:00 2001 From: Sven Jost Date: Thu, 16 May 2024 18:19:08 +0200 Subject: [PATCH 1/2] feat: Testservice can create MLS group conversations (WPB-9185) --- .../api/v1/ConversationResources.kt | 25 ++++++++++++++++ .../managed/ConversationRepository.kt | 30 +++++++++++++++++++ .../models/NewConversationRequest.kt | 23 ++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 testservice/src/main/kotlin/com/wire/kalium/testservice/models/NewConversationRequest.kt diff --git a/testservice/src/main/kotlin/com/wire/kalium/testservice/api/v1/ConversationResources.kt b/testservice/src/main/kotlin/com/wire/kalium/testservice/api/v1/ConversationResources.kt index 6778f988478..573aa554469 100644 --- a/testservice/src/main/kotlin/com/wire/kalium/testservice/api/v1/ConversationResources.kt +++ b/testservice/src/main/kotlin/com/wire/kalium/testservice/api/v1/ConversationResources.kt @@ -30,6 +30,7 @@ import com.wire.kalium.testservice.models.ClearConversationRequest import com.wire.kalium.testservice.models.DeleteMessageRequest import com.wire.kalium.testservice.models.GetMessageReceiptsRequest import com.wire.kalium.testservice.models.GetMessagesRequest +import com.wire.kalium.testservice.models.NewConversationRequest import com.wire.kalium.testservice.models.SendButtonActionConfirmationRequest import com.wire.kalium.testservice.models.SendButtonActionRequest import com.wire.kalium.testservice.models.SendConfirmationReadRequest @@ -480,4 +481,28 @@ class ConversationResources(private val instanceService: InstanceService) { } } } + + @POST + @Path("/instance/{id}/conversation") + @Operation(summary = "Create a new conversation") + @Consumes(MediaType.APPLICATION_JSON) + fun createConversation(@PathParam("id") id: String, @Valid request: NewConversationRequest): Response { + val instance = instanceService.getInstanceOrThrow(id) + return with(request) { + val users = userIds.map { + if (it.contains("@")) { + UserId(it.split("@")[0], it.split("@")[1]) + } else { + UserId(it, "staging.zinfra.io") + } + } + runBlocking { + ConversationRepository.createConversation( + instance, + name, + users + ) + } + } + } } diff --git a/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt b/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt index 3920d0c48b8..c5a2aeb6d45 100644 --- a/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt +++ b/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt @@ -20,6 +20,7 @@ package com.wire.kalium.testservice.managed import com.wire.kalium.logic.StorageFailure import com.wire.kalium.logic.data.conversation.Conversation +import com.wire.kalium.logic.data.conversation.ConversationOptions import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.message.Message import com.wire.kalium.logic.data.message.mention.MessageMention @@ -31,6 +32,7 @@ import com.wire.kalium.logic.feature.debug.SendBrokenAssetMessageResult import com.wire.kalium.logic.data.message.SelfDeletionTimer import com.wire.kalium.logic.data.message.receipt.DetailedReceipt import com.wire.kalium.logic.data.user.UserId +import com.wire.kalium.logic.feature.conversation.CreateGroupConversationUseCase import com.wire.kalium.logic.feature.message.composite.SendButtonActionConfirmationMessageUseCase import com.wire.kalium.logic.feature.message.composite.SendButtonActionMessageUseCase import com.wire.kalium.logic.feature.session.CurrentSessionResult @@ -105,6 +107,34 @@ sealed class ConversationRepository { } } + suspend fun createConversation( + instance: Instance, + name: String, + userIds: List + ): Response = instance.coreLogic.globalScope { + when (val session = session.currentSession()) { + is CurrentSessionResult.Success -> { + instance.coreLogic.sessionScope(session.accountInfo.userId) { + log.info("Instance ${instance.instanceId}: Create group conversation with ...") + when (val result = conversations.createGroupConversation(name, listOf(), ConversationOptions())) { + is CreateGroupConversationUseCase.Result.Success -> { + Response.status(Response.Status.OK).build() + } + + else -> { + Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Instance ${instance.instanceId}: $result").build() + } + } + } + } + + is CurrentSessionResult.Failure -> { + Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Session failure").build() + } + } + } + suspend fun sendConfirmation(instance: Instance, conversationId: ConversationId, type: ReceiptType, messageId: String): Response = instance.coreLogic.globalScope { when (val session = session.currentSession()) { diff --git a/testservice/src/main/kotlin/com/wire/kalium/testservice/models/NewConversationRequest.kt b/testservice/src/main/kotlin/com/wire/kalium/testservice/models/NewConversationRequest.kt new file mode 100644 index 00000000000..7e4e2c2a93b --- /dev/null +++ b/testservice/src/main/kotlin/com/wire/kalium/testservice/models/NewConversationRequest.kt @@ -0,0 +1,23 @@ +/* + * 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.testservice.models + +data class NewConversationRequest( + val name: String = "", + val userIds: List = emptyList() +) From 83eeb87f2ea7d4811a4c781af99eead3b4960c7b Mon Sep 17 00:00:00 2001 From: Sven Jost Date: Wed, 29 May 2024 16:57:41 +0200 Subject: [PATCH 2/2] Always use MLS protocol and print future participants --- .../testservice/managed/ConversationRepository.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt b/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt index c5a2aeb6d45..e03ea2a3d7e 100644 --- a/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt +++ b/testservice/src/main/kotlin/com/wire/kalium/testservice/managed/ConversationRepository.kt @@ -115,8 +115,14 @@ sealed class ConversationRepository { when (val session = session.currentSession()) { is CurrentSessionResult.Success -> { instance.coreLogic.sessionScope(session.accountInfo.userId) { - log.info("Instance ${instance.instanceId}: Create group conversation with ...") - when (val result = conversations.createGroupConversation(name, listOf(), ConversationOptions())) { + log.info("Instance ${instance.instanceId}: Create conversation \"$name\" with ${ + userIds.joinToString { user -> user.value + "@" + user.domain } + }") + when (val result = conversations.createGroupConversation( + name, + userIds, + ConversationOptions(protocol = ConversationOptions.Protocol.MLS) + )) { is CreateGroupConversationUseCase.Result.Success -> { Response.status(Response.Status.OK).build() }