Skip to content

Commit 1cbd03a

Browse files
authored
Merge pull request #3257 from element-hq/feature/fga/push_subscribe_to_room
Feature/fga/push subscribe to room
2 parents bbacd0f + 08030b5 commit 1cbd03a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
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
@@ -120,4 +120,11 @@ enum class FeatureFlags(
120120
defaultValue = { it.buildType != BuildType.RELEASE },
121121
isFinished = false,
122122
),
123+
SyncOnPush(
124+
key = "feature.syncOnPush",
125+
title = "Sync on push",
126+
description = "Subscribe to room sync when a push is received",
127+
defaultValue = { false },
128+
isFinished = false,
129+
),
123130
}

libraries/push/impl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ dependencies {
5656
implementation(projects.libraries.uiStrings)
5757
implementation(projects.libraries.troubleshoot.api)
5858
implementation(projects.features.call.api)
59+
implementation(projects.libraries.featureflag.api)
5960
api(projects.libraries.pushproviders.api)
6061
api(projects.libraries.pushstore.api)
6162
api(projects.libraries.push.api)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package io.element.android.libraries.push.impl.push
1818

1919
import com.squareup.anvil.annotations.ContributesBinding
2020
import io.element.android.libraries.di.AppScope
21+
import io.element.android.libraries.featureflag.api.FeatureFlagService
22+
import io.element.android.libraries.featureflag.api.FeatureFlags
23+
import io.element.android.libraries.matrix.api.MatrixClientProvider
2124
import io.element.android.libraries.push.impl.notifications.DefaultNotificationDrawerManager
2225
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
2326
import kotlinx.coroutines.CoroutineScope
@@ -32,10 +35,23 @@ interface OnNotifiableEventReceived {
3235
class DefaultOnNotifiableEventReceived @Inject constructor(
3336
private val defaultNotificationDrawerManager: DefaultNotificationDrawerManager,
3437
private val coroutineScope: CoroutineScope,
38+
private val matrixClientProvider: MatrixClientProvider,
39+
private val featureFlagService: FeatureFlagService,
3540
) : OnNotifiableEventReceived {
3641
override fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
3742
coroutineScope.launch {
43+
subscribeToRoomIfNeeded(notifiableEvent)
3844
defaultNotificationDrawerManager.onNotifiableEventReceived(notifiableEvent)
3945
}
4046
}
47+
48+
private fun CoroutineScope.subscribeToRoomIfNeeded(notifiableEvent: NotifiableEvent) = launch {
49+
if (!featureFlagService.isFeatureEnabled(FeatureFlags.SyncOnPush)) {
50+
return@launch
51+
}
52+
val client = matrixClientProvider.getOrRestore(notifiableEvent.sessionId).getOrNull() ?: return@launch
53+
client.getRoom(notifiableEvent.roomId)?.use { room ->
54+
room.subscribeToSync()
55+
}
56+
}
4157
}

0 commit comments

Comments
 (0)