Skip to content

Commit

Permalink
Checks if Blaze for WooCommerce plugin is installed and active
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgeMucientes committed Sep 18, 2024
1 parent b610386 commit 584137b
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package com.woocommerce.android.ui.blaze

import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.tools.SiteConnectionType
import com.woocommerce.android.tools.SiteConnectionType.Jetpack
import com.woocommerce.android.tools.SiteConnectionType.JetpackConnectionPackage
import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled
import com.woocommerce.android.util.RemoteFeatureFlag.WOO_BLAZE
import javax.inject.Inject

class IsBlazeEnabled @Inject constructor(
private val selectedSite: SelectedSite,
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled,
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled
) {
companion object {
private const val BLAZE_FOR_WOOCOMMERCE_PLUGIN_SLUG = "blaze-ads"
}

suspend operator fun invoke(): Boolean = selectedSite.getIfExists()?.isAdmin ?: false &&
selectedSite.connectionType == SiteConnectionType.Jetpack &&
hasAValidJetpackConnectionForBlaze() &&
selectedSite.getIfExists()?.canBlaze ?: false &&
isRemoteFeatureFlagEnabled(WOO_BLAZE)

/**
* In order for Blaze to work, the site requires the Jetpack Sync module to be enabled. This means not all
* Jetpack connection will work. For now, Blaze will only be enabled for sites with Jetpack plugin installed and
* active, or for sites with Blaze for WooCommerce plugin installed and connected (Jetpack CP with sync module)
*/
private fun hasAValidJetpackConnectionForBlaze() =
selectedSite.connectionType == Jetpack ||
(selectedSite.connectionType == JetpackConnectionPackage && isBlazeForWooCommercePluginInstalled())

private fun isBlazeForWooCommercePluginInstalled(): Boolean =
selectedSite.get().activeJetpackConnectionPlugins.any { it.toString() == BLAZE_FOR_WOOCOMMERCE_PLUGIN_SLUG }
}

0 comments on commit 584137b

Please sign in to comment.