Skip to content

Commit

Permalink
Enable identity pinning violation notifications unconditionally
Browse files Browse the repository at this point in the history
(Remove the feature flag we added when this feature seemed unstable.)
  • Loading branch information
andybalaam committed Oct 28, 2024
1 parent 01e7986 commit e362cad
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.featureflag.api.FeatureFlags
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.encryption.EncryptionService
import io.element.android.libraries.matrix.api.room.MatrixRoom
Expand All @@ -41,7 +39,6 @@ import javax.inject.Inject
class IdentityChangeStatePresenter @Inject constructor(
private val room: MatrixRoom,
private val encryptionService: EncryptionService,
private val featureFlagService: FeatureFlagService,
) : Presenter<IdentityChangeState> {
@Composable
override fun present(): IdentityChangeState {
Expand All @@ -64,11 +61,7 @@ class IdentityChangeStatePresenter @Inject constructor(

@OptIn(ExperimentalCoroutinesApi::class)
private fun ProduceStateScope<PersistentList<RoomMemberIdentityStateChange>>.observeRoomMemberIdentityStateChange() {
featureFlagService.isFeatureEnabledFlow(FeatureFlags.IdentityPinningViolationNotifications)
.filter { it }
.flatMapLatest {
room.syncUpdateFlow
}
room.syncUpdateFlow
.filter {
// Room cannot become unencrypted, so we can just apply a filter here.
room.isEncrypted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ package io.element.android.features.messages.impl.crypto.identity

import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
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.core.UserId
import io.element.android.libraries.matrix.api.encryption.EncryptionService
import io.element.android.libraries.matrix.api.encryption.identity.IdentityState
Expand Down Expand Up @@ -68,43 +65,6 @@ class IdentityChangeStatePresenterTest {
}
}

@Test
fun `present - when the room emits identity change, but the feature is disabled, the presenter does not emit new state`() = runTest {
val room = FakeMatrixRoom(
isEncrypted = true,
)
val featureFlagService = FakeFeatureFlagService(
initialState = mapOf(
FeatureFlags.IdentityPinningViolationNotifications.key to false,
)
)
val presenter = createIdentityChangeStatePresenter(
room = room,
featureFlagService = featureFlagService,
)
presenter.test {
val initialState = awaitItem()
assertThat(initialState.roomMemberIdentityStateChanges).isEmpty()
room.emitIdentityStateChanges(
listOf(
IdentityStateChange(
userId = A_USER_ID_2,
identityState = IdentityState.PinViolation,
),
)
)
// No item emitted.
expectNoEvents()
// Enable the feature
featureFlagService.setFeatureEnabled(FeatureFlags.IdentityPinningViolationNotifications, true)
val finalItem = awaitItem()
assertThat(finalItem.roomMemberIdentityStateChanges).hasSize(1)
val value = finalItem.roomMemberIdentityStateChanges.first()
assertThat(value.identityRoomMember.userId).isEqualTo(A_USER_ID_2)
assertThat(value.identityState).isEqualTo(IdentityState.PinViolation)
}
}

@Test
fun `present - when the clear room emits identity change, the presenter does not emit new state`() = runTest {
val room = FakeMatrixRoom(isEncrypted = false)
Expand Down Expand Up @@ -188,16 +148,10 @@ class IdentityChangeStatePresenterTest {
private fun createIdentityChangeStatePresenter(
room: MatrixRoom = FakeMatrixRoom(),
encryptionService: EncryptionService = FakeEncryptionService(),
featureFlagService: FeatureFlagService = FakeFeatureFlagService(
initialState = mapOf(
FeatureFlags.IdentityPinningViolationNotifications.key to true,
)
),
): IdentityChangeStatePresenter {
return IdentityChangeStatePresenter(
room = room,
encryptionService = encryptionService,
featureFlagService = featureFlagService,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package io.element.android.libraries.featureflag.api

import io.element.android.appconfig.OnBoardingConfig
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.core.meta.BuildType

/**
* To enable or disable a FeatureFlags, change the `defaultValue` value.
Expand Down Expand Up @@ -125,18 +124,5 @@ enum class FeatureFlags(
" You'll have to stop and re-open the app manually for that setting to take effect.",
defaultValue = { false },
isFinished = false,
),
IdentityPinningViolationNotifications(
key = "feature.identityPinningViolationNotifications",
title = "Identity pinning violation notifications",
description = null,
defaultValue = { buildMeta ->
when (buildMeta.buildType) {
// Do not enable this feature in release builds
BuildType.RELEASE -> false
else -> true
}
},
isFinished = false,
),
)
}

0 comments on commit e362cad

Please sign in to comment.