-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checks if Blaze for WooCommerce plugin is installed and active
- Loading branch information
1 parent
b610386
commit 584137b
Showing
1 changed file
with
20 additions
and
3 deletions.
There are no files selected for viewing
23 changes: 20 additions & 3 deletions
23
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/IsBlazeEnabled.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |