Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion WordPress/Classes/System/RootViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class RootViewCoordinator {
// MARK: Private instance variables

private(set) var rootViewPresenter: RootViewPresenter
private(set) var currentAppUIType: AppUIType
private var currentAppUIType: AppUIType {
didSet {
updateJetpackFeaturesRemovalCoordinatorState()
}
}
private var featureFlagStore: RemoteFeatureFlagStore
private var windowManager: WindowManager?

Expand All @@ -53,6 +57,7 @@ class RootViewCoordinator {
let meScenePresenter = MeScenePresenter()
self.rootViewPresenter = MySitesCoordinator(meScenePresenter: meScenePresenter, onBecomeActiveTab: {})
}
updateJetpackFeaturesRemovalCoordinatorState()
updatePromptsIfNeeded()
}

Expand All @@ -69,6 +74,10 @@ class RootViewCoordinator {
}
}

private func updateJetpackFeaturesRemovalCoordinatorState() {
JetpackFeaturesRemovalCoordinator.currentAppUIType = currentAppUIType
}

// MARK: UI Reload

/// Reload the UI if needed after the app has already been launched.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class JetpackFeaturesRemovalCoordinator: NSObject {
}
}

static var currentAppUIType: RootViewCoordinator.AppUIType?

static func generalPhase(featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore()) -> GeneralPhase {
if AppConfiguration.isJetpack {
return .normal // Always return normal for Jetpack
Expand Down Expand Up @@ -139,34 +141,30 @@ class JetpackFeaturesRemovalCoordinator: NSObject {

/// Used to determine if the Jetpack features are enabled based on the current app UI type.
/// This way we ensure features are not removed before reloading the UI.
/// But if this function is called from a background thread, we determine if the Jetpack Features
/// But if the current app UI type is not set, we determine if the Jetpack Features
/// are enabled based on the removal phase regardless of the app UI state.
/// Default root view coordinator is used.
@objc
static func jetpackFeaturesEnabled() -> Bool {
guard Thread.isMainThread else {
return shouldEnableJetpackFeatures()
}
return jetpackFeaturesEnabled(rootViewCoordinator: .shared)
return jetpackFeaturesEnabled(featureFlagStore: RemoteFeatureFlagStore())
}

/// Used to determine if the Jetpack features are enabled based on the current app UI type.
/// This way we ensure features are not removed before reloading the UI.
/// But if this function is called from a background thread, we determine if the Jetpack Features
/// But if the current app UI type is not set, we determine if the Jetpack Features
/// are enabled based on the removal phase regardless of the app UI state.
/// Using two separate methods (rather than one method with a default argument) because Obj-C.
/// - Returns: `true` if UI type is normal, and `false` if UI type is simplified.
static func jetpackFeaturesEnabled(rootViewCoordinator: RootViewCoordinator) -> Bool {
guard Thread.isMainThread else {
return shouldEnableJetpackFeatures()
static func jetpackFeaturesEnabled(featureFlagStore: RemoteFeatureFlagStore) -> Bool {
guard let currentAppUIType else {
return shouldEnableJetpackFeatures(featureFlagStore: featureFlagStore)
}
return rootViewCoordinator.currentAppUIType == .normal
return currentAppUIType == .normal
}


/// Used to determine if the Jetpack features are enabled based on the removal phase regardless of the app UI state.
private static func shouldEnableJetpackFeatures(featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore()) -> Bool {
let phase = generalPhase()
private static func shouldEnableJetpackFeatures(featureFlagStore: RemoteFeatureFlagStore) -> Bool {
let phase = generalPhase(featureFlagStore: featureFlagStore)
switch phase {
case .four, .newUsers, .selfHosted:
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class JetpackBrandingMenuCardPresenter {
private let persistenceStore: UserPersistentRepository
private let currentDateProvider: CurrentDateProvider
private let featureFlagStore: RemoteFeatureFlagStore
private let rootViewCoordinator: RootViewCoordinator
private var phase: JetpackFeaturesRemovalCoordinator.GeneralPhase {
return JetpackFeaturesRemovalCoordinator.generalPhase(featureFlagStore: featureFlagStore)
}
Expand All @@ -30,14 +29,12 @@ class JetpackBrandingMenuCardPresenter {
remoteConfigStore: RemoteConfigStore = RemoteConfigStore(),
featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore(),
persistenceStore: UserPersistentRepository = UserDefaults.standard,
currentDateProvider: CurrentDateProvider = DefaultCurrentDateProvider(),
rootViewCoordinator: RootViewCoordinator = .shared) {
currentDateProvider: CurrentDateProvider = DefaultCurrentDateProvider()) {
self.blog = blog
self.remoteConfigStore = remoteConfigStore
self.persistenceStore = persistenceStore
self.currentDateProvider = currentDateProvider
self.featureFlagStore = featureFlagStore
self.rootViewCoordinator = rootViewCoordinator
}

// MARK: Public Functions
Expand Down Expand Up @@ -65,7 +62,7 @@ class JetpackBrandingMenuCardPresenter {
guard isCardEnabled() else {
return false
}
let jetpackFeaturesEnabled = JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled(rootViewCoordinator: rootViewCoordinator)
let jetpackFeaturesEnabled = JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled(featureFlagStore: featureFlagStore)
switch (phase, jetpackFeaturesEnabled) {
case (.three, true):
return true
Expand All @@ -80,7 +77,7 @@ class JetpackBrandingMenuCardPresenter {
guard isCardEnabled() else {
return false
}
let jetpackFeaturesEnabled = JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled(rootViewCoordinator: rootViewCoordinator)
let jetpackFeaturesEnabled = JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled(featureFlagStore: featureFlagStore)
switch (phase, jetpackFeaturesEnabled) {
case (.four, false):
fallthrough
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
private var remoteFeatureFlagsStore = RemoteFeatureFlagStoreMock()
private var remoteConfigStore = RemoteConfigStoreMock()
private var currentDateProvider: MockCurrentDateProvider!
private var rootViewCoordinator: RootViewCoordinator!

override func setUp() {
contextManager.useAsSharedInstance(untilTestFinished: self)
mockUserDefaults = InMemoryUserDefaults()
currentDateProvider = MockCurrentDateProvider()
rootViewCoordinator = RootViewCoordinator(featureFlagStore: remoteFeatureFlagsStore,
windowManager: WindowManager(window: UIWindow()))
let account = AccountBuilder(contextManager).build()
UserSettings.defaultDotComUUID = account.uuid
}
Expand All @@ -29,8 +26,7 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
let presenter = JetpackBrandingMenuCardPresenter(
blog: blog,
featureFlagStore: remoteFeatureFlagsStore,
persistenceStore: mockUserDefaults,
rootViewCoordinator: rootViewCoordinator)
persistenceStore: mockUserDefaults)

// Normal phase
setPhase(phase: .normal)
Expand Down Expand Up @@ -68,8 +64,7 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
let presenter = JetpackBrandingMenuCardPresenter(
blog: blog,
featureFlagStore: remoteFeatureFlagsStore,
persistenceStore: mockUserDefaults,
rootViewCoordinator: rootViewCoordinator)
persistenceStore: mockUserDefaults)

// Normal phase
setPhase(phase: .normal)
Expand Down Expand Up @@ -107,8 +102,7 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
blog: nil,
remoteConfigStore: remoteConfigStore,
featureFlagStore: remoteFeatureFlagsStore,
persistenceStore: mockUserDefaults,
rootViewCoordinator: rootViewCoordinator)
persistenceStore: mockUserDefaults)
setPhase(phase: .three)
remoteConfigStore.phaseThreeBlogPostUrl = "example.com"

Expand All @@ -126,8 +120,7 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
blog: nil,
remoteConfigStore: remoteConfigStore,
featureFlagStore: remoteFeatureFlagsStore,
persistenceStore: mockUserDefaults,
rootViewCoordinator: rootViewCoordinator)
persistenceStore: mockUserDefaults)
setPhase(phase: .four)

// When
Expand All @@ -144,8 +137,7 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
blog: nil,
remoteConfigStore: remoteConfigStore,
featureFlagStore: remoteFeatureFlagsStore,
persistenceStore: mockUserDefaults,
rootViewCoordinator: rootViewCoordinator)
persistenceStore: mockUserDefaults)
setPhase(phase: .newUsers)
remoteConfigStore.phaseNewUsersBlogPostUrl = "example.com"

Expand All @@ -165,8 +157,7 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
blog: blog,
remoteConfigStore: remoteConfigStore,
featureFlagStore: remoteFeatureFlagsStore,
persistenceStore: mockUserDefaults,
rootViewCoordinator: rootViewCoordinator)
persistenceStore: mockUserDefaults)
setPhase(phase: .selfHosted)
remoteConfigStore.phaseSelfHostedBlogPostUrl = "example.com"

Expand All @@ -183,8 +174,7 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
let presenter = JetpackBrandingMenuCardPresenter(
blog: nil,
featureFlagStore: remoteFeatureFlagsStore,
persistenceStore: mockUserDefaults,
rootViewCoordinator: rootViewCoordinator)
persistenceStore: mockUserDefaults)
setPhase(phase: .three)

// When
Expand Down Expand Up @@ -260,8 +250,5 @@ final class JetpackBrandingMenuCardPresenterTests: CoreDataTestCase {
case .selfHosted:
remoteFeatureFlagsStore.removalPhaseSelfHosted = true
}

// Reload UI
rootViewCoordinator.reloadUIIfNeeded(blog: nil)
}
}