15
15
16
16
package com.wire.integrations.jvm.service
17
17
18
- import com.wire.crypto.MLSGroupId
19
- import com.wire.crypto.MLSKeyPackage
20
- import com.wire.crypto.toGroupId
21
18
import com.wire.integrations.jvm.client.BackendClient
22
- import com.wire.integrations.jvm.crypto.CoreCryptoClient
23
19
import com.wire.integrations.jvm.crypto.CryptoClient
24
20
import com.wire.integrations.jvm.exception.WireException
25
21
import com.wire.integrations.jvm.model.AssetResource
@@ -34,27 +30,20 @@ import com.wire.integrations.jvm.model.asset.AssetRetention
34
30
import com.wire.integrations.jvm.model.asset.AssetUploadData
35
31
import com.wire.integrations.jvm.model.http.ApiVersionResponse
36
32
import com.wire.integrations.jvm.model.http.AppDataResponse
37
- import com.wire.integrations.jvm.model.http.conversation.ConversationTeamInfo
38
- import com.wire.integrations.jvm.model.http.conversation.CreateConversationRequest
39
- import com.wire.integrations.jvm.model.http.conversation.KeyPackage
40
- import com.wire.integrations.jvm.model.http.conversation.getRemovalKey
41
33
import com.wire.integrations.jvm.model.http.user.UserResponse
42
34
import com.wire.integrations.jvm.model.protobuf.ProtobufSerializer
43
35
import com.wire.integrations.jvm.persistence.ConversationStorage
44
36
import com.wire.integrations.jvm.persistence.TeamStorage
37
+ import com.wire.integrations.jvm.service.conversation.CreateGroupConversationService
45
38
import com.wire.integrations.jvm.utils.AESDecrypt
46
39
import com.wire.integrations.jvm.utils.AESEncrypt
47
40
import com.wire.integrations.jvm.utils.MAX_DATA_SIZE
48
- import com.wire.integrations.jvm.utils.toHexString
49
- import io.ktor.util.decodeBase64Bytes
50
41
import java.io.ByteArrayInputStream
51
- import java.util.Base64
52
42
import java.util.UUID
53
43
import javax.imageio.ImageIO
54
44
import kotlinx.coroutines.Dispatchers
55
45
import kotlinx.coroutines.runBlocking
56
46
import kotlinx.coroutines.withContext
57
- import org.slf4j.LoggerFactory
58
47
59
48
/* *
60
49
* Allows fetching common data and interacting with each Team instance invited to the Application.
@@ -66,10 +55,9 @@ class WireApplicationManager internal constructor(
66
55
private val conversationStorage : ConversationStorage ,
67
56
private val backendClient : BackendClient ,
68
57
private val cryptoClient : CryptoClient ,
69
- private val mlsFallbackStrategy : MlsFallbackStrategy
58
+ private val mlsFallbackStrategy : MlsFallbackStrategy ,
59
+ private val createGroupConversationService : CreateGroupConversationService
70
60
) {
71
- private val logger = LoggerFactory .getLogger(" WireApplicationManager" )
72
-
73
61
fun getStoredTeams (): List <TeamId > = teamStorage.getAll()
74
62
75
63
fun getStoredConversations (): List <ConversationData > = conversationStorage.getAll()
@@ -375,103 +363,10 @@ class WireApplicationManager internal constructor(
375
363
name : String ,
376
364
teamId : TeamId ,
377
365
userIds : List <QualifiedId >
378
- ): QualifiedId {
379
- val conversationRequest = CreateConversationRequest (
366
+ ): QualifiedId =
367
+ createGroupConversationService.create (
380
368
name = name,
381
- conversationTeamInfo = ConversationTeamInfo (
382
- managed = false ,
383
- teamId = teamId.value.toString()
384
- )
385
- )
386
-
387
- val conversationResponse = backendClient.createGroupConversation(
388
- createConversationRequest = conversationRequest
389
- )
390
-
391
- val mlsGroupId = Base64
392
- .getDecoder()
393
- .decode(conversationResponse.groupId)
394
- .toGroupId()
395
-
396
- val cipherSuiteCode = backendClient
397
- .getApplicationFeatures()
398
- .mlsFeatureResponse
399
- .mlsFeatureConfigResponse
400
- .defaultCipherSuite
401
-
402
- val cipherSuite = CoreCryptoClient .getMlsCipherSuiteName(code = cipherSuiteCode)
403
-
404
- val publicKeys = (conversationResponse.publicKeys ? : backendClient.getPublicKeys())
405
- .getRemovalKey(cipherSuite = cipherSuite)
406
-
407
- createMlsGroupConversation(
408
- publicKeys = publicKeys,
409
- cipherSuiteCode = cipherSuiteCode,
410
- mlsGroupId = mlsGroupId,
369
+ teamId = teamId,
411
370
userIds = userIds
412
371
)
413
-
414
- val conversationId = conversationResponse.id
415
- logger.info(" Conversation created with ID: $conversationId " )
416
- return conversationId
417
- }
418
-
419
- private suspend fun createMlsGroupConversation (
420
- publicKeys : ByteArray? ,
421
- cipherSuiteCode : Int ,
422
- mlsGroupId : MLSGroupId ,
423
- userIds : List <QualifiedId >
424
- ) {
425
- publicKeys?.let { externalSenders ->
426
- cryptoClient.createConversation(
427
- groupId = mlsGroupId,
428
- externalSenders = externalSenders
429
- )
430
-
431
- cryptoClient.commitPendingProposals(mlsGroupId)
432
-
433
- val claimedKeyPackages: List <ByteArray > = claimKeyPackages(
434
- userIds = userIds,
435
- cipherSuiteCode = cipherSuiteCode
436
- )
437
-
438
- if (claimedKeyPackages.isEmpty()) {
439
- cryptoClient.updateKeyingMaterial(mlsGroupId)
440
- } else {
441
- cryptoClient.addMemberToMlsConversation(
442
- mlsGroupId = mlsGroupId,
443
- keyPackages = claimedKeyPackages.map { keyPackage ->
444
- MLSKeyPackage (com.wire.crypto.uniffi.KeyPackage (keyPackage))
445
- }
446
- )
447
- }
448
- }
449
- }
450
-
451
- @Suppress(" TooGenericExceptionCaught" )
452
- private suspend fun claimKeyPackages (
453
- userIds : List <QualifiedId >,
454
- cipherSuiteCode : Int
455
- ): List <ByteArray > {
456
- val claimedKeyPackages = mutableListOf<KeyPackage >()
457
- userIds.forEach { user ->
458
- try {
459
- val result = backendClient.claimKeyPackages(
460
- userDomain = user.domain,
461
- userId = user.id,
462
- cipherSuite = cipherSuiteCode.toHexString()
463
- )
464
-
465
- if (result.keyPackages.isNotEmpty()) {
466
- claimedKeyPackages.addAll(result.keyPackages)
467
- }
468
- } catch (exception: Exception ) {
469
- // Ignoring when claiming key packages fails for a user
470
- // as for now there is no retry
471
- logger.info(" Error when claiming key packages: $exception " )
472
- }
473
- }
474
-
475
- return claimedKeyPackages.map { it.keyPackage.decodeBase64Bytes() }
476
- }
477
372
}
0 commit comments