Skip to content

Commit f99b6f3

Browse files
committed
Revert "Remove FeatureFlag.SyncOnPush"
This reverts commit b394688.
1 parent e9b9ada commit f99b6f3

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ enum class FeatureFlags(
3434
defaultValue = { false },
3535
isFinished = false,
3636
),
37+
SyncOnPush(
38+
key = "feature.syncOnPush",
39+
title = "Sync on push",
40+
description = "Subscribe to room sync when a push is received",
41+
defaultValue = { true },
42+
isFinished = false,
43+
),
3744
OnlySignedDeviceIsolationMode(
3845
key = "feature.onlySignedDeviceIsolationMode",
3946
title = "Exclude insecure devices when sending/receiving messages",

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/SyncOnNotifiableEvent.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
package io.element.android.libraries.push.impl.push
99

1010
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
11+
import io.element.android.libraries.featureflag.api.FeatureFlagService
12+
import io.element.android.libraries.featureflag.api.FeatureFlags
1113
import io.element.android.libraries.matrix.api.MatrixClientProvider
1214
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
1315
import io.element.android.services.appnavstate.api.AppForegroundStateService
@@ -19,10 +21,15 @@ import kotlin.time.Duration.Companion.seconds
1921

2022
class SyncOnNotifiableEvent @Inject constructor(
2123
private val matrixClientProvider: MatrixClientProvider,
24+
private val featureFlagService: FeatureFlagService,
2225
private val appForegroundStateService: AppForegroundStateService,
2326
private val dispatchers: CoroutineDispatchers,
2427
) {
2528
suspend operator fun invoke(notifiableEvents: List<NotifiableEvent>) = withContext(dispatchers.io) {
29+
if (!featureFlagService.isFeatureEnabled(FeatureFlags.SyncOnPush)) {
30+
return@withContext
31+
}
32+
2633
try {
2734
val eventsBySession = notifiableEvents.groupBy { it.sessionId }
2835

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/SyncOnNotifiableEventTest.kt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package io.element.android.libraries.push.impl.push
99

1010
import app.cash.turbine.test
1111
import com.google.common.truth.Truth.assertThat
12+
import io.element.android.libraries.featureflag.api.FeatureFlags
13+
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
1214
import io.element.android.libraries.matrix.api.MatrixClient
1315
import io.element.android.libraries.matrix.api.sync.SyncState
1416
import io.element.android.libraries.matrix.test.A_ROOM_ID
@@ -21,6 +23,7 @@ import io.element.android.libraries.matrix.test.sync.FakeSyncService
2123
import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableCallEvent
2224
import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent
2325
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
26+
import io.element.android.tests.testutils.lambda.assert
2427
import io.element.android.tests.testutils.lambda.lambdaRecorder
2528
import io.element.android.tests.testutils.testCoroutineDispatchers
2629
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -57,13 +60,24 @@ class SyncOnNotifiableEventTest {
5760
private val notifiableEvent = aNotifiableMessageEvent()
5861
private val incomingCallNotifiableEvent = aNotifiableCallEvent()
5962

63+
@Test
64+
fun `when feature flag is disabled, nothing happens`() = runTest {
65+
val sut = createSyncOnNotifiableEvent(client = client, isSyncOnPushEnabled = false)
66+
67+
sut(listOf(notifiableEvent))
68+
69+
assert(startSyncLambda).isNeverCalled()
70+
assert(stopSyncLambda).isNeverCalled()
71+
assert(subscribeToSyncLambda).isNeverCalled()
72+
}
73+
6074
@OptIn(ExperimentalCoroutinesApi::class)
6175
@Test
6276
fun `when feature flag is enabled, a ringing call waits until the room is in 'in-call' state`() = runTest {
6377
val appForegroundStateService = FakeAppForegroundStateService(
6478
initialForegroundValue = false,
6579
)
66-
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
80+
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true)
6781

6882
val unlocked = AtomicBoolean(false)
6983
launch {
@@ -83,7 +97,7 @@ class SyncOnNotifiableEventTest {
8397
val appForegroundStateService = FakeAppForegroundStateService(
8498
initialForegroundValue = false,
8599
)
86-
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
100+
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true)
87101

88102
val unlocked = AtomicBoolean(false)
89103
launch {
@@ -102,7 +116,7 @@ class SyncOnNotifiableEventTest {
102116
val appForegroundStateService = FakeAppForegroundStateService(
103117
initialForegroundValue = false,
104118
)
105-
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
119+
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true)
106120

107121
appForegroundStateService.isSyncingNotificationEvent.test {
108122
syncService.emitSyncState(SyncState.Running)
@@ -124,7 +138,7 @@ class SyncOnNotifiableEventTest {
124138
val appForegroundStateService = FakeAppForegroundStateService(
125139
initialForegroundValue = false,
126140
)
127-
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService)
141+
val sut = createSyncOnNotifiableEvent(client = client, appForegroundStateService = appForegroundStateService, isSyncOnPushEnabled = true)
128142

129143
appForegroundStateService.isSyncingNotificationEvent.test {
130144
launch { sut(listOf(notifiableEvent)) }
@@ -143,13 +157,20 @@ class SyncOnNotifiableEventTest {
143157

144158
private fun TestScope.createSyncOnNotifiableEvent(
145159
client: MatrixClient = FakeMatrixClient(),
160+
isSyncOnPushEnabled: Boolean = true,
146161
appForegroundStateService: FakeAppForegroundStateService = FakeAppForegroundStateService(
147162
initialForegroundValue = true,
148163
),
149164
): SyncOnNotifiableEvent {
165+
val featureFlagService = FakeFeatureFlagService(
166+
initialState = mapOf(
167+
FeatureFlags.SyncOnPush.key to isSyncOnPushEnabled
168+
)
169+
)
150170
val matrixClientProvider = FakeMatrixClientProvider { Result.success(client) }
151171
return SyncOnNotifiableEvent(
152172
matrixClientProvider = matrixClientProvider,
173+
featureFlagService = featureFlagService,
153174
appForegroundStateService = appForegroundStateService,
154175
dispatchers = testCoroutineDispatchers(),
155176
)

0 commit comments

Comments
 (0)