Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mls): respect default protocol in one-on-one conversation initialisation (WPB-8975) 🍒 #2769

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ class UserSessionScope internal constructor(

internal val mlsMigrationManager: MLSMigrationManager = MLSMigrationManagerImpl(
kaliumConfigs,
featureSupport,
isMLSEnabled,
incrementalSyncRepository,
lazy { clientRepository },
lazy { users.timestampKeyRepository },
Expand Down Expand Up @@ -1632,7 +1632,8 @@ class UserSessionScope internal constructor(

private val oneOnOneProtocolSelector: OneOnOneProtocolSelector
get() = OneOnOneProtocolSelectorImpl(
userRepository
userRepository,
userConfigRepository
)

private val acmeCertificatesSyncWorker: ACMECertificatesSyncWorker by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.wire.kalium.logic.data.sync.IncrementalSyncRepository
import com.wire.kalium.logic.data.sync.IncrementalSyncStatus
import com.wire.kalium.logic.feature.TimestampKeyRepository
import com.wire.kalium.logic.feature.TimestampKeys
import com.wire.kalium.logic.featureFlags.FeatureSupport
import com.wire.kalium.logic.feature.user.IsMLSEnabledUseCase
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.flatMap
Expand All @@ -50,7 +50,7 @@ internal interface MLSMigrationManager
@Suppress("LongParameterList")
internal class MLSMigrationManagerImpl(
private val kaliumConfigs: KaliumConfigs,
private val featureSupport: FeatureSupport,
private val isMLSEnabledUseCase: IsMLSEnabledUseCase,
private val incrementalSyncRepository: IncrementalSyncRepository,
private val clientRepository: Lazy<ClientRepository>,
private val timestampKeyRepository: Lazy<TimestampKeyRepository>,
Expand All @@ -73,7 +73,7 @@ internal class MLSMigrationManagerImpl(
incrementalSyncRepository.incrementalSyncState.collect { syncState ->
ensureActive()
if (syncState is IncrementalSyncStatus.Live &&
featureSupport.isMLSSupported &&
isMLSEnabledUseCase() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isMLSEnabledUseCase() &&
isMLSEnabled() &&

Just a tiny change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the note, I'm afraid if I change it now; then in other cherrypicks gonna create other issues!

clientRepository.value.hasRegisteredMLSClient().getOrElse(false)
) {
updateMigration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class MLSMigrationWorkerImpl(
override suspend fun runMigration() =
syncMigrationConfigurations().flatMap {
userConfigRepository.getMigrationConfiguration().getOrNull()?.let { configuration ->
if (configuration.hasMigrationStarted()) {
if (configuration.status.toBoolean() && configuration.hasMigrationStarted()) {
kaliumLogger.i("Running proteus to MLS migration")
mlsMigrator.migrateProteusConversations().flatMap {
if (configuration.hasMigrationEnded()) {
Expand All @@ -57,7 +57,6 @@ internal class MLSMigrationWorkerImpl(
}
} ?: Either.Right(Unit)
}

private suspend fun syncMigrationConfigurations(): Either<CoreFailure, Unit> =
featureConfigRepository.getFeatureConfigs().flatMap { configurations ->
mlsConfigHandler.handle(configurations.mlsModel, duringSlowSync = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
package com.wire.kalium.logic.feature.protocol

import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.configuration.UserConfigRepository
import com.wire.kalium.logic.data.user.SupportedProtocol
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.flatMap
import com.wire.kalium.logic.functional.fold

internal interface OneOnOneProtocolSelector {
suspend fun getProtocolForUser(userId: UserId): Either<CoreFailure, SupportedProtocol>
}

internal class OneOnOneProtocolSelectorImpl(
private val userRepository: UserRepository
private val userRepository: UserRepository,
private val userConfigRepository: UserConfigRepository
) : OneOnOneProtocolSelector {
override suspend fun getProtocolForUser(userId: UserId): Either<CoreFailure, SupportedProtocol> =
userRepository.userById(userId).flatMap { otherUser ->
Expand All @@ -40,8 +43,11 @@ internal class OneOnOneProtocolSelectorImpl(

val selfUserProtocols = selfUser.supportedProtocols.orEmpty()
val otherUserProtocols = otherUser.supportedProtocols.orEmpty()

val commonProtocols = selfUserProtocols.intersect(otherUserProtocols)
val commonProtocols = userConfigRepository.getDefaultProtocol().fold({
selfUserProtocols.intersect(otherUserProtocols)
}, {
selfUserProtocols.intersect(listOf(it).toSet()).intersect(otherUserProtocols)
})

return when {
commonProtocols.contains(SupportedProtocol.MLS) -> Either.Right(SupportedProtocol.MLS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.wire.kalium.logic.data.sync.IncrementalSyncRepository
import com.wire.kalium.logic.data.sync.IncrementalSyncStatus
import com.wire.kalium.logic.feature.TimestampKeyRepository
import com.wire.kalium.logic.feature.TimestampKeys
import com.wire.kalium.logic.featureFlags.FeatureSupport
import com.wire.kalium.logic.feature.user.IsMLSEnabledUseCase
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.test_util.TestKaliumDispatcher
Expand Down Expand Up @@ -121,7 +121,7 @@ class MLSMigrationManagerTest {
val clientRepository = mock(ClientRepository::class)

@Mock
val featureSupport = mock(FeatureSupport::class)
val isMLSEnabledUseCase = mock(IsMLSEnabledUseCase::class)

@Mock
val timestampKeyRepository = mock(TimestampKeyRepository::class)
Expand Down Expand Up @@ -149,8 +149,9 @@ class MLSMigrationManagerTest {

fun withIsMLSSupported(supported: Boolean) = apply {
every {
featureSupport.isMLSSupported
isMLSEnabledUseCase()
}.returns(supported)

}

suspend fun withHasRegisteredMLSClient(result: Boolean) = apply {
Expand All @@ -161,7 +162,7 @@ class MLSMigrationManagerTest {

fun arrange() = this to MLSMigrationManagerImpl(
kaliumConfigs,
featureSupport,
isMLSEnabledUseCase,
incrementalSyncRepository,
lazy { clientRepository },
lazy { timestampKeyRepository },
Expand Down
Loading
Loading