diff --git a/Podfile b/Podfile index cd67f39445f1..6777f4fb76bc 100644 --- a/Podfile +++ b/Podfile @@ -49,7 +49,7 @@ end def wordpress_kit pod 'WordPressKit', '~> 6.1.0-beta' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' - # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' + # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: 'fix/plan-flag' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' end diff --git a/Podfile.lock b/Podfile.lock index 59d5992924f4..2a79f697cfcf 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -511,7 +511,7 @@ PODS: - WordPressKit (~> 6.0-beta) - WordPressShared (~> 2.0-beta) - WordPressUI (~> 1.7-beta) - - WordPressKit (6.1.0-beta.1): + - WordPressKit (6.1.0-beta.3): - Alamofire (~> 4.8.0) - NSObject-SafeExpectations (~> 0.0.4) - UIDeviceIdentifier (~> 2.0) @@ -881,7 +881,7 @@ SPEC CHECKSUMS: WordPress-Aztec-iOS: 7d11d598f14c82c727c08b56bd35fbeb7dafb504 WordPress-Editor-iOS: 9eb9f12f21a5209cb837908d81ffe1e31cb27345 WordPressAuthenticator: 0b13d0fc6488a9d6b2a48f4f841e41ce41f08f3b - WordPressKit: c44a1186285cf9bbd61c8e2c8ab323912d7de989 + WordPressKit: 1addcb4df350194b3e3fd2239afaac040f29293c WordPressShared: 8e59bc8cec256f54a7c4cc6c94911adc2a9a65d2 WordPressUI: c5be816f6c7b3392224ac21de9e521e89fa108ac WPMediaPicker: 0d45dfd7b3c5651c5236ffd48c1b0b2f60a2d5d2 @@ -896,6 +896,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37 -PODFILE CHECKSUM: d851d81f272d28ad08e164edaec3601d41c0198f +PODFILE CHECKSUM: 4ffd4693c4a029b5d79ba5f171448834181b3d2a COCOAPODS: 1.11.2 diff --git a/WordPress/Classes/ViewRelated/Support/SupportConfiguration.swift b/WordPress/Classes/ViewRelated/Support/SupportConfiguration.swift index 9b56e927cdba..523d9db4b005 100644 --- a/WordPress/Classes/ViewRelated/Support/SupportConfiguration.swift +++ b/WordPress/Classes/ViewRelated/Support/SupportConfiguration.swift @@ -4,16 +4,22 @@ enum SupportConfiguration { case zendesk case forum + private static func hasSiteWithPaidPlan() -> Bool { + let allBlogs = (try? BlogQuery().blogs(in: ContextManager.sharedInstance().mainContext)) ?? [] + return allBlogs.contains { $0.hasPaidPlan } + } + static func current( featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore(), isWordPress: Bool = AppConfiguration.isWordPress, - zendeskEnabled: Bool = ZendeskUtils.zendeskEnabled + zendeskEnabled: Bool = ZendeskUtils.zendeskEnabled, + hasPaidPlan: Bool = hasSiteWithPaidPlan() ) -> SupportConfiguration { guard zendeskEnabled else { return .forum } - if isWordPress && featureFlagStore.value(for: FeatureFlag.wordPressSupportForum) { + if isWordPress && !hasPaidPlan && featureFlagStore.value(for: FeatureFlag.wordPressSupportForum) { return .forum } else { return .zendesk diff --git a/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift b/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift index 14ec1aa330b7..a78da25c74de 100644 --- a/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift @@ -16,7 +16,6 @@ class SupportTableViewController: UITableViewController { private var tableHandler: ImmuTableViewHandler? private let userDefaults = UserPersistentStoreFactory.instance() - private let isForumShown = SupportConfiguration.current() == .forum /// This closure is called when this VC is about to be dismissed due to the user /// tapping the dismiss button. @@ -46,7 +45,7 @@ class SupportTableViewController: UITableViewController { WPAnalytics.track(.openedSupport) setupNavBar() setupTable() - if !isForumShown { + if SupportConfiguration.current() == .zendesk { checkForAutomatticEmail() } ZendeskUtils.sharedInstance.cacheUnlocalizedSitePlans() @@ -137,21 +136,33 @@ private extension SupportTableViewController { // MARK: - Table Model - func wordPressAppTableViewModel() -> ImmuTable { - - // Community Forums Section - var communityForumsSectionRows = [ImmuTableRow]() - communityForumsSectionRows.append(SupportForumRow(title: LocalizedText.wpForumPrompt, - action: nil, - accessibilityIdentifier: "visit-wordpress-forums-prompt")) - communityForumsSectionRows.append(SupportForumButtonRow(title: LocalizedText.visitWpForumsButton, - accessibilityHint: LocalizedText.visitWpForumsButtonAccessibilityHint, - action: visitForumsSelected(), - accessibilityIdentifier: "visit-wordpress-forums-button")) - - let forumsSection = ImmuTableSection(headerText: LocalizedText.wpForumsSectionHeader, - rows: communityForumsSectionRows, - footerText: nil) + func tableViewModel(supportConfiguration: SupportConfiguration) -> ImmuTable { + + // Support section + let helpSection: ImmuTableSection? + switch supportConfiguration { + case .zendesk: + var rows = [ImmuTableRow]() + rows.append(HelpRow(title: LocalizedText.wpHelpCenter, action: helpCenterSelected(), accessibilityIdentifier: "help-center-link-button")) + rows.append(HelpRow(title: LocalizedText.contactUs, action: contactUsSelected(), accessibilityIdentifier: "contact-support-button")) + rows.append(HelpRow(title: LocalizedText.tickets, action: myTicketsSelected(), showIndicator: ZendeskUtils.showSupportNotificationIndicator, accessibilityIdentifier: "my-tickets-button")) + rows.append(SupportEmailRow(title: LocalizedText.contactEmail, + value: ZendeskUtils.userSupportEmail() ?? LocalizedText.emailNotSet, + accessibilityHint: LocalizedText.contactEmailAccessibilityHint, + action: supportEmailSelected(), + accessibilityIdentifier: "set-contact-email-button")) + helpSection = ImmuTableSection(headerText: LocalizedText.prioritySupportSectionHeader, rows: rows, footerText: nil) + case .forum: + var rows = [ImmuTableRow]() + rows.append(SupportForumRow(title: LocalizedText.wpForumPrompt, + action: nil, + accessibilityIdentifier: "visit-wordpress-forums-prompt")) + rows.append(SupportForumButtonRow(title: LocalizedText.visitWpForumsButton, + accessibilityHint: LocalizedText.visitWpForumsButtonAccessibilityHint, + action: visitForumsSelected(), + accessibilityIdentifier: "visit-wordpress-forums-button")) + helpSection = ImmuTableSection(headerText: LocalizedText.wpForumsSectionHeader, rows: rows, footerText: nil) + } // Information Section var informationSection: ImmuTableSection? @@ -179,60 +190,6 @@ private extension SupportTableViewController { logOutSections = .init(headerText: LocalizedText.wpAccount, optionalRows: [logOutRow]) } - // Create and return table - let sections = [forumsSection, informationSection, logOutSections].compactMap { $0 } - return ImmuTable(sections: sections) - } - - func jetpackAppTableViewModel() -> ImmuTable { - - // Help Section - var helpSectionRows = [ImmuTableRow]() - helpSectionRows.append(HelpRow(title: LocalizedText.wpHelpCenter, action: helpCenterSelected(), accessibilityIdentifier: "help-center-link-button")) - - if ZendeskUtils.zendeskEnabled { - helpSectionRows.append(HelpRow(title: LocalizedText.contactUs, action: contactUsSelected(), accessibilityIdentifier: "contact-support-button")) - helpSectionRows.append(HelpRow(title: LocalizedText.tickets, action: myTicketsSelected(), showIndicator: ZendeskUtils.showSupportNotificationIndicator, accessibilityIdentifier: "my-tickets-button")) - helpSectionRows.append(SupportEmailRow(title: LocalizedText.contactEmail, - value: ZendeskUtils.userSupportEmail() ?? LocalizedText.emailNotSet, - accessibilityHint: LocalizedText.contactEmailAccessibilityHint, - action: supportEmailSelected(), - accessibilityIdentifier: "set-contact-email-button")) - } else { - helpSectionRows.append(HelpRow(title: LocalizedText.wpForums, action: contactUsSelected())) - } - - let helpSection = ImmuTableSection( - headerText: LocalizedText.prioritySupportSectionHeader, - rows: helpSectionRows, - footerText: nil) - - // Information Section - var informationSection: ImmuTableSection? - if configuration.showsLogsSection { - let versionRow = TextRow(title: LocalizedText.version, value: Bundle.main.shortVersionString()) - let logsRow = NavigationItemRow(title: LocalizedText.logs, action: activityLogsSelected(), accessibilityIdentifier: "activity-logs-button") - let switchRow = SwitchRow(title: LocalizedText.debug, - value: userDefaults.bool(forKey: UserDefaultsKeys.extraDebug), - onChange: extraDebugToggled()) - informationSection = ImmuTableSection( - headerText: LocalizedText.advancedSectionHeader, - rows: [versionRow, logsRow, switchRow], - footerText: LocalizedText.informationFooter - ) - } - - // Log out Section - var logOutSections: ImmuTableSection? - if configuration.showsLogOutButton { - let logOutRow = DestructiveButtonRow( - title: LocalizedText.logOutButtonTitle, - action: logOutTapped(), - accessibilityIdentifier: "" - ) - logOutSections = .init(headerText: LocalizedText.wpAccount, optionalRows: [logOutRow]) - } - // Create and return table let sections = [helpSection, informationSection, logOutSections].compactMap { $0 } return ImmuTable(sections: sections) @@ -243,7 +200,7 @@ private extension SupportTableViewController { } func reloadViewModel() { - tableHandler?.viewModel = isForumShown ? wordPressAppTableViewModel() : jetpackAppTableViewModel() + tableHandler?.viewModel = tableViewModel(supportConfiguration: SupportConfiguration.current()) } // MARK: - Row Handlers @@ -263,17 +220,13 @@ private extension SupportTableViewController { return { [weak self] row in guard let self = self else { return } self.tableView.deselectSelectedRowWithAnimation(true) - if SupportConfiguration.current() == .zendesk { - guard let controllerToShowFrom = self.controllerToShowFrom() else { - return - } - ZendeskUtils.sharedInstance.showNewRequestIfPossible(from: controllerToShowFrom, with: self.sourceTag) { [weak self] identityUpdated in - if identityUpdated { - self?.reloadViewModel() - } + guard let controllerToShowFrom = self.controllerToShowFrom() else { + return + } + ZendeskUtils.sharedInstance.showNewRequestIfPossible(from: controllerToShowFrom, with: self.sourceTag) { [weak self] identityUpdated in + if identityUpdated { + self?.reloadViewModel() } - } else { - self.launchForum(url: Constants.forumsURL) } } } diff --git a/WordPress/WordPressTest/Support/SupportConfigurationTests.swift b/WordPress/WordPressTest/Support/SupportConfigurationTests.swift index cb9d8fe329ec..c965fa1760ec 100644 --- a/WordPress/WordPressTest/Support/SupportConfigurationTests.swift +++ b/WordPress/WordPressTest/Support/SupportConfigurationTests.swift @@ -8,41 +8,56 @@ final class SupportConfigurationTests: XCTestCase { XCTAssertEqual(configuration, .forum) } - func testSupportConfigurationWhenWordPressAndFeatureFlagEnabled() { + func testSupportConfigurationWhenWordPressWithFreePlanAndFeatureFlagEnabled() { let configuration = SupportConfiguration.current( featureFlagStore: RemoteFeatureFlagStoreMock(isSupportForumEnabled: true), isWordPress: true, - zendeskEnabled: true + zendeskEnabled: true, + hasPaidPlan: false ) XCTAssertTrue(configuration == .forum) } - func testSupportConfigurationWhenWordPressAndFeatureFlagDisabled() { + func testSupportConfigurationWhenWordPressWithFreePlanAndFeatureFlagDisabled() { let configuration = SupportConfiguration.current( featureFlagStore: RemoteFeatureFlagStoreMock(isSupportForumEnabled: false), isWordPress: true, - zendeskEnabled: true + zendeskEnabled: true, + hasPaidPlan: false ) XCTAssertTrue(configuration == .zendesk) } - func testSupportConfigurationWhenJetpackAndFeatureFlagEnabled() { + func testSupportConfigurationWhenWordPressWithPaidPlanAndFeatureFlagEnabled() { + let configuration = SupportConfiguration.current( + featureFlagStore: RemoteFeatureFlagStoreMock(isSupportForumEnabled: true), + isWordPress: true, + zendeskEnabled: true, + hasPaidPlan: true + ) + + XCTAssertTrue(configuration == .zendesk) + } + + func testSupportConfigurationWhenJetpackWithFreePlanAndFeatureFlagEnabled() { let configuration = SupportConfiguration.current( featureFlagStore: RemoteFeatureFlagStoreMock(isSupportForumEnabled: true), isWordPress: false, - zendeskEnabled: true + zendeskEnabled: true, + hasPaidPlan: false ) XCTAssertTrue(configuration == .zendesk) } - func testSupportConfigurationWhenJetpackAndFeatureFlagDisabled() { + func testSupportConfigurationWhenJetpackWithPaidPlanAndFeatureFlagEnabled() { let configuration = SupportConfiguration.current( - featureFlagStore: RemoteFeatureFlagStoreMock(isSupportForumEnabled: false), + featureFlagStore: RemoteFeatureFlagStoreMock(isSupportForumEnabled: true), isWordPress: false, - zendeskEnabled: true + zendeskEnabled: true, + hasPaidPlan: true ) XCTAssertTrue(configuration == .zendesk)