Skip to content

Commit 440699e

Browse files
Merge pull request #19894 from wordpress-mobile/task/19453-new-users-phase-card-and-display-logic
Jetpack Focus: New users phase menu card and overlay display logic
2 parents f53c6a1 + f814486 commit 440699e

File tree

7 files changed

+64
-20
lines changed

7 files changed

+64
-20
lines changed

WordPress/Classes/Stores/RemoteFeatureFlagStore.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class RemoteFeatureFlagStore {
3232
callback?()
3333
case .failure(let error):
3434
DDLogError("🚩 Unable to update Feature Flag Store: \(error.localizedDescription)")
35+
callback?()
3536
}
3637
}
3738
}

WordPress/Classes/System/WordPressAppDelegate.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,17 @@ extension WordPressAppDelegate {
672672
}
673673
}
674674

675-
/// Updates the remote feature flags using an authenticated remote if an account exists, or using an anonymous remote if no account exists.
676-
func updateFeatureFlags() {
677-
do {
678-
let defaultAccount = try WPAccount.lookupDefaultWordPressComAccount(in: mainContext)
679-
let api = defaultAccount?.wordPressComRestV2Api ?? WordPressComRestApi.defaultApi()
680-
let remote = FeatureFlagRemote(wordPressComRestApi: api)
681-
remoteFeatureFlagStore.update(using: remote)
682-
} catch {
683-
DDLogError("Error fetching default user account: \(error)")
675+
/// Updates the remote feature flags using an authenticated remote if a token is provided or an account exists
676+
/// Otherwise an anonymous remote will be used
677+
func updateFeatureFlags(authToken: String? = nil, completion: (() -> Void)? = nil) {
678+
var api: WordPressComRestApi
679+
if let authToken {
680+
api = WordPressComRestApi.defaultV2Api(authToken: authToken)
681+
} else {
682+
api = WordPressComRestApi.defaultV2Api(in: mainContext)
684683
}
684+
let remote = FeatureFlagRemote(wordPressComRestApi: api)
685+
remoteFeatureFlagStore.update(using: remote, then: completion)
685686
}
686687

687688
func updateRemoteConfig() {

WordPress/Classes/Utility/Networking/WordPressComRestApi+Defaults.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ extension WordPressComRestApi {
2121
let token: String? = defaultAccount?.authToken
2222

2323
return WordPressComRestApi.defaultApi(oAuthToken: token,
24-
userAgent: WPUserAgent.wordPress())
24+
userAgent: userAgent,
25+
localeKey: localeKey)
26+
}
27+
28+
@objc public static func defaultV2Api(authToken: String? = nil) -> WordPressComRestApi {
29+
let userAgent = WPUserAgent.wordPress()
30+
let localeKey = WordPressComRestApi.LocaleKeyV2
31+
return WordPressComRestApi.defaultApi(oAuthToken: authToken,
32+
userAgent: userAgent,
33+
localeKey: localeKey)
34+
}
35+
36+
@objc public static func defaultV2Api(in context: NSManagedObjectContext) -> WordPressComRestApi {
37+
return WordPressComRestApi.defaultApi(in: context,
38+
userAgent: WPUserAgent.wordPress(),
39+
localeKey: WordPressComRestApi.LocaleKeyV2)
2540
}
2641
}

WordPress/Classes/ViewRelated/Jetpack/Branding/Fullscreen Overlay/JetpackFullscreenOverlayGeneralViewModel.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ struct JetpackFullscreenOverlayGeneralViewModel: JetpackFullscreenOverlayViewMod
3030
case (.three, _):
3131
return true
3232

33-
// Phase Four: Show feature-collection overlays. Features are removed by this point so they are irrelevant.
34-
case (.four, .card):
33+
// Do not show feature overlays in phases where they are removed.
34+
case (_, .stats):
3535
fallthrough
36-
case (.four, .appOpen):
36+
case (_, .reader):
37+
fallthrough
38+
case (_, .notifications):
39+
return false
40+
41+
// Phase Four: Show feature-collection overlays.
42+
case (.four, _):
3743
return true
3844

39-
// New Users Phase: Show feature-collection overlays. Features are removed by this point so they are irrelevant.
45+
// New Users Phase: Show feature-collection overlays.
4046
case (.newUsers, _):
4147
return true
4248

WordPress/Classes/ViewRelated/Jetpack/Branding/Menu Card/JetpackBrandingMenuCardPresenter.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class JetpackBrandingMenuCardPresenter {
4747
let description = Strings.phaseFourTitle
4848
let url = RemoteConfig(store: remoteConfigStore).phaseFourBlogPostUrl.value
4949
return .init(description: description, learnMoreButtonURL: url, type: .compact)
50+
case .newUsers:
51+
let description = Strings.newUsersPhaseTitle
52+
let url = RemoteConfig(store: remoteConfigStore).phaseNewUsersBlogPostUrl.value
53+
return .init(description: description, learnMoreButtonURL: url, type: .expanded)
5054
default:
5155
return nil
5256
}
@@ -70,6 +74,8 @@ class JetpackBrandingMenuCardPresenter {
7074
}
7175
switch phase {
7276
case .four:
77+
fallthrough
78+
case .newUsers:
7379
return true
7480
default:
7581
return false
@@ -184,5 +190,8 @@ private extension JetpackBrandingMenuCardPresenter {
184190
static let phaseFourTitle = NSLocalizedString("jetpack.menuCard.phaseFour.title",
185191
value: "Switch to Jetpack",
186192
comment: "Title of a button prompting users to switch to the Jetpack app.")
193+
static let newUsersPhaseTitle = NSLocalizedString("jetpack.menuCard.newUsers.title",
194+
value: "Unlock your site’s full potential. Get stats, notifications and more with Jetpack.",
195+
comment: "Description inside a menu card prompting users to switch to the Jetpack app.")
187196
}
188197
}

WordPress/Classes/ViewRelated/NUX/WordPressAuthenticationManager.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,11 @@ private extension WordPressAuthenticationManager {
691691
private func syncWPCom(authToken: String, isJetpackLogin: Bool, onCompletion: @escaping () -> ()) {
692692
let service = WordPressComSyncService()
693693

694+
// Create a dispatch group to wait for both API calls.
695+
let syncGroup = DispatchGroup()
696+
697+
// Sync account and blog
698+
syncGroup.enter()
694699
service.syncWPCom(authToken: authToken, isJetpackLogin: isJetpackLogin, onSuccess: { account in
695700

696701
/// HACK: An alternative notification to LoginFinished. Observe this instead of `WPSigninDidFinishNotification` for Jetpack logins.
@@ -699,14 +704,21 @@ private extension WordPressAuthenticationManager {
699704
let notification = isJetpackLogin == true ? .wordpressLoginFinishedJetpackLogin : Foundation.Notification.Name(rawValue: WordPressAuthenticator.WPSigninDidFinishNotification)
700705
NotificationCenter.default.post(name: notification, object: account)
701706

702-
// Refresh Remote Feature Flags
703-
WordPressAppDelegate.shared?.updateFeatureFlags()
707+
syncGroup.leave()
708+
}, onFailure: { _ in
709+
syncGroup.leave()
710+
})
704711

705-
onCompletion()
712+
// Refresh Remote Feature Flags
713+
syncGroup.enter()
714+
WordPressAppDelegate.shared?.updateFeatureFlags(authToken: authToken, completion: {
715+
syncGroup.leave()
716+
})
706717

707-
}, onFailure: { _ in
718+
// Sync done
719+
syncGroup.notify(queue: .main) {
708720
onCompletion()
709-
})
721+
}
710722
}
711723

712724
/// Synchronizes a WordPress.org account with the specified credentials.

WordPress/WordPressTest/JetpackBrandingMenuCardPresenterTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ final class JetpackBrandingMenuCardPresenterTests: XCTestCase {
7070

7171
// Phase New Users
7272
remoteFeatureFlagsStore.removalPhaseNewUsers = true
73-
XCTAssertFalse(presenter.shouldShowBottomCard())
73+
XCTAssertTrue(presenter.shouldShowBottomCard())
7474
}
7575

7676
func testPhaseThreeCardConfig() throws {

0 commit comments

Comments
 (0)