Merge pull request #3257 from element-hq/feature/fga/push_subscribe_to_room
Feature/fga/push subscribe to room
This commit is contained in:
commit
e0a3389f3a
3 changed files with 24 additions and 0 deletions
|
|
@ -120,4 +120,11 @@ enum class FeatureFlags(
|
||||||
defaultValue = { it.buildType != BuildType.RELEASE },
|
defaultValue = { it.buildType != BuildType.RELEASE },
|
||||||
isFinished = false,
|
isFinished = false,
|
||||||
),
|
),
|
||||||
|
SyncOnPush(
|
||||||
|
key = "feature.syncOnPush",
|
||||||
|
title = "Sync on push",
|
||||||
|
description = "Subscribe to room sync when a push is received",
|
||||||
|
defaultValue = { false },
|
||||||
|
isFinished = false,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ dependencies {
|
||||||
implementation(projects.libraries.uiStrings)
|
implementation(projects.libraries.uiStrings)
|
||||||
implementation(projects.libraries.troubleshoot.api)
|
implementation(projects.libraries.troubleshoot.api)
|
||||||
implementation(projects.features.call.api)
|
implementation(projects.features.call.api)
|
||||||
|
implementation(projects.libraries.featureflag.api)
|
||||||
api(projects.libraries.pushproviders.api)
|
api(projects.libraries.pushproviders.api)
|
||||||
api(projects.libraries.pushstore.api)
|
api(projects.libraries.pushstore.api)
|
||||||
api(projects.libraries.push.api)
|
api(projects.libraries.push.api)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ package io.element.android.libraries.push.impl.push
|
||||||
|
|
||||||
import com.squareup.anvil.annotations.ContributesBinding
|
import com.squareup.anvil.annotations.ContributesBinding
|
||||||
import io.element.android.libraries.di.AppScope
|
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.DefaultNotificationDrawerManager
|
||||||
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
|
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
@ -32,10 +35,23 @@ interface OnNotifiableEventReceived {
|
||||||
class DefaultOnNotifiableEventReceived @Inject constructor(
|
class DefaultOnNotifiableEventReceived @Inject constructor(
|
||||||
private val defaultNotificationDrawerManager: DefaultNotificationDrawerManager,
|
private val defaultNotificationDrawerManager: DefaultNotificationDrawerManager,
|
||||||
private val coroutineScope: CoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
|
private val matrixClientProvider: MatrixClientProvider,
|
||||||
|
private val featureFlagService: FeatureFlagService,
|
||||||
) : OnNotifiableEventReceived {
|
) : OnNotifiableEventReceived {
|
||||||
override fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
|
override fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
|
subscribeToRoomIfNeeded(notifiableEvent)
|
||||||
defaultNotificationDrawerManager.onNotifiableEventReceived(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…
Add table
Add a link
Reference in a new issue