Browse Source

Merge pull request #3257 from element-hq/feature/fga/push_subscribe_to_room

Feature/fga/push subscribe to room
pull/3258/head
ganfra 2 months ago committed by GitHub
parent
commit
1cbd03aa7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt
  2. 1
      libraries/push/impl/build.gradle.kts
  3. 16
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/OnNotifiableEventReceived.kt

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

@ -120,4 +120,11 @@ enum class FeatureFlags( @@ -120,4 +120,11 @@ enum class FeatureFlags(
defaultValue = { it.buildType != BuildType.RELEASE },
isFinished = false,
),
SyncOnPush(
key = "feature.syncOnPush",
title = "Sync on push",
description = "Subscribe to room sync when a push is received",
defaultValue = { false },
isFinished = false,
),
}

1
libraries/push/impl/build.gradle.kts

@ -56,6 +56,7 @@ dependencies { @@ -56,6 +56,7 @@ dependencies {
implementation(projects.libraries.uiStrings)
implementation(projects.libraries.troubleshoot.api)
implementation(projects.features.call.api)
implementation(projects.libraries.featureflag.api)
api(projects.libraries.pushproviders.api)
api(projects.libraries.pushstore.api)
api(projects.libraries.push.api)

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

@ -18,6 +18,9 @@ package io.element.android.libraries.push.impl.push @@ -18,6 +18,9 @@ package io.element.android.libraries.push.impl.push
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.featureflag.api.FeatureFlags
import io.element.android.libraries.matrix.api.MatrixClientProvider
import io.element.android.libraries.push.impl.notifications.DefaultNotificationDrawerManager
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
import kotlinx.coroutines.CoroutineScope
@ -32,10 +35,23 @@ interface OnNotifiableEventReceived { @@ -32,10 +35,23 @@ interface OnNotifiableEventReceived {
class DefaultOnNotifiableEventReceived @Inject constructor(
private val defaultNotificationDrawerManager: DefaultNotificationDrawerManager,
private val coroutineScope: CoroutineScope,
private val matrixClientProvider: MatrixClientProvider,
private val featureFlagService: FeatureFlagService,
) : OnNotifiableEventReceived {
override fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
coroutineScope.launch {
subscribeToRoomIfNeeded(notifiableEvent)
defaultNotificationDrawerManager.onNotifiableEventReceived(notifiableEvent)
}
}
private fun CoroutineScope.subscribeToRoomIfNeeded(notifiableEvent: NotifiableEvent) = launch {
if (!featureFlagService.isFeatureEnabled(FeatureFlags.SyncOnPush)) {
return@launch
}
val client = matrixClientProvider.getOrRestore(notifiableEvent.sessionId).getOrNull() ?: return@launch
client.getRoom(notifiableEvent.roomId)?.use { room ->
room.subscribeToSync()
}
}
}

Loading…
Cancel
Save