Merge pull request #6586 from element-hq/feature/bma/useSignInWithClassicFlag
Take into account the value of FeatureFlags.SignInWithClassic
This commit is contained in:
commit
be775d686e
2 changed files with 37 additions and 0 deletions
|
|
@ -28,6 +28,8 @@ import io.element.android.libraries.androidutils.service.ServiceBinder
|
||||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||||
import io.element.android.libraries.core.uri.ensureProtocol
|
import io.element.android.libraries.core.uri.ensureProtocol
|
||||||
import io.element.android.libraries.di.annotations.AppCoroutineScope
|
import io.element.android.libraries.di.annotations.AppCoroutineScope
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlagService
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlags
|
||||||
import io.element.android.libraries.matrix.api.auth.ElementClassicSession
|
import io.element.android.libraries.matrix.api.auth.ElementClassicSession
|
||||||
import io.element.android.libraries.matrix.api.auth.HomeServerLoginCompatibilityChecker
|
import io.element.android.libraries.matrix.api.auth.HomeServerLoginCompatibilityChecker
|
||||||
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
||||||
|
|
@ -69,6 +71,7 @@ class DefaultElementClassicConnection(
|
||||||
private val coroutineScope: CoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
private val matrixAuthenticationService: MatrixAuthenticationService,
|
private val matrixAuthenticationService: MatrixAuthenticationService,
|
||||||
private val homeServerLoginCompatibilityChecker: HomeServerLoginCompatibilityChecker,
|
private val homeServerLoginCompatibilityChecker: HomeServerLoginCompatibilityChecker,
|
||||||
|
private val featureFlagService: FeatureFlagService,
|
||||||
) : ElementClassicConnection {
|
) : ElementClassicConnection {
|
||||||
// Messenger for communicating with the service.
|
// Messenger for communicating with the service.
|
||||||
private var messenger: Messenger? = null
|
private var messenger: Messenger? = null
|
||||||
|
|
@ -116,6 +119,10 @@ class DefaultElementClassicConnection(
|
||||||
override fun start() {
|
override fun start() {
|
||||||
Timber.tag(loggerTag.value).d("start()")
|
Timber.tag(loggerTag.value).d("start()")
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
|
if (!featureFlagService.isFeatureEnabled(FeatureFlags.SignInWithClassic)) {
|
||||||
|
Timber.tag(loggerTag.value).d("Login with Element Classic is disabled, not starting connection")
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
// Establish a connection with the service. We use an explicit
|
// Establish a connection with the service. We use an explicit
|
||||||
// class name because there is no reason to be able to let other
|
// class name because there is no reason to be able to let other
|
||||||
// applications replace our component.
|
// applications replace our component.
|
||||||
|
|
@ -151,6 +158,11 @@ class DefaultElementClassicConnection(
|
||||||
override fun requestSession() {
|
override fun requestSession() {
|
||||||
Timber.tag(loggerTag.value).d("requestSession()")
|
Timber.tag(loggerTag.value).d("requestSession()")
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
|
if (!featureFlagService.isFeatureEnabled(FeatureFlags.SignInWithClassic)) {
|
||||||
|
Timber.tag(loggerTag.value).d("Login with Element Classic is disabled")
|
||||||
|
emitState(ElementClassicConnectionState.Error("The feature is disabled"))
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
val finalMessenger = messenger
|
val finalMessenger = messenger
|
||||||
if (finalMessenger == null) {
|
if (finalMessenger == null) {
|
||||||
Timber.tag(loggerTag.value).d("The messenger is null, can't request data")
|
Timber.tag(loggerTag.value).d("The messenger is null, can't request data")
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ import androidx.core.graphics.createBitmap
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.libraries.androidutils.service.ServiceBinder
|
import io.element.android.libraries.androidutils.service.ServiceBinder
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlagService
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlags
|
||||||
|
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
||||||
import io.element.android.libraries.matrix.api.auth.ElementClassicSession
|
import io.element.android.libraries.matrix.api.auth.ElementClassicSession
|
||||||
import io.element.android.libraries.matrix.api.auth.HomeServerLoginCompatibilityChecker
|
import io.element.android.libraries.matrix.api.auth.HomeServerLoginCompatibilityChecker
|
||||||
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
||||||
|
|
@ -109,6 +112,21 @@ class DefaultElementClassicConnectionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `requestSession when the feature is disabled emits an error`() = runTest {
|
||||||
|
val connection = createDefaultElementClassicConnection(
|
||||||
|
matrixAuthenticationService = FakeMatrixAuthenticationService(
|
||||||
|
setElementClassicSessionResult = {},
|
||||||
|
),
|
||||||
|
isFeatureEnabled = false,
|
||||||
|
)
|
||||||
|
connection.stateFlow.test {
|
||||||
|
assertThat(awaitItem()).isEqualTo(ElementClassicConnectionState.Idle)
|
||||||
|
connection.requestSession()
|
||||||
|
assertThat(awaitItem()).isInstanceOf(ElementClassicConnectionState.Error::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when an error is received, an error is emitted`() = runTest {
|
fun `when an error is received, an error is emitted`() = runTest {
|
||||||
val connection = createDefaultElementClassicConnection(
|
val connection = createDefaultElementClassicConnection(
|
||||||
|
|
@ -496,10 +514,17 @@ class DefaultElementClassicConnectionTest {
|
||||||
homeServerLoginCompatibilityChecker: HomeServerLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(
|
homeServerLoginCompatibilityChecker: HomeServerLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(
|
||||||
checkResult = { Result.success(true) }
|
checkResult = { Result.success(true) }
|
||||||
),
|
),
|
||||||
|
isFeatureEnabled: Boolean = true,
|
||||||
|
featureFlagService: FeatureFlagService = FakeFeatureFlagService(
|
||||||
|
initialState = mapOf(
|
||||||
|
FeatureFlags.SignInWithClassic.key to isFeatureEnabled,
|
||||||
|
)
|
||||||
|
),
|
||||||
) = DefaultElementClassicConnection(
|
) = DefaultElementClassicConnection(
|
||||||
serviceBinder = serviceBinder,
|
serviceBinder = serviceBinder,
|
||||||
coroutineScope = coroutineScope,
|
coroutineScope = coroutineScope,
|
||||||
matrixAuthenticationService = matrixAuthenticationService,
|
matrixAuthenticationService = matrixAuthenticationService,
|
||||||
homeServerLoginCompatibilityChecker = homeServerLoginCompatibilityChecker,
|
homeServerLoginCompatibilityChecker = homeServerLoginCompatibilityChecker,
|
||||||
|
featureFlagService = featureFlagService,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue