Skip to content

Commit

Permalink
Merge pull request #3257 from element-hq/feature/fga/push_subscribe_t…
Browse files Browse the repository at this point in the history
…o_room

Feature/fga/push subscribe to room
  • Loading branch information
ganfra authored Jul 30, 2024
2 parents bbacd0f + 08030b5 commit 1cbd03a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions libraries/push/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
}

0 comments on commit 1cbd03a

Please sign in to comment.