|
1 | 1 | package com.woocommerce.android.ui.blaze
|
2 | 2 |
|
3 | 3 | import com.woocommerce.android.tools.SelectedSite
|
4 |
| -import com.woocommerce.android.tools.SiteConnectionType |
| 4 | +import com.woocommerce.android.tools.SiteConnectionType.Jetpack |
5 | 5 | import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled
|
6 | 6 | import com.woocommerce.android.util.RemoteFeatureFlag.WOO_BLAZE
|
7 | 7 | import javax.inject.Inject
|
8 | 8 |
|
9 | 9 | class IsBlazeEnabled @Inject constructor(
|
10 | 10 | private val selectedSite: SelectedSite,
|
11 |
| - private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled, |
| 11 | + private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled |
12 | 12 | ) {
|
| 13 | + companion object { |
| 14 | + private const val BLAZE_FOR_WOOCOMMERCE_PLUGIN_SLUG = "blaze-ads" |
| 15 | + } |
| 16 | + |
13 | 17 | suspend operator fun invoke(): Boolean = selectedSite.getIfExists()?.isAdmin ?: false &&
|
14 |
| - selectedSite.connectionType == SiteConnectionType.Jetpack && |
| 18 | + hasAValidJetpackConnectionForBlaze() && |
15 | 19 | selectedSite.getIfExists()?.canBlaze ?: false &&
|
16 | 20 | isRemoteFeatureFlagEnabled(WOO_BLAZE)
|
| 21 | + |
| 22 | + /** |
| 23 | + * In order for Blaze to work, the site requires the Jetpack Sync module to be enabled. This means not all |
| 24 | + * Jetpack connection will work. For now, Blaze will only be enabled for sites with Jetpack plugin installed and |
| 25 | + * active, or for sites with Blaze for WooCommerce plugin installed and connected. |
| 26 | + */ |
| 27 | + private fun hasAValidJetpackConnectionForBlaze() = |
| 28 | + selectedSite.connectionType == Jetpack || isBlazeForWooCommercePluginActive() |
| 29 | + |
| 30 | + private fun isBlazeForWooCommercePluginActive(): Boolean = |
| 31 | + selectedSite.get().activeJetpackConnectionPlugins?.contains(BLAZE_FOR_WOOCOMMERCE_PLUGIN_SLUG) == true |
17 | 32 | }
|
0 commit comments